-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (36 loc) · 1.24 KB
/
app.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
var static = require('node-static'),
http = require('http'),
util = require('util'),
url = require('url'),
fs = require('fs');
var fileServer = new static.Server('./public');
var server = http.createServer(function (req, res) {
var pathname = url.parse(req.url).pathname;
//console.log('pathname: '+pathname);
req.addListener('end', function () {
fileServer.serve(req, res);
}).resume();
}).listen(process.env.PORT || 8888, function() {
console.log('Listening at: http://localhost:' + (process.env.PORT || 8888));
});
var io = require('socket.io').listen(server, { log: false });
io.sockets.on('connection', function(socket){
socket.on('message', function(message){
socket.broadcast.emit('message', message);
});
socket.on('key down', function(data){
socket.broadcast.emit('key down', data);
});
socket.on('key up', function(data){
socket.broadcast.emit('key up', data);
});
socket.on('flowtime minimap complete', function(data){
socket.broadcast.emit('flowtime minimap complete', data);
});
socket.on('navigate', function(data){
socket.broadcast.emit('navigate', data);
});
socket.on('disconnect', function(){
console.log("Connection " + socket.id + " terminated.");
});
});