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.

    Simplfying my understanding of sendNotification and sendSocketNotification with and without a this

    Scheduled Pinned Locked Moved Development
    6 Posts 2 Posters 375 Views 2 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 @kayakbabe
      last edited by sdetweil

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

      the 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 instead

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

      module-parts.jpeg

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      kayakbabeK 1 Reply Last reply Reply Quote 0
      • kayakbabeK Offline
        kayakbabe @sdetweil
        last edited by

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

        S 2 Replies Last reply Reply Quote 0
        • S Offline
          sdetweil @kayakbabe
          last edited by sdetweil

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

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          S 1 Reply Last reply Reply Quote 0
          • S Offline
            sdetweil @kayakbabe
            last edited by

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

            its the connected module that is responsible for checking if the received notification is intended to go to it…

            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 @sdetweil
              last edited by

              @kayakbabe

              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 own

              some 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

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              1 Reply Last reply Reply Quote 1
              • 1 / 1
              • First post
                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