forked from thebookins/transpector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transmitter-worker.js
41 lines (32 loc) · 1.03 KB
/
transmitter-worker.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
const Transmitter = require('xdrip-js');
const id = process.argv[2];
const getMessages = () => {
/*eslint-disable no-unused-vars*/
return new Promise((resolve, reject) => {
/*eslint-enable no-unused-vars*/
process.on('message', messages => {
resolve(messages);
});
// TODO: consider adding a timeout here, with resolve([]), or reject
process.send({msg: 'getMessages'});
});
};
// TODO: reinstate messages
const transmitter = new Transmitter(id, getMessages);
// const transmitter = new Transmitter(id);
transmitter.on('glucose', glucose => {
process.send({msg: 'glucose', data: glucose });
});
transmitter.on('messageProcessed', data => {
process.send({msg: 'messageProcessed', data});
});
transmitter.on('calibrationData', data => {
process.send({msg: 'calibrationData', data});
});
transmitter.on('batteryStatus', data => {
process.send({msg: 'batteryStatus', data});
});
transmitter.on('sawTransmitter', data => {
process.send({msg: 'sawTransmitter', data});
});
transmitter.on('disconnect', process.exit);