Read the statement by Michael Teeuw here.
Simplfying my understanding of sendNotification and sendSocketNotification with and without a this
-
@kayakbabe
here is a drawing I made years ago, the right side is clipped on purpose as it it is just more modules doing the samethe socketNotification (send and receive) are between the module and its node helper ONLY. (1/3/4)
IF there are multiple clients (browsers) connected and running the same module, when the node helper sends the message it goes to ALL connected clients.IF you want to support MULTIPLE instances, then you should send some unique ID (this.identifier) from the module to helper on each sendSocketNotification from the node_helper(which has to include that ID) , AND CHECK in the socketNotificationReceived if the ID matches…
NOTE. for multiple browsers on MULTIPLE machines, the this.identifier will be the same (as its the logical count from top of config.js )
I provide a small module (getip) that can return the clients IP address(as seen by node_helper) so you can use this as the unique ID insteadthe send/receive notifications are IN THE SAME browser.
send is a BROADCAST that goes to every module in this browser.
(note: if you start another browser instance, connecting to the SAME MagicMirror, the broadcast is ONLY to ONE browser, where the module initiated connection)the ‘this’ is because the Module is object oriented, and this points to the individual context for the MagicMirror provided functions (notifications, getDom(), updateDom()… your #2
you MUST use this. for these functions#5, correct…
(as an example see my https://github.com/sdetweil/MMM-CurlToNotification,
which accepts an http post(at the server), and forwards that to module(unknown locations) to broadcast as notification) -
@sdetweil AHHHH!!! AHA moment here. That graphic really helps me understand.
Not everyone runs a single mirror on it’s own computer like I do. Some use the MM like digital signage. One beefy server doing the heavy lifting and then a bunch of lightweight microcomputers just displaying the MM front end.
The Kid node_helper is running on the server! While the MotherModules are only in their own browsers on whatever weenie machine is displaying the front end of MM. (might not be weenie but might be.)
so I see how I would have to be really careful about unique id’s in an environment where I run the MagicMirror on a server and have a bunch of displays all connected to it. May not want the KidModule blasting the same info out to every single display. Unique ID’s mean info would only go to the display it’s intended for.
Though I supposed it’s possible that one would want the same info to go out to every display.
I was thinking of setting up a few displays showing golf tournament scores and in that situation, I’d want every single mirror to show the same info. So in this use case, I wouldn’t want the unique id at all.
-
@kayakbabe said in Simplfying my understanding of sendNotification and sendSocketNotification with and without a this:
I’d want every single mirror to show the same info. So in this use case, I wouldn’t want the unique id at all.
yes, implementation architecture and design matter, (like always)!
because the MagicMirror instances are pulling the same html file and config
they are ordered the same… you would need something (getip) to provide a more certain unique ID when you need that
In the case of multiple instances in multiple clients you would need both ip and identifier in the ID. -
@kayakbabe said in Simplfying my understanding of sendNotification and sendSocketNotification with and without a this:
May not want the KidModule blasting the same info out to every single display. Unique ID’s mean info would only go to the display it’s intended for.
NO… the kidmodule will ALWAYS SEND (BLAST) to ALL connected…
it is using the socketio room technologyits the connected module that is responsible for checking if the received notification is intended to go to it…
-
and on the architecture/design topic
if you are doing the signage solution, then one would
want one data fetch and broadcast to each client
vs each client getting the data on their ownsome provider apikeys count data access requests (openweather) . so while you dont NEED a node_helper, sometimes you want it. but some of the existing modules dont really support that thought