Read the statement by Michael Teeuw here.
ELI5 how notifications between modules work and how and where to create them
-
I have been reading through multiple forum posts and it seems like when someone gets the answer, they don’t break it down in a way that’s understandable.
I’m trying to add a button to a module like this:
https://github.com/shbatm/MMM-OnScreenMenu/issues
And use the button to call a keyboard like this:
https://forum.magicmirror.builders/topic/12526/mmm-keyboard-a-virtual-touch-keyboard
I don’t understand where I’m supposed to put the notification and how it’s supposed to get called.
Apologies if this has been answered clearly, but I need a step by step break down because I’m just not getting it.
I need to understand:
- Where specifically to add the notification .
- How it’s supposed to be formatted. Does it need to be a new function or something if it’s going into a module.js?
- Does the other module need to be modified too?
I’m a newbie and managed to get multiple modules working, but I can’t seem to understand how to send notifications/call other modules.
I’d really like to use an on screen button module to call a keyboard and do some text entry, but having a heck of a time figuring this all out.
Thanks!
-
@reverendz so you have to create a button html/Dom object, as part of the response to getDom(), to be shown on the screen
Then you need to attach some handler/function to react when the button is pushed.
In the routine, you would add one line of code to call
this.sendNotification(Code, parms) as required by the keyboard module,
to tell the module supplying the keyboard to pop it upI assume the keyboard will pop down, and send you back a notification with the text entered
(Not my modules, I just helped solve some problem)
This module reuses an existing routine
https://github.com/sdetweil/new-MP3PlayerThis one calls a new routine
https://github.com/sdetweil/MMM-MyVideoPlayer -
@reverendz the how they work part
The sender calls
this.sendNotification(x,y)Where x is the notification code some receiving module has published to accomplish the function you want
And y is whatever parameters that notification code might requireALL modules running will receive a call at their notificationReceived(x,y) function
Any module receiving the message that understands what to do with code x, can handle it
At some time later one of the running modules will call this.sendNotification(q,z). With a response and ALL modules running will hear it.