Skip to content

Commit

Permalink
Added an automatic plugin reinstall from npm
Browse files Browse the repository at this point in the history
  • Loading branch information
Luligu committed Jul 4, 2024
1 parent d273cb5 commit b03dbb1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ If you like this project and find it useful, please consider giving it a star on
- [sessions]: Added sessionInfo to matterbridge in bridge mode and to the plugins in childbridge mode.
- [frontend]: Added fabricInfo in bridge mode and in childbridge mode instead of QRCode if already paired.
- [matterbridge]: Added parsePlugin to load the updated data from the plugin even when is disabled.
- [matterbridge]: Added an automatic plugin reinstall from npm when the plugin is not found. (e.g. when the docker image is updated and the plugin is not an official plugin)

### Changed

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"matter-history": "^1.1.2",
"node-ansi-logger": "^1.9.5",
"node-persist-manager": "^1.0.7",
"ws": "^8.17.1"
"ws": "^8.18.0"
},
"devDependencies": {
"@eslint/js": "^9.6.0",
Expand Down
51 changes: 12 additions & 39 deletions src/matterbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,22 @@ export class Matterbridge extends EventEmitter {
for (const plugin of this.registeredPlugins) {
const packageJson = await this.parsePlugin(plugin);
if (packageJson) {
// Update the plugin information
plugin.name = packageJson.name as string;
plugin.version = packageJson.version as string;
plugin.description = packageJson.description as string;
plugin.author = packageJson.author as string;
} else {
this.log.info(`Error parsing plugin ${plg}${plugin.name}${er}. Trying to reinstall it from npm.`);
try {
await this.spawnCommand('npm', ['install', '-g', plugin.name]);
this.log.info(`Plugin ${plg}${plugin.name}${nf} installed correctly.`);
plugin.error = false;
} catch (error) {
plugin.error = true;
plugin.enabled = false;
this.log.error(`Error installing plugin ${plg}${plugin.name}${er}. The plugin is disabled.`);
}
}
this.log.debug(`Creating node storage context for plugin ${plugin.name}`);
plugin.nodeContext = await this.nodeStorage.createStorage(plugin.name);
Expand Down Expand Up @@ -3128,45 +3140,6 @@ export class Matterbridge extends EventEmitter {
this.log.error(`WebSocketServer error: ${error}`);
});

/*
// Create a WebSocket server
const wssPort = 8284;
const wssHost = `ws://${this.systemInformation.ipv4Address}:${wssPort}`;
this.webSocketServer = new WebSocketServer({ port: wssPort, host: this.systemInformation.ipv4Address });
this.log.debug(`WebSocket server created on ${UNDERLINE}${wssHost}${UNDERLINEOFF}${rs}`);
this.webSocketServer.on('listening', () => {
this.log.info(`WebSocketServer is listening on ${UNDERLINE}${wssHost}${UNDERLINEOFF}${rs}`);
return;
});
*/

/*
// Serve React build directory
this.expressApp = express();
this.expressApp.use(express.static(path.join(this.rootDirectory, 'frontend/build')));
// Listen on HTTP
this.expressServer = this.expressApp.listen(port, () => {
this.log.info(`The frontend is listening on ${UNDERLINE}http://${this.systemInformation.ipv4Address}:${port}${UNDERLINEOFF}${rs}`);
this.log.debug(`The frontend is listening on ${UNDERLINE}http://[${this.systemInformation.ipv6Address}]:${port}${UNDERLINEOFF}${rs}`);
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.expressServer.on('error', (error: any) => {
this.log.error(`Frontend error listening on ${UNDERLINE}http://${this.systemInformation.ipv4Address}:${port}${UNDERLINEOFF}${rs}`);
switch (error.code) {
case 'EACCES':
this.log.error(`Port ${port} requires elevated privileges`);
break;
case 'EADDRINUSE':
this.log.error(`Port ${port} is already in use`);
break;
}
process.exit(1);
});
*/

// Endpoint to validate login code
this.expressApp.post('/api/login', express.json(), async (req, res) => {
const { password } = req.body;
Expand Down

0 comments on commit b03dbb1

Please sign in to comment.