Read the statement by Michael Teeuw here.
sendSocketNotification() does not arrive at module
-
Hi,
I’m very new to MM (2 days in…).
I have successfully got a module I’ve written working. It scrapes a local transit website for real-time train departure info and displays in the mirror.
My second module, however, is having problems. The node_helper is getting socket notifications from the module, but when it calls sendSocketNotification(), nothing is received at the module. I tried used the original (working) module as a template, making it almost an exact copy of the working module, but that didn’t help.
I’ve stipped it back to almost nothing, and still no luck. Here’s the node_helper and module file in question:
node_helper.js:
const NodeHelper = require('node_helper'); module.exports = NodeHelper.create({ start: function() { console.log("Starting node helper: " + this.name); }, socketNotificationReceived: function(notification, payload) { var self = this; console.log("Notification: " + notification + " Payload: " + JSON.stringify(payload)); if (notification === "GET_DATA") { self.sendSocketNotification("GOT_DATA", "1234566789"); } } });
and MMM-MYTEST.js:
Module.register("MMM-MYTEST", { // Default configs defaults: { intervalSecs: 10, }, start: function () { Log.info(this.config); Log.log('Starting module: ' + this.name); self = this; self.getData(); setInterval(function() { self.getData(); }, self.config.intervalSecs * 1000); }, getData: function () { Log.info(this.name + ': Getting data'); this.sendSocketNotification("GET_DATA", { config: this.config, }); }, getStyles: function () { return [ this.file('styles.css'), ]; }, socketNotificationReceived: function(notification, payload) { if (notification === "GOT_DATA") { Log.info('socketNotificationReceived: GOT_DATA'); this.updateDom(); } }, // Override the DOM generator getDom: function () { let wrapper = document.createElement('div'); return wrapper; }, });
And snipped log output while running (I added some debug outout to NodeHelper.socketNotificationReceived() to make sure it was being called):
[27.02.2023 14:10.56.820] [LOG] Notification: GET_DATA Payload: {"config":{"intervalSecs":10}} [27.02.2023 14:10.56.821] [INFO] in MMM-MYTEST sendSocketNotification GOT_DATA [27.02.2023 14:11.06.819] [LOG] Notification: GET_DATA Payload: {"config":{"intervalSecs":10}} [27.02.2023 14:11.06.820] [INFO] in MMM-MYTEST sendSocketNotification GOT_DATA [27.02.2023 14:11.16.827] [LOG] Notification: GET_DATA Payload: {"config":{"intervalSecs":10}} [27.02.2023 14:11.16.829] [INFO] in MMM-MYTEST sendSocketNotification GOT_DATA
So I can see that NodeHelp.socketNotificationRecieved() is being called, but my module never gets the notification. I’ve run out of debug ideas. Any assistance would be greatly appreciated.
m
-
@mjlee - I copied your code and I’m not getting the same results.
From the browser console:socketNotificationReceived: GOT_DATA MMM-MYTEST.js:20 MMM-MYTEST: Getting data MMM-MYTEST.js:34 socketNotificationReceived: GOT_DATA MMM-MYTEST.js:20 MMM-MYTEST: Getting data MMM-MYTEST.js:34
And from the terminal console:
Ready to go! Please point your browser to: http://localhost:8080 [28.02.2023 20:52.46.170] [LOG] Notification: GET_DATA Payload: {"config":{"intervalSecs":10}} [28.02.2023 20:52.46.207] [INFO] Checking git for module: MMM-MYTEST [28.02.2023 20:52.46.207] [INFO] Checking git for module: default [28.02.2023 20:52.56.164] [LOG] Notification: GET_DATA Payload: {"config":{"intervalSecs":10}} [28.02.2023 20:53.06.156] [LOG] Notification: GET_DATA Payload: {"config":{"intervalSecs":10}}
Perhaps the issue is that you’re looking at the wrong console log? The MYTEST.js log will write to the browser’s console rather than the terminal.