-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnode_helper.js
More file actions
53 lines (43 loc) · 1.22 KB
/
node_helper.js
File metadata and controls
53 lines (43 loc) · 1.22 KB
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
/* Magic Mirror
* Module: MMM-KVV
*
* By yo-less
* MIT Licensed.
*/
const request = require('request');
const NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node helper for: " + this.name);
},
/* getParams
* Generates an url with api parameters based on the config.
*
* return String - URL params.
*/
getParams: function() {
var params = this.config.stopID;
params += "?";
if (this.config.maxConn !== '') {
params += "maxInfos=" + this.config.maxConn + "&";
}
params +="key=" + this.config.apiKey;
return params;
},
socketNotificationReceived: function(notification, payload) {
if(notification === 'CONFIG'){
this.config = payload;
var kvv_url = this.config.apiBase + this.getParams();
this.getData(kvv_url, this.config.stopID);
}
},
getData: function(options, stopID) {
request(options, (error, response, body) => {
if (response.statusCode === 200) {
this.sendSocketNotification("TRAMS" + stopID, JSON.parse(body));
} else {
console.log("Error getting tram connections " + response.statusCode);
}
});
}
});