-
Notifications
You must be signed in to change notification settings - Fork 3
/
node_helper.js
70 lines (70 loc) · 2.42 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
67
68
69
70
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var bring_updater_1 = require("./bring-updater");
var bring_logger_1 = require("./bring-logger");
/* Magic Mirror
* Node Helper: bringList
*
* By Robert Seidt
* MIT Licensed.
*/
var NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
// Override socketNotificationReceived method.
/* socketNotificationReceived(notification, payload)
* This method is called when a socket notification arrives.
*
* argument notification string - The identifier of the noitication.
* argument payload mixed - The payload of the notification.
*/
updater: new bring_updater_1.BringUpdater(),
running: false,
currentInterval: null,
intervalTime: 60000,
logger: null,
socketNotificationReceived: function (notification, payload) {
if (notification === "bringList-REGISTER") {
this.logger = new bring_logger_1.BringLogger(payload);
this.logger.log("Received registration notification.", true);
this.updater.register(payload, this.logger);
this.intervalTime = Math.max(30000, payload.updateInterval);
this.stopLoop();
this.ensureLoop();
}
if (notification === "bringList-SUSPEND") {
this.logger.log("Received suspend notification.", true);
this.updater.unregister(payload);
if (!this.updater.hasJobs()) {
this.stopLoop();
}
}
},
stopLoop: function () {
if (this.running) {
this.logger.log("Loop running. Stopping.", true);
clearInterval(this.currentInterval);
this.running = false;
this.currentInterval = null;
}
},
ensureLoop: function () {
var _this = this;
if (!this.running) {
this.logger.log("Loop not running. Starting.", true);
this.running = true;
this.updater.refreshLists(function (l) {
_this.sendSocketNotification("bringList-LISTUPDATE", l);
});
this.currentInterval = setInterval(function () {
_this.updater.refreshLists(function (l) {
_this.sendSocketNotification("bringList-LISTUPDATE", l);
});
}, this.intervalTime);
}
},
start: function () {
},
stop: function () {
this.stopLoop();
}
});