-
Notifications
You must be signed in to change notification settings - Fork 2
/
node_helper.js
40 lines (35 loc) · 1.19 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
/* Magic Mirror
* Module: MMM-ShipmentTracking
*
* By fewieden https://github.com/fewieden/MMM-ShipmentTracking
* MIT Licensed.
*/
/* eslint-env node */
const NodeHelper = require('node_helper');
const track = require('./Tracker.js')().track;
module.exports = NodeHelper.create({
socketNotificationReceived(notification, payload) {
if (notification === 'CONFIG') {
this.config = payload;
this.carriers = Object.keys(this.config.tracking);
this.track();
setInterval(() => {
this.track();
}, this.config.updateInterval);
}
},
track() {
for (let i = 0; i < this.carriers.length; i += 1) {
track(this.carriers[i], this.config.tracking[this.carriers[i]], this.config.language)
.then((result) => {
if (Object.prototype.hasOwnProperty.call(result, 'error')) {
this.sendSocketNotification('ERROR', result);
} else {
this.sendSocketNotification('DATA', result);
}
}).catch((result) => {
this.sendSocketNotification('ERROR', result);
});
}
}
});