-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserver.js
More file actions
59 lines (47 loc) · 1.23 KB
/
server.js
File metadata and controls
59 lines (47 loc) · 1.23 KB
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
48
49
50
51
52
53
54
55
56
var app = require('http').createServer(handler).listen(3000)
, fs = require('fs')
, kinect = require('kinect')
, BufferStream = require('bufferstream')
, $ = require('jquery')
, WebSocketServer = require('ws').Server
, websocket = require('websocket-stream')
, wss = new WebSocketServer({server: app});
function handler (req, res) {
if(req.url === "/"){
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
else{
fs.readFile(__dirname + req.url, function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading ' +req.url);
}
res.writeHead(200);
res.end(data);
});
}
}
var kcontext = kinect();
kcontext.resume();
kcontext.start('depth');
var kstream = new BufferStream();
kcontext.on('depth', function (buf) {
kstream.write(buf);
});
wss.on('connection', function(ws) {
var stream = websocket(ws);
kstream.pipe(stream);
console.log("connection made");
ws.on('close', function() {
stream.writable=false;
console.log('closed socket');
});
});