mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 04:02:12 +00:00
Improve duplicate module filtering. Update SocketIO catch-all API. (#3523)
- [x] Base your pull requests against the `develop` branch. - [x] Include these infos in the description: > - Does the pull request solve a **related** issue? Yes - solves #3521 > - If so, can you reference the issue like this `Fixes #<issue_number>`? Fixes #3521 (also mentioned in commit message) > - What does the pull request accomplish? Use a list if needed. > > - Updates duplicate module filter method (upstream vs downstream - see #3502) > > - Updates socket io catchall functionality to new API [[docs](https://socket.io/docs/v4/listening-to-events/)]. - [x] Please run `npm run lint:prettier` before submitting - [x] Don't forget to add an entry about your changes to the CHANGELOG.md file.
This commit is contained in:
parent
976c8ae00a
commit
cc1d4ab240
@ -21,6 +21,7 @@ _This release is scheduled to be released on 2024-10-01._
|
|||||||
- [weather] Updated `apiVersion` default from 2.5 to 3.0 (#3424)
|
- [weather] Updated `apiVersion` default from 2.5 to 3.0 (#3424)
|
||||||
- [core] Updated dependencies including stylistic-eslint
|
- [core] Updated dependencies including stylistic-eslint
|
||||||
- [core] Allow custom module positions by setting `allowCustomModulePositions` in `config.js` (fixes #3504, related to https://github.com/MagicMirrorOrg/MagicMirror/pull/3445)
|
- [core] Allow custom module positions by setting `allowCustomModulePositions` in `config.js` (fixes #3504, related to https://github.com/MagicMirrorOrg/MagicMirror/pull/3445)
|
||||||
|
- [core] Updated SocketIO catch all to new API
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
30
js/app.js
30
js/app.js
@ -9,7 +9,6 @@ const Log = require("logger");
|
|||||||
const Server = require(`${__dirname}/server`);
|
const Server = require(`${__dirname}/server`);
|
||||||
const Utils = require(`${__dirname}/utils`);
|
const Utils = require(`${__dirname}/utils`);
|
||||||
const defaultModules = require(`${__dirname}/../modules/default/defaultmodules`);
|
const defaultModules = require(`${__dirname}/../modules/default/defaultmodules`);
|
||||||
const helperhash = {};
|
|
||||||
|
|
||||||
// Get version number.
|
// Get version number.
|
||||||
global.version = require(`${__dirname}/../package.json`).version;
|
global.version = require(`${__dirname}/../package.json`).version;
|
||||||
@ -176,23 +175,15 @@ function App () {
|
|||||||
|
|
||||||
const helperPath = `${moduleFolder}/node_helper.js`;
|
const helperPath = `${moduleFolder}/node_helper.js`;
|
||||||
|
|
||||||
// find out if helper was loaded before for this module
|
let loadHelper = true;
|
||||||
// only load it once
|
try {
|
||||||
let loadHelper = helperhash[moduleName] ? false : true;
|
fs.accessSync(helperPath, fs.R_OK);
|
||||||
|
} catch (e) {
|
||||||
// if this is the 1st time for this module, check for helper file
|
loadHelper = false;
|
||||||
// otherwise, its already loaded, if found
|
Log.log(`No helper found for module: ${moduleName}.`);
|
||||||
if (loadHelper) {
|
|
||||||
try {
|
|
||||||
fs.accessSync(helperPath, fs.R_OK);
|
|
||||||
// indicte we found one to load for this module
|
|
||||||
helperhash[moduleName] = true;
|
|
||||||
} catch (e) {
|
|
||||||
loadHelper = false;
|
|
||||||
Log.log(`No helper found for module: ${moduleName}.`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// if the helper was found, AND needed 1st time
|
|
||||||
|
// if the helper was found
|
||||||
if (loadHelper) {
|
if (loadHelper) {
|
||||||
const Module = require(helperPath);
|
const Module = require(helperPath);
|
||||||
let m = new Module();
|
let m = new Module();
|
||||||
@ -270,7 +261,10 @@ function App () {
|
|||||||
if (module.disabled) continue;
|
if (module.disabled) continue;
|
||||||
if (module.module) {
|
if (module.module) {
|
||||||
if (Utils.moduleHasValidPosition(module.position) || typeof (module.position) === "undefined") {
|
if (Utils.moduleHasValidPosition(module.position) || typeof (module.position) === "undefined") {
|
||||||
modules.push(module.module);
|
// Only add this module to be loaded if it is not a duplicate (repeated instance of the same module)
|
||||||
|
if (!modules.includes(module.module)) {
|
||||||
|
modules.push(module.module);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.warn("Invalid module position found for this configuration:", module);
|
Log.warn("Invalid module position found for this configuration:", module);
|
||||||
}
|
}
|
||||||
|
@ -86,20 +86,9 @@ const NodeHelper = Class.extend({
|
|||||||
Log.log(`Connecting socket for: ${this.name}`);
|
Log.log(`Connecting socket for: ${this.name}`);
|
||||||
|
|
||||||
io.of(this.name).on("connection", (socket) => {
|
io.of(this.name).on("connection", (socket) => {
|
||||||
// add a catch all event.
|
|
||||||
const onevent = socket.onevent;
|
|
||||||
socket.onevent = function (packet) {
|
|
||||||
const args = packet.data || [];
|
|
||||||
onevent.call(this, packet); // original call
|
|
||||||
packet.data = ["*"].concat(args);
|
|
||||||
onevent.call(this, packet); // additional call to catch-all
|
|
||||||
};
|
|
||||||
|
|
||||||
// register catch all.
|
// register catch all.
|
||||||
socket.on("*", (notification, payload) => {
|
socket.onAny((notification, payload) => {
|
||||||
if (notification !== "*") {
|
this.socketNotificationReceived(notification, payload);
|
||||||
this.socketNotificationReceived(notification, payload);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user