Skip to content

Commit

Permalink
Allow multiple instances
Browse files Browse the repository at this point in the history
  • Loading branch information
timdows committed Apr 3, 2018
1 parent f167fca commit 3506d23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
12 changes: 8 additions & 4 deletions MMM-JsonTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ Module.register("MMM-JsonTable", {

// Request node_helper to get json from url
getJson: function () {
this.sendSocketNotification('GET_JSON', this.config.url);
this.sendSocketNotification("MMM-JsonTable_GET_JSON", this.config.url);
},

socketNotificationReceived: function (notification, payload) {
if (notification === "JSON_RESULT") {
this.jsonData = payload;
this.updateDom(500);
if (notification === "MMM-JsonTable_JSON_RESULT") {
// Only continue if the notification came from the request we made
if (payload.url === this.config.url)
{
this.jsonData = payload.data;
this.updateDom(500);
}
}
},

Expand Down
11 changes: 6 additions & 5 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ module.exports = NodeHelper.create({

request({ url: url, method: 'GET' }, function (error, response, body) {
if (!error && response.statusCode == 200) {
var result = JSON.parse(body);
self.sendSocketNotification('JSON_RESULT', result);
var json = JSON.parse(body);
// Send the json data back with the url to distinguish it on the receiving part
self.sendSocketNotification("MMM-JsonTable_JSON_RESULT", {url: url, data: json});
}
});

},

//Subclass socketNotificationReceived received.
socketNotificationReceived: function (notification, payload) {
if (notification === 'GET_JSON') {
this.getJson(payload);
socketNotificationReceived: function (notification, url) {
if (notification === "MMM-JsonTable_GET_JSON") {
this.getJson(url);
}
}
});

0 comments on commit 3506d23

Please sign in to comment.