-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
55 lines (44 loc) · 1.4 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
52
53
54
55
'use strict';
var nodeStatic = require('node-static');
var http = require('http');
var socketIO = require('socket.io');
var fileServer = new(nodeStatic.Server)();
var app = http.createServer(function(req, res) {
fileServer.serve(req, res);
}).listen(8080, "0.0.0.0");
console.log('Server running on port 8080');
var clients = {}
var io = socketIO.listen(app);
io.sockets.on('connection', function(socket) {
socket.on('open-lc', function(addr) {
console.log('Opening a channel with ' + addr);
clients[addr] = socket;
// Other open-lc stuff...
})
socket.on('open-thread', function(data) {
console.log("Opening thread between " + data.from + " and " + data.to);
if(clients[data.from] && clients[data.to]) {
clients[data.to].emit('open-thread', data);
}
});
socket.on('open-thread-resp', function(data) {
console.log("Opening thread response from" + data.from);
if(clients[data.from] && clients[data.to]) {
clients[data.to].emit('open-thread-resp', data);
}
})
socket.on('ice-msg', function(data) {
console.log("Passing ice messages..");
if(clients[data.from] && clients[data.to]) {
clients[data.to].emit('ice-msg', data);
}
})
socket.on('bye', function(data) {
if(clients[data.from] && clients[data.to]) {
clients[data.to].emit('bye', data);
}
})
socket.on('bye', function(){
console.log('received bye');
});
});