-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (32 loc) · 910 Bytes
/
index.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
const socket = require('socket.io-client')(process.env.SERVER_URL);
const LightLighter = require('./light-lighter/index')
const VigilantGuitar = require('./vigilant-guitar')
const state = {
mainLight: false
}
const toggleMainLight = () => {
if(state.mainLight) {
LightLighter.off()
} else {
LightLighter.on()
}
state.mainLight = !state.mainLight
}
VigilantGuitar.init()
socket.on('connect', () => {
socket.emit('register', process.env.ID)
console.log('[THOMAS-LIGHT-CLIENT][WS][CONNECTED]')
})
.on('disconnect', (data) => {
console.log('[THOMAS-LIGHT-CLIENT][WS][DISCONECTED]')
})
.on('registered', (data) => {
console.log('[THOMAS-LIGHT-CLIENT][WS][REGISTERED]');
})
.on('status.update', () => {
toggleMainLight()
console.log(`[THOMAS-LIGHT-CLIENT][WS][STATUS][UPDATE] State: ${state.mainLight}`)
})
VigilantGuitar.start((color) => {
socket.emit('guitar.press', color)
})