-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
32 lines (23 loc) · 867 Bytes
/
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
var WebSocket = require("ws")
var http = require("http")
var express = require("express")
var timesyncServer = require('timesync/server');
var app = express()
var port = process.env.PORT || 5000
app.use(express.static(__dirname + "/public"))
app.use('/timesync', timesyncServer.requestHandler);
var server = http.createServer(app)
server.listen(port)
console.log("http server listening on %d", port)
var wss = new WebSocket.WebSocketServer({server: server})
console.log ("INScore Web Socket Broadcaster is running");
wss.on('connection', function connection(ws) {
console.log ("new connection - clients count", wss.clients.size)
ws.on('message', function message(data, isBinary) {
wss.clients.forEach(function each(client) {
if (client.readyState === WebSocket.OPEN) {
client.send(data, { binary: isBinary });
}
});
});
});