-
Notifications
You must be signed in to change notification settings - Fork 0
/
linker_server.js
54 lines (39 loc) · 989 Bytes
/
linker_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
const https = require('https');
const API_URL = "api.twicecast.ovh";
const server = require('http').createServer();
const io = require('socket.io')(server);
const config = require('./config');
var colors = require('colors');
var clients = [];
io.on('connection', function(client) {
console.log("New connection !");
client.uid = -1;
if (!(client in clients)) {
clients.push(client);
}
client.on('Auth', function(content) {
client.uid = content.uid;
});
client.on('message', function(content) {
var i = 0;
while (i < clients.length) {
if (clients[i].uid == client.uid)
clients[i].emit('message', content);
i++;
}
});
client.on('disconnect', function(){
var id = clients.indexOf(client);
if (id >= 0)
clients.splice(id, 1);
});
});
var port = config.SERVER_PORT;
if (process.argv.length > 2) {
try {
port = parseInt(process.argv[2]);
} catch (e) {
}
}
console.log('Server listening on ' + port + ' !');
server.listen(port);