-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
66 lines (59 loc) · 1.5 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
64
65
66
/* Magic Mirror
* Module: MMM-FF-XKCD
*
* By Michael Trenkler
* ISC Licensed.
*/
const NodeHelper = require("node_helper");
const ComicFetcher = require("./comicFetcher.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 ComicFetcher(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_COMIC":
fetcher.getInitialComic();
break;
case "GET_FIRST_COMIC":
fetcher.getFirstComic();
break;
case "GET_PREVIOUS_COMIC":
fetcher.getPreviousComic();
break;
case "GET_NEXT_COMIC":
fetcher.getNextComic();
break;
case "GET_LATEST_COMIC":
fetcher.getLatestComic();
break;
case "GET_RANDOM_COMIC":
fetcher.getRandomComic();
break;
case "GET_COMIC":
fetcher.getComic(payload.num);
break;
case "SUSPEND":
fetcher.suspend();
break;
case "RESUME":
fetcher.resume();
break;
default:
break;
}
}
});