-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
51 lines (42 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
41
42
43
44
45
46
47
48
49
50
51
'use strict';
/* Magic Mirror
* Module: MMM-backlog
*
* By Stefan Krause http://yawns.de
* MIT Licensed.
*/
const NodeHelper = require('node_helper');
var request = require('request');
module.exports = NodeHelper.create({
start: function() {
this.started = false;
this.config = null;
},
getData: function() {
var self = this;
//var myUrl = this.config.url;
//var myUrl = "http://" + this.config.ip + ":" + this.config.port + "/JSON?request=getstatus&ref=" + this.config.ref;
var ip = this.config.ip;
var port = this.config.port;
var ref = this.config.ref;
var myUrl = "http://" + ip + ":" + port + "/JSON?request=getstatus&ref=" + ref;
request({
url: myUrl,
method: 'GET',
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
self.sendSocketNotification("DATA", body);
}
});
setTimeout(function() { self.getData(); }, this.config.refreshInterval);
},
socketNotificationReceived: function(notification, payload) {
var self = this;
if (notification === 'CONFIG' && self.started == false) {
self.config = payload;
self.sendSocketNotification("STARTED", true);
self.getData();
self.started = true;
}
}
});