-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_helper.js
59 lines (53 loc) · 1.41 KB
/
node_helper.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
/* MagicMirror²
* Module: MMM-FF-multigeiger
*
* By Michael Trenkler
* ISC Licensed.
*/
const NodeHelper = require("node_helper");
const DataFetcher = require("./dataFetcher.js");
module.exports = NodeHelper.create({
fetcherInstances: [],
start: function () {
console.log("Starting node helper: " + this.name);
},
getFetcher: function (config) {
let instance = this.fetcherInstances.filter((_) => {
return _.moduleId === config.moduleId;
})[0];
if (!instance) {
instance = new DataFetcher(this, config);
this.fetcherInstances.push(instance);
}
return instance;
},
socketNotificationReceived: function (notification, payload) {
if (!payload.config) return;
const fetcher = this.getFetcher(payload.config);
switch (notification) {
case "GET_INITIAL_SENSOR_DATA":
fetcher.getSensorDataInitial();
break;
case "GET_PREVIOUS_SENSOR_LIST_ITEM":
fetcher.getSensorDataPrevious();
break;
case "GET_NEXT_SENSOR_LIST_ITEM":
fetcher.getSensorDataNext();
break;
case "GET_RANDOM_SENSOR_LIST_ITEM":
fetcher.getSensorDataRandom();
break;
case "UPDATE_CONFIG":
fetcher.updateConfig(payload.config);
break;
case "SUSPEND":
fetcher.suspend();
break;
case "RESUME":
fetcher.resume();
break;
default:
break;
}
}
});