Please read the release notes carefully since this update requires adjustments to your Raspberry Pi configuration!
what can i do in a module, porting from another mirror project
sdetweil last edited by sdetweil
file, dropbox, google drive, one drive (to be finished), based on filtering a calendar (ical) with info stored in a mongo db.
note: these images are in new windows, and do NOT modify the base dom
the images are shown in an electron remote browserwindow, there may be multiple of these presented concurrently, depending on the filtering specified (show pics of my daughter for her birthday, starting 20 days before, next image every minute ), show pics of my trip to rome on its anniversary , starting 2 days before, next image every 20 seconds, … etc…
i have a mobile app for ios and android that does the config of these filters. The app uses a private rest api to get/set/modify/delete the data, and also does mirror discovery on the local wifi network using udp broadcast…
there are really two plugins/modules… one that does the data collection and filter mgmt, and one that does the image displaying. today these use direct inter instance angular calls… I see I would probably replace these with socket calls.
the scheduler kicks off instances of the imager as required, and terminates when the time window is no longer valid, or the calendar entry list doesn’t contain an entry that matches the active filters.
is there any reason any of this won’t work?
ok, starting to migrate…
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)
maxbachmann last edited by maxbachmann
yes there is only sendNotification to send to all modules. So you need to filter those informations:
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
sdetweil last edited by sdetweil
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.
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…
@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.jsand any other
There are many node.js websocket server modules: https://www.npmjs.com/search?q=Websocket
node_helper.jsis running the Websocket server and your other part is running a Websocket client. Follow this tutorial for the Websocket Client
The 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.)