-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
63 lines (56 loc) · 1.53 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
60
61
62
63
/* Magic Mirror
* Module: MMM-FF-cht-sh
*
* By Michael Trenkler
* ISC Licensed.
*/
const NodeHelper = require("node_helper");
const SheetFetcher = require("./sheetFetcher.js");
module.exports = NodeHelper.create({
fetcherInstances: [],
start: function () {
console.log("Starting node helper: " + this.name);
},
getFetcher: function (config) {
let instance = this.fetcherInstances.filter(
(instance) => instance.moduleId === config.moduleId
)[0];
if (!instance) {
instance = new SheetFetcher(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_CHEAT_SHEET":
fetcher.getInitialCheatSheet();
break;
case "GET_PREVIOUS_CHEAT_SHEET_LIST_ITEM":
fetcher.getPreviousCheatSheet();
break;
case "GET_NEXT_CHEAT_SHEET_LIST_ITEM":
fetcher.getNextCheatSheet();
break;
case "GET_RANDOM_CHEAT_SHEET_LIST_ITEM":
fetcher.getRandomCheatSheetListItem();
break;
case "GET_RANDOM_CHEAT_SHEET":
fetcher.getRandomCheatSheet();
break;
case "GET_CHEAT_SHEET":
fetcher.getCheatSheet(payload.sheet);
break;
case "SUSPEND":
fetcher.suspend();
break;
case "RESUME":
fetcher.resume();
break;
default:
break;
}
}
});