-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (39 loc) · 1.28 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
48
49
50
51
var express = require('express')
, app = express()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server);
io.set('log level', 0);
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/static'));
app.get('/', function(req, res){
res.render('index.jade');
});
app.get('/mobile/:id', function(req, res){
res.render('mobile.jade', {id: req.params.id});
});
server.listen(process.env.PORT || 8080);
var regUsers = {};
io.sockets.on('connection', function(socket) {
var deskSocket;
var mobileSocket
socket.on('desktop-register', function(data) {
regUsers[data.id] = deskSocket = socket;
});
socket.on('mobile-register', function(data) {
mobileSocket = socket;
if(typeof(regUsers[data.id]) !== "undefined") {
deskSocket = regUsers[data.id];
deskSocket.emit('mobile-on');
mobileSocket.emit('start');
}
});
socket.on('mobile-orientation', function(orientation) {
if(typeof(deskSocket) !== "undefined" && deskSocket !== null) {
deskSocket.emit('orientation', orientation);
}
});
});