-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode_helper.js
48 lines (41 loc) · 1.05 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
/* Magic Mirror
* Module: MMM-FF-Genius-Lyrics
*
* By Michael Trenkler
* ISC Licensed.
*/
const NodeHelper = require("node_helper");
const LyricFetcher = require("./lyricsFetcher.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 LyricFetcher(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_LYRICS":
fetcher.getLyrics(payload.songInfo);
break;
case "SUSPEND":
fetcher.suspend();
break;
case "RESUME":
fetcher.resume();
break;
default:
break;
}
}
});