-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
81 lines (63 loc) · 2.05 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var express = require('express');
var app = express();
var fs = require('fs');
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var port = process.env.PORT || 3000;
// app.use(express.static(__dirname + '/node_modules'));
var distDir = __dirname + "/dist/";
app.use(express.static(distDir));
app.get('/', function(req, res,next) {
//res.sendFile(__dirname + '/index.html');
});
function writeToFile(matches){
fs.writeFile('matches.json', JSON.stringify(matches), function(err) {
if(err) return console.log(err);
});
}
io.on('connection', function(client) {
client.on('data', function(data){
io.emit('data', data);
});
client.on('tracker', function(data){
io.emit('tracker', data);
});
client.on('timer', function(start, data){
io.emit('timer', start, data);
});
client.on('timer1', function(finished, data){
io.emit('timer1', finished, data);
});
client.on('timer2', function(finished, data){
io.emit('timer2', finished, data);
});
client.on('timer-set', function(ticks, data){
io.emit('timer-set', ticks, data);
});
client.on('p1Stats', function(data, text){
io.emit('p1Stats', data, text);
});
client.on('p2Stats', function(data, text){
io.emit('p2Stats', data, text);
});
client.on('freeTextStats', function(data, text){
io.emit('freeTextStats', data, text);
});
client.on('swissPlayerSelected', function(data, playerId){
io.emit('swissPlayerSelected', data, playerId);
});
client.on('swissTeamSelected', function(data, teamId){
io.emit('swissTeamSelected', data, teamId);
});
client.on('resetSwiss', function(data){
io.emit('resetSwiss', data);
});
client.on('undoSwissSingles', function(data){
io.emit('undoSwissSingles', data);
});
client.on('undoSwissDoubles', function(data){
io.emit('undoSwissDoubles', data);
});
});
server.listen(port);
console.log('Server listening on port ' + port)