-
Notifications
You must be signed in to change notification settings - Fork 0
/
ceremony.js
26 lines (23 loc) · 922 Bytes
/
ceremony.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
import WebSocket, { WebSocketServer } from 'ws';
import config from './config.js';
for (const eventCode of Object.keys(config.events)) {
const wsPort = config.events[eventCode];
const wss = new WebSocketServer({ port: wsPort });
const wssBroadcast = data => {
wss.clients.forEach(client => {
if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify(data));
}
});
};
const red = (state, seconds) => wssBroadcast(['red', -1, state, seconds]);
const blue = (state, seconds) => wssBroadcast(['blue', -1, state, seconds]);
const amber = (state, seconds) => wssBroadcast(['amber', -1, state, seconds]);
const green = (state, seconds) => wssBroadcast(['green', -1, state, seconds]);
setInterval(() => {
blue('on', 1);
setTimeout(() => red('on', 1), 1000);
setTimeout(() => amber('on', 1), 2000);
setTimeout(() => green('on', 1), 3000);
}, 4000);
}