-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake-device.js
59 lines (48 loc) · 1.34 KB
/
fake-device.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
const { HOST, PORT } = require("./config.js");
const socket = require("socket.io-client")(`http://${HOST}:${PORT}`);
const ip = require("ip");
const { Message, DeviceStatus } = require("./protocol.js");
var pulse = null;
var overrides = null;
const DEVICE_INFO = {
id: "robin-prototype-fake",
ip: ip.address(),
deviceBatteryLow: false,
emitterBatteryLow: false,
bluetoothConnections: "Unknown",
};
function emitStatus() {
console.log("emitting status", DeviceStatus.READY);
socket.emit(Message.DEVICE_STATUS, {
status: DeviceStatus.READY,
info: Object.assign({
lastSeen: new Date().toString(),
pulse: pulse,
}, DEVICE_INFO),
});
}
socket.on(Message.CONNECT, () => {
console.log("I am connected");
console.log("Sending device handshake...");
socket.emit(Message.HANDSHAKE_DEVICE, DEVICE_INFO);
});
socket.on(Message.DEVICE_NEW_REMOTE, () => {
console.log("I have a new client");
emitStatus();
});
socket.on(Message.DISCONNECT, () => {
console.log("I am disconnected");
overrides = null;
});
socket.on(Message.UPDATE_PULSE, (p) => {
console.log("Setting pulse to ", p);
pulse = p;
});
socket.on(Message.UPDATE_OVERRIDES, (o) => {
console.log("Setting overrides to ", o);
overrides = o;
});
socket.on(Message.ASSIGN_PULSE, ({ button, pulse }) => {
console.log("Assigning pulse", button, pulse);
})
setInterval(emitStatus, 5000);