-
Notifications
You must be signed in to change notification settings - Fork 1
/
node_helper.js
41 lines (37 loc) · 1.18 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
/* MagicMirror²
* Module: MMM-HK-KMB
*
* By Winston / https://github.com/winstonma
* AGPL-3.0 Licensed.
*/
const NodeHelper = require("node_helper");
const Kmb = require('js-kmb-api').default;
const StorageShim = require('node-storage-shim');
const Log = require("../../js/logger");
module.exports = NodeHelper.create({
// Override start method.
start: function () {
Log.log("Starting node helper for: " + this.name);
this.localStorage = new StorageShim();
},
// Override socketNotificationReceived received.
socketNotificationReceived: function (notification, payload) {
if (notification === "ADD_KMB_STOP") {
this.kmb = new Kmb('en', this.localStorage);
const stop = payload ? new this.kmb.Stop(payload) : null;
stop.getStoppings()
.then(data => {
const retVal = {station: payload, data: data};
this.broadcastETAs(retVal);
});
}
},
/*
* Creates an object with all feed items of the different registered ETAs,
* and broadcasts these using sendSocketNotification.
*/
broadcastETAs: function (data) {
Log.log("Sending KMB Stop Info");
this.sendSocketNotification("KMB_STOP_ITEM", data);
},
});