-
Notifications
You must be signed in to change notification settings - Fork 32
/
node_helper.js
47 lines (39 loc) · 1.76 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
var NodeHelper = require("node_helper");
var fs = require('fs');
var path = require('path');
module.exports = NodeHelper.create({
// Override socketNotificationReceived method.
start: function() {
console.log("Starting node_helper for module: " + this.name);
},
/* 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.
*/
socketNotificationReceived: function(notification, payload) {
if (notification === "MMM-GOOGLE_MAPS_TRAFFIC-GET") {
console.log("Working notification system. Notification:", notification, "payload: ", payload);
this.sendNotification(this.getStyleMap(payload.style));
}
},
getStyleMap: function(style) {
var styledMapType = [];
try {
styledMapType = JSON.parse(fs.readFileSync(path.join(__dirname, 'mapStyle', style), 'utf8'));
} catch (err) {
if (err.code == 'ENOENT') {
console.log('File not found!');
} else {
console.log('Error code: ' + err.code);;
}
styledMapType = JSON.parse([]);
}
return {styledMapType: styledMapType};
},
// Function send notification
sendNotification: function(payload) {
this.sendSocketNotification("MMM-GOOGLE_MAPS_TRAFFIC-RESPONSE", payload);
}
});