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

Getting module's URL from node_helper before socket connected

Scheduled Pinned Locked Moved Unsolved Feature Requests
8 Posts 4 Posters 885 Views 4 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.
  • M Offline
    MMRIZE
    last edited by May 4, 2022, 7:57 AM

    Is there any convenient way to get the related/launched MM module’s basic URL from node_helper?
    In the module itself, it has .file() can be used. But in node_helper, there is no equivalent. .path would return the local path for the module, not the URL.

    Of course, I might be able to calculate or assume the URL from the path and name, but that way looks not so elegant. Default core modules will have .../modules/default/moduleName but 3rd party would have .../modules/moduleName, I need to distinguish the cases.

    Or the module could send that info to node_helper through socketNotification. But I need that URL in the early initializing stage even when the socket is not connected yet.

    .file() or .url() method of node_helper would be helpful for me.

    S K 2 Replies Last reply May 4, 2022, 12:11 PM Reply Quote 0
    • S Offline
      sdetweil @MMRIZE
      last edited by sdetweil May 4, 2022, 12:33 PM May 4, 2022, 12:11 PM

      @MMRIZE why do u need the url before socket connected.

      nothing ‘needs’ to be done before then. the helpers JOB is to service the module. if it needs config info, then it can’t start is job til notification w that info.

      as u wait for the calendar broadcast, your module has eons of time waiting.

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      S 1 Reply Last reply May 4, 2022, 12:16 PM Reply Quote 0
      • S Offline
        sdetweil @sdetweil
        last edited by sdetweil May 4, 2022, 12:36 PM May 4, 2022, 12:16 PM

        @MMRIZE also, u know that mm’s web server is routed at ~/MagicMirror

        so __dirname with give u path to this file, strip of everything before /modules

        back up one folder from this modules location and u know the root of where modules are located (mroot)

        and mroot/default/defaultmodules.js
        will give u the list of modules in defaults(that don’t use explicit name ‘default/modulename’)

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • K Online
          karsten13 @MMRIZE
          last edited by May 4, 2022, 9:30 PM

          @MMRIZE

          Is there any convenient way to get the related/launched MM module’s basic URL from node_helper?

          AFAIS not really …

          You could iterate over the modules in the config.js doing something like this in the init() of your node_helper:

              const configFilename = path.resolve(
                global.configuration_file || `${global.root_path}/config/config.js`
              );
          
              let config;
              try {
                fs.accessSync(configFilename, fs.F_OK);
                const c = require(configFilename);
                config = Object.assign(c);
              } catch (e) {
                Log.error(name + ": Couldn't read config.js");
                return;
              }
          
              let modules = [];
          
              for (const module of config.modules) {
                if (
                  !modules.includes(module.module) &&
                  !module.disabled
                ) {
                console.dir(module.module);
                }
              }
          

          So you have the names and for knowing what are default modules you could use modules/default/defaultmodules.js

          S 1 Reply Last reply May 4, 2022, 9:59 PM Reply Quote 0
          • S Offline
            sdetweil @karsten13
            last edited by May 4, 2022, 9:59 PM

            @karsten13 wow!!!.. i didn’t think config was available to node_helper…

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            C 1 Reply Last reply May 5, 2022, 10:01 PM Reply Quote 0
            • C Offline
              cowboysdude Module Developer @sdetweil
              last edited by May 5, 2022, 10:01 PM

              @sdetweil Yes I send my config to node_helper in my weather module :)

              S 1 Reply Last reply May 5, 2022, 10:04 PM Reply Quote 0
              • S Offline
                sdetweil @cowboysdude
                last edited by May 5, 2022, 10:04 PM

                @cowboysdude said in Getting module's URL from node_helper before socket connected:

                Yes I send my config to node_helper in my weather module

                but that is not the topic

                without doing ANYTHING

                in the node_helper

                config points to the TOTAL config/config.js
                ALL modules and ALL (config.js) parms to ALL modules…

                this is NOT the merged with defaults view that you would send…

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                1 Reply Last reply Reply Quote 0
                • M Offline
                  MMRIZE
                  last edited by May 6, 2022, 6:34 AM

                  Assuming URL with PATH might be an almost general solution, but Sometimes, People install modules in weird ways like using Symlink. (That way could have some benefit, anyway, this is out of issues) In that case, assuming is somehow picky.

                  My purpose is to rewrite the Translator class to use in Module and node_helper together with one common class. (So that is the reason why pre-connection is needed.)To access translations in both layers, there could be many ways to achieve. However, if the exact URL could be obtained in the background layer, it would be easier and simpler and with the least dependency. (To work on browser and on nodejs layer together)

                  Of course, there could be many alternative approaches. I’m just curious if there could be a better way.

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