-
Notifications
You must be signed in to change notification settings - Fork 8
/
server.js
47 lines (45 loc) · 1.47 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var paper = require('./lib/paper.js/node.js');
var express = require('express');
var receiver = require('./public/receiver');
var webServer = express.createServer();
var io = require('socket.io').listen(webServer);
function publishPathsToClient(socket) {
var path = paper.project.activeLayer.firstChild;
while (path) {
var segments = [];
for (var segmentIndex = 0, l = path.segments.length; segmentIndex < l; ++segmentIndex) {
var segment = path.segments[segmentIndex];
segments.push({
x: segment.point.x,
y: segment.point.y,
ix: segment.handleIn.x,
iy: segment.handleIn.y,
ox: segment.handleOut.x,
oy: segment.handleOut.y,
});
}
var message = {
id: path.name,
};
if (segments.length > 0) {
message.segments = segments;
}
message.closed = path.closed;
socket.emit('add path', message);
path = path.nextSibling;
}
}
io.set('log level', 1);
webServer.listen(8001);
webServer.set('view engine', 'jade');
webServer.use(express.static(__dirname + '/public'));
webServer.use(express.errorHandler());
webServer.use(express.bodyParser());
webServer.get('/', function(req, res) {
res.render('index');
});
paper.setup();
io.sockets.on('connection', function(socket) {
publishPathsToClient(socket);
receiver.setupReceiver(paper, socket, true);
});