-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (32 loc) · 1.06 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
47
48
49
var express = require('express');
var app = express();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var fs = require('fs');
var port = 8001;
app.use('/dist', express.static(__dirname + '/web/dist'));
app.use('/fonts', express.static(__dirname + '/web/fonts'));
app.all('/m', function(req, res, next) {
res.sendFile('web/mobile.html', { root: __dirname });
});
app.all('/*', function(req, res, next) {
res.sendFile('web/index.html', { root: __dirname });
});
server.listen(port);
console.log('Server up and running on:', port);
var clientList = {};
var id = Math.floor(Math.random() * 9000) + 1000;
io.on('connection', function (socket) {
var uniqueID = id;
id = Math.floor(Math.random() * 9000) + 1000;
socket.on('Get ID', function (data) {
clientList[uniqueID] = socket;
socket.emit('unique id', { id : uniqueID });
});
socket.on('control', function (data) {
var desktopClient = clientList[data.id];
if (desktopClient !== undefined){
desktopClient.emit('control', data );
}
});
});