the two parts of a module talk to each other thru socket notification events…
the node_helper can interact with the system ,but not the dom, and the module (js) interacts with the dom and not the system…
the two sides would use the sendSocketNotification(event_id, buffer) method…
each would have a method called socketNotificationReceived(event_id, buffer) that will be called when the event arrives…
the buffer can be any kind of data. formatted or not.
to open the socket the first time, the module.js MUST be the first side to sendSocketNotification().
typically the module sends the config info to the node_helper when its starts up.
this is another event notification, which is called notificationReceived(event, buffer, sender)
there are a a few builtin events, I use the ‘ALL_MODULES_STARTED’ event to send my module config to my helper and open the socket.
see the doc here for the additional specifics
https://github.com/MichMich/MagicMirror/tree/master/modules
the event id strings for socketnotification are completely up to you… the MM system does not send socket notifications. it DOES send notifications (notice no ‘socket’) to the notificationReceived() method
but summary
-
create both files (per the doc)
-
when module receives the ‘ALL_MODULES_STARTED’ event, send a socket notification from the module to the helper to open the communications channel
-
when the node_helper gets new data, it sends a socket notification (will ONLY be to the module(js)) with the data
-
the module(js) uses the data to update the dom
-
if the module(js) decides when there should be new data, then the module sends a socket notification to the helper, and the helper responds with a socket notification with the new data (if any).