A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.
Read the statement by Michael Teeuw here.
Need help creating a module.
-
@sdmydbr9 A few things are missing. Your MMM-LocalNews.js sends a Socket Notification which the node_helper is supposed to listening for and act upon. The node_helper need a socketNotificationReceived in order to start its work. When it is done doing it’s work it needs to send the data back to the MMM-LocalNews.js (sendSocketNotifcation). Have a look at this sample module https://github.com/sdetweil/SampleModule.
-
@mumblebaj so to sum up, the main.is is correct and I need to edit the nodehelper.js script?
-
@mumblebaj
Here is the updated nodehelpervar https = require("https"); module.exports = NodeHelper.create({ // Override start method. start: function() { console.log("Starting node helper for: " + this.name); }, // Handle the GET_VIDEO_TITLES socket notification. socketNotificationReceived: function(notification, payload) { if (notification === "GET_VIDEO_TITLES") { var apiKey = payload.apiKey; var channelId = payload.channelId; var url = "https://www.googleapis.com/youtube/v3/search?key=" + apiKey + "&channelId=" + channelId + "&part=snippet,id&order=date&maxResults=10"; https.get(url, function(res) { var body = ""; res.on("data", function(chunk) { body += chunk; }); res.on("end", function() { var response = JSON.parse(body); var titles = []; for (var i = 0; i < response.items.length; i++) { titles.push(response.items[i].snippet.title); } // Send the video titles back to the module. this.sendSocketNotification("VIDEO_TITLES", { titles: titles }); }.bind(this)); }.bind(this)).on("error", function(error) { console.log("Error: " + error.message); }); } } });
-
@sdmydbr9
Module has been created and working version has been published in GitHub. Feel free to Check out -
@sdmydbr9 Awesome. Glad we could help