-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode_helper.js
44 lines (34 loc) · 867 Bytes
/
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
/* MagicMirror²
* Node Helper: Luxembourg Public Transport
*
* By Evghenii Marinescu https://github.com/uxigene/
* MIT Licensed.
*/
'use strict';
const https = require("node:https");
const NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
start () {
console.log("Starting node helper for: " + this.name);
},
socketNotificationReceived (notification, payload) {
if (notification === "LUX_TRANSPORT:FETCH") {
this.fetch(payload.url);
}
},
fetch (url) {
url = encodeURI(url);
https.get(url, resp => {
let buffer = '';
resp.on('data', chunk => {
buffer += chunk;
});
resp.on('end', () => {
const data = JSON.parse(buffer);
this.sendSocketNotification('LUX_TRANSPORT:SUCCESS', data);
});
}).on("error", err => {
this.sendSocketNotification('LUX_TRANSPORT:ERROR');
});
}
});