Read the statement by Michael Teeuw here.
what can i do in a module, porting from another mirror project
-
ok, starting to migrate…
questions:
is there a way to communicate across modules? I don’t see a way to have module A request info from module B, and have B’s response only come back to module A.
in my design, only the scheduler knows about the config DB, and HOW to decide if a viewer is needed, or not.
it then tells the viewer manager to start/stop a viewer… the schedulers also is the only one that knows HOW to get the list of images (using the appropriate api of the source location, file, dropbox, etc)
the viewer makes a call to the scheduler to get the next image, and if at the end of the list, it causes another list reload. the viewer doesn’t know where the list came from. the list is just to images.
now, if someone uses the mobile app and changes the data, it MAY be cause to terminate a running viewer, as the filter would no longer cause that particular viewer to be selected…
but… the db change handler is in the viewer scheduler node_helper, and the running viewer list is in the viewer handler node_helper…looks like I can only do sendnotification, and broadcast to all modules (ugh)
-
yes there is only sendNotification to send to all modules. So you need to filter those informations:
the commandthis.sendNotification(notification, payload)
has the part notification which you could ask for by a if condition and the payload that includes the actual data you want to send to the other module. So just make sure to take a unique notification and you should be fine
-
the doc also mentions sendSocketNotification, in both directions… module to helper and helper to module(s) (of same name if multiple)…
this.sendSocketNotification(notification, payload) notification String - The notification identifier. payload AnyType - Optional. A notification payload. If you want to send a notification to the node_helper, use the sendSocketNotification(notification, payload). Only the node_helper of this module will receive the socket notification.
and
Each **node helper** has some handy methods which can be helpful building your module. this.sendSocketNotification(notification, payload) notification String - The notification identifier. payload AnyType - Optional. A notification payload. If you want to send a notification to all your modules, use the sendSocketNotification(notification, payload). Only the module of your module type will receive the socket notification.
and also looks like with MM.getModules(). i can get an object reference to the instances of the other components, and access their public methods…
scheduler->handler.start(viewer_config),
handler->scheduler.next(viewer) -
@sdetweil You can establish a custom Websocket connection between your
node_helper.js
, which is node.js and your other JS code which runs in a browser. -
cool… that would allow my components to communicate in a synchronous mode…
-
do you have any pointers to examples of websockets from the module? or your “other JS code” means some OTHER library of JS code…
looks like I would have to build another js class to wrap the ws services…(run the server side in the helper) cause I can’t require() in the module itself… load those classes via the scripts…
-
@sdetweil A MagicMirror Module has two parts, the
node_helper.js
and any otherrequired
node.js modulewhich runs on your Raspberry Pi, the other part is just plain Javascript like in any Website running on the Browser (Electron in the default case).There are many node.js websocket server modules: https://www.npmjs.com/search?q=Websocket
Your
node_helper.js
is running the Websocket server and your other part is running a Websocket client. Follow this tutorial for the Websocket ClientThe communication won’t be encrypted in any way, so don’t pass importand information over the Websocket!
-
thanks… not a nodejs developer generally, so didn’t know about the npmjs site…
also, i run the MM on an ODROID not PI. a lot faster.
i understand how ws works… i built a custom ws server and interface in front of an api emulation platform to support software testing a couple years ago.
-
i have done some work over the weekend to get my two modules and their helpers working to do the basics…
database access is working, rest api server is working. (scheduler helper)
browser window creation and destruction is working, and image loading (handler helper)one thing of note, a json object transports from module to helper and back. BUT any data added to the object in the helper (like a browserwindow object), does NOT transport (becomes undefined on receipt.)
-
@sdetweil The module helper communication relies on a websocket connection. Any references will be lost. Try to clone the Object.