forked from jclarke0000/MMM-MyScoreboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
65 lines (43 loc) · 1.66 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
const NodeHelper = require("node_helper");
const dirTree = require("directory-tree");
module.exports = NodeHelper.create({
providers: {},
start: function() {
console.log("Starting node_helper for module [" + this.name + "]");
this.providers.SNET = require("./providers/SNET.js");
this.providers.ESPN = require("./providers/ESPN.js");
this.localLogos = {};
const fsTree = dirTree("./modules/MMM-MyScoreboard/logos", {
extensions: /\.(svg|png)$/
});
fsTree.children.forEach( league => {
if (league.children) {
var logoFiles = [];
league.children.forEach( logo => {
logoFiles.push(logo.name);
});
this.localLogos[league.name] = logoFiles;
}
});
},
socketNotificationReceived: function(notification, payload) {
if (notification == "MMM-MYSCOREBOARD-GET-SCORES") {
/*
payload contains:
provider to get data from
game date for which to retrive scores,
league
teams
module instance identifier
sport's index from the config's order
*/
var self = this;
var provider = this.providers[payload.provider];
provider.getScores(payload.league, payload.teams, payload.gameDate, function(scores) {
self.sendSocketNotification("MMM-MYSCOREBOARD-SCORE-UPDATE", {instanceId: payload.instanceId, index: payload.index, scores: scores});
});
} else if (notification == "MMM-MYSCOREBOARD-GET-LOCAL-LOGOS") {
this.sendSocketNotification("MMM-MYSCOREBOARD-LOCAL-LOGO-LIST", {instanceId: payload.instanceId, index: payload.index, logos: this.localLogos});
}
},
});