• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

what can i do in a module, porting from another mirror project

Scheduled Pinned Locked Moved Development
13 Posts 3 Posters 4.0k Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    sdetweil @sdetweil
    last edited by May 15, 2018, 1:53 PM

    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)

    Sam

    How to add modules

    learning how to use browser developers window for css changes

    1 Reply Last reply Reply Quote 0
    • M Offline
      maxbachmann
      last edited by maxbachmann May 15, 2018, 10:58 PM May 15, 2018, 10:57 PM

      yes there is only sendNotification to send to all modules. So you need to filter those informations:
      the command

      this.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

      1 Reply Last reply Reply Quote 0
      • S Offline
        sdetweil
        last edited by sdetweil May 17, 2018, 6:55 PM May 17, 2018, 1:39 PM

        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)

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        I 1 Reply Last reply May 18, 2018, 7:38 PM Reply Quote 0
        • I Offline
          idoodler Module Developer @sdetweil
          last edited by May 18, 2018, 7:38 PM

          @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.

          1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil
            last edited by May 18, 2018, 8:03 PM

            cool… that would allow my components to communicate in a synchronous mode…

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            1 Reply Last reply Reply Quote 1
            • S Offline
              sdetweil
              last edited by May 18, 2018, 9:20 PM

              @idoodler

              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…

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              I 1 Reply Last reply May 18, 2018, 9:29 PM Reply Quote 0
              • I Offline
                idoodler Module Developer @sdetweil
                last edited by May 18, 2018, 9:29 PM

                @sdetweil A MagicMirror Module has two parts, the node_helper.js and any other required 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 Client

                The communication won’t be encrypted in any way, so don’t pass importand information over the Websocket!

                1 Reply Last reply Reply Quote 0
                • S Offline
                  sdetweil
                  last edited by May 19, 2018, 12:29 PM

                  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.

                  Sam

                  How to add modules

                  learning how to use browser developers window for css changes

                  1 Reply Last reply Reply Quote 1
                  • S Offline
                    sdetweil
                    last edited by May 21, 2018, 3:34 PM

                    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.)

                    Sam

                    How to add modules

                    learning how to use browser developers window for css changes

                    I 1 Reply Last reply May 21, 2018, 3:46 PM Reply Quote 0
                    • I Offline
                      idoodler Module Developer @sdetweil
                      last edited by May 21, 2018, 3:46 PM

                      @sdetweil The module helper communication relies on a websocket connection. Any references will be lost. Try to clone the Object.

                      S 1 Reply Last reply May 29, 2018, 1:40 PM Reply Quote 0
                      • 1
                      • 2
                      • 1 / 2
                      1 / 2
                      • First post
                        6/13
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy