-
Notifications
You must be signed in to change notification settings - Fork 3
/
node_helper.js
49 lines (39 loc) · 1.07 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
/* Magic Mirror
* Node Helper: MMM-YouLess2
*
* By M. Eckert
* MIT Licensed.
*/
var request = require("request");
var NodeHelper = require("node_helper");
var nodeHelper = NodeHelper.create({
config: {},
// Override start method.
start: function () {
},
// Override socketNotificationReceived method.
socketNotificationReceived: function (notification, payload) {
var self = this;
var config = function (payload) {
self.config = payload;
};
var query = function (payload) {
var options = {
uri: `http://${self.config.youlessHost}/a?f=j`,
method: "GET",
};
request(options, function (error, response, body) {
if (response && response.statusCode === 200) {
self.sendSocketNotification("RESPONSE", body);
}
});
};
var acceptedNotifications = {
"CONFIG": config,
"QUERY": query,
};
// Call appropriate handler for socket notification
acceptedNotifications[notification] && typeof acceptedNotifications[notification] === "function" && acceptedNotifications[notification](payload);
},
});
module.exports = nodeHelper;