This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
executable file
·62 lines (49 loc) · 1.92 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
50
51
52
53
54
55
56
57
58
59
60
61
62
// main server setup
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
// other things
var path = require('path');
// our sockets
var conn = {};
// let us get stuff please?
app.use(express.static(path.join(__dirname, 'www')));
// start listening
server.listen(8008);
// connection
io.sockets.on('connection', function(socket) {
socket.emit('identify');
socket.on('identity', function(data) {
var uid = data['uid'];
if (conn[uid] == undefined)
conn[uid] = {};
if (data['type'] == 'viewer') {
conn[uid]['viewer'] = socket;
}
if (data['type'] == 'remote') {
conn[uid]['remote'] = socket;
// register remote disconnect
socket.on('disconnect', function() {
if (conn[uid]['viewer'] != undefined)
conn[uid]['viewer'].emit('disconnected');
});
}
if (conn[uid] != undefined) {
if (conn[uid]['viewer'] != undefined && conn[uid]['remote'] != undefined) {
var viewer = conn[uid]['viewer'];
var remote = conn[uid]['remote'];
viewer.emit('ready');
remote.emit('ready');
// now set up relays
remote.on('next', function() { viewer.emit('next'); });
remote.on('prev', function() { viewer.emit('prev'); });
remote.on('right', function() { viewer.emit('right'); });
remote.on('left', function() { viewer.emit('left'); });
remote.on('up', function() { viewer.emit('up'); });
remote.on('down', function() { viewer.emit('down'); });
remote.on('overview', function() { viewer.emit('overview'); });
}
}
});
});