Read the statement by Michael Teeuw here.
Getting module's URL from node_helper before socket connected
-
@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.
-
@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’) -
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 theinit()
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
-
@karsten13 wow!!!.. i didn’t think config was available to node_helper…
-
@sdetweil Yes I send my config to node_helper in my weather module :)
-
@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…
-
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.