matterbridge 2.1.5-dev.3 → 2.1.5-dev.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -33,13 +33,15 @@ matterbridge-zigbee2mqtt v. 2.4.4
33
33
  matterbridge-somfy-tahoma v. 1.2.3
34
34
  matterbridge-hass v. 0.0.8
35
35
 
36
- ## [2.1.5] - 2025-02-09
36
+ ## [2.1.5] - 2025-02-10
37
37
 
38
38
  ### Added
39
39
 
40
40
  - [frontend]: Frontend v.2.4.1.
41
41
  - [frontend]: Optimized rendering of all pages.
42
42
  - [frontend]: Added cpuUsed, rss and heapUsed to SystemInformation.
43
+ - [frontend]: Added UiProvider.
44
+ - [frontend]: Added wssSendCpuUpdate, wssSendMemoryUpdate and wssSendSnackbarMessage.
43
45
 
44
46
  ### Changed
45
47
 
@@ -48,6 +50,8 @@ matterbridge-hass v. 0.0.8
48
50
 
49
51
  ### Fixed
50
52
 
53
+ - [matterbridge]: Refactor shutdown sequences for reset and factory reset.
54
+
51
55
  <a href="https://www.buymeacoffee.com/luligugithub">
52
56
  <img src="./yellow-button.png" alt="Buy me a coffee" width="120">
53
57
  </a>
package/dist/frontend.js CHANGED
@@ -15,6 +15,7 @@ export const WS_ID_REFRESH_NEEDED = 1;
15
15
  export const WS_ID_RESTART_NEEDED = 2;
16
16
  export const WS_ID_CPU_UPDATE = 3;
17
17
  export const WS_ID_MEMORY_UPDATE = 4;
18
+ export const WS_ID_SNACKBAR = 5;
18
19
  export class Frontend {
19
20
  matterbridge;
20
21
  log;
@@ -462,6 +463,7 @@ export class Frontend {
462
463
  this.log.notice(`Prepairing the backup...`);
463
464
  await createZip(path.join(os.tmpdir(), `matterbridge.backup.zip`), path.join(this.matterbridge.matterbridgeDirectory), path.join(this.matterbridge.matterbridgePluginDirectory));
464
465
  this.log.notice(`Backup ready to be downloaded.`);
466
+ this.wssSendSnackbarMessage('Backup ready to be downloaded', 10);
465
467
  res.json({ message: 'Command received' });
466
468
  return;
467
469
  }
@@ -749,9 +751,11 @@ export class Frontend {
749
751
  }
750
752
  async stop() {
751
753
  if (hasParameter('memorycheck')) {
754
+ this.wssSendSnackbarMessage('Memory check started', getIntParameter('memorycheck') ?? 5 * 60 * 1000);
752
755
  await new Promise((resolve) => {
753
756
  this.log.debug(`***Memory check started for ${getIntParameter('memorycheck') ?? 5 * 60 * 1000} ms`);
754
757
  setTimeout(() => {
758
+ this.wssSendSnackbarMessage('Memory check stopped', 10);
755
759
  this.log.debug(`***Memory check stopped after ${getIntParameter('memorycheck') ?? 5 * 60 * 1000} ms`);
756
760
  resolve();
757
761
  }, getIntParameter('memorycheck') ?? 5 * 60 * 1000);
@@ -1384,4 +1388,12 @@ export class Frontend {
1384
1388
  }
1385
1389
  });
1386
1390
  }
1391
+ wssSendSnackbarMessage(message, timeout = 5) {
1392
+ this.log.debug('Sending a snackbar message to all connected clients');
1393
+ this.webSocketServer?.clients.forEach((client) => {
1394
+ if (client.readyState === WebSocket.OPEN) {
1395
+ client.send(JSON.stringify({ id: WS_ID_SNACKBAR, src: 'Matterbridge', dst: 'Frontend', method: 'memory_update', params: { message, timeout } }));
1396
+ }
1397
+ });
1398
+ }
1387
1399
  }
@@ -929,61 +929,9 @@ export class Matterbridge extends EventEmitter {
929
929
  await this.cleanup('unregistered all devices and shutting down...', false);
930
930
  }
931
931
  async shutdownProcessAndReset() {
932
- this.log.info('Resetting Matterbridge commissioning information...');
933
- await this.matterStorageManager?.createContext('events')?.clearAll();
934
- await this.matterStorageManager?.createContext('fabrics')?.clearAll();
935
- await this.matterStorageManager?.createContext('root')?.clearAll();
936
- await this.matterStorageManager?.createContext('sessions')?.clearAll();
937
- await this.matterbridgeContext?.clearAll();
938
- await this.stopMatterStorage();
939
- this.log.info('Matter storage reset done! Remove the bridge from the controller.');
940
932
  await this.cleanup('shutting down with reset...', false);
941
933
  }
942
934
  async shutdownProcessAndFactoryReset() {
943
- try {
944
- const file = path.join(this.matterbridgeDirectory, 'matterbridge' + (getParameter('profile') ? '.' + getParameter('profile') : '') + '.json');
945
- this.log.info(`Unlinking old matter storage file: ${file}`);
946
- await fs.unlink(file);
947
- const backup = path.join(this.matterbridgeDirectory, 'matterbridge' + (getParameter('profile') ? '.' + getParameter('profile') : '') + '.backup.json');
948
- this.log.info(`Unlinking old matter storage backup file: ${backup}`);
949
- await fs.unlink(backup);
950
- }
951
- catch (err) {
952
- if (err instanceof Error && err.code !== 'ENOENT') {
953
- this.log.error(`Error unlinking old matter storage file: ${err}`);
954
- }
955
- }
956
- try {
957
- const dir = path.join(this.matterbridgeDirectory, 'matterstorage' + (getParameter('profile') ? '.' + getParameter('profile') : ''));
958
- this.log.info(`Removing matter node storage directory: ${dir}`);
959
- await fs.rm(dir, { recursive: true });
960
- const backup = path.join(this.matterbridgeDirectory, 'matterstorage' + (getParameter('profile') ? '.' + getParameter('profile') : '') + '.backup');
961
- this.log.info(`Removing matter node storage backup directory: ${backup}`);
962
- await fs.rm(backup, { recursive: true });
963
- }
964
- catch (err) {
965
- if (err instanceof Error && err.code !== 'ENOENT') {
966
- this.log.error(`Error removing matter storage directory: ${err}`);
967
- }
968
- }
969
- try {
970
- const dir = path.join(this.matterbridgeDirectory, 'storage' + (getParameter('profile') ? '.' + getParameter('profile') : ''));
971
- this.log.info(`Removing storage directory: ${dir}`);
972
- await fs.rm(dir, { recursive: true });
973
- const backup = path.join(this.matterbridgeDirectory, 'storage' + (getParameter('profile') ? '.' + getParameter('profile') : '') + '.backup');
974
- this.log.info(`Removing storage backup directory: ${backup}`);
975
- await fs.rm(backup, { recursive: true });
976
- }
977
- catch (err) {
978
- if (err instanceof Error && err.code !== 'ENOENT') {
979
- this.log.error(`Error removing storage directory: ${err}`);
980
- }
981
- }
982
- this.log.info('Factory reset done! Remove all paired fabrics from the controllers.');
983
- this.nodeContext = undefined;
984
- this.nodeStorage = undefined;
985
- this.plugins.clear();
986
- this.devices.clear();
987
935
  await this.cleanup('shutting down with factory reset...', false);
988
936
  }
989
937
  async cleanup(message, restart = false) {
@@ -1036,6 +984,15 @@ export class Matterbridge extends EventEmitter {
1036
984
  }
1037
985
  }
1038
986
  this.log.notice('Stopped matter server nodes');
987
+ if (message === 'shutting down with reset...') {
988
+ this.log.info('Resetting Matterbridge commissioning information...');
989
+ await this.matterStorageManager?.createContext('events')?.clearAll();
990
+ await this.matterStorageManager?.createContext('fabrics')?.clearAll();
991
+ await this.matterStorageManager?.createContext('root')?.clearAll();
992
+ await this.matterStorageManager?.createContext('sessions')?.clearAll();
993
+ await this.matterbridgeContext?.clearAll();
994
+ this.log.info('Matter storage reset done! Remove the bridge from the controller.');
995
+ }
1039
996
  await this.stopMatterStorage();
1040
997
  await this.frontend.stop();
1041
998
  try {
@@ -1063,6 +1020,48 @@ export class Matterbridge extends EventEmitter {
1063
1020
  }
1064
1021
  this.plugins.clear();
1065
1022
  this.devices.clear();
1023
+ if (message === 'shutting down with factory reset...') {
1024
+ try {
1025
+ const file = path.join(this.matterbridgeDirectory, 'matterbridge' + (getParameter('profile') ? '.' + getParameter('profile') : '') + '.json');
1026
+ this.log.info(`Unlinking old matter storage file: ${file}`);
1027
+ await fs.unlink(file);
1028
+ const backup = path.join(this.matterbridgeDirectory, 'matterbridge' + (getParameter('profile') ? '.' + getParameter('profile') : '') + '.backup.json');
1029
+ this.log.info(`Unlinking old matter storage backup file: ${backup}`);
1030
+ await fs.unlink(backup);
1031
+ }
1032
+ catch (err) {
1033
+ if (err instanceof Error && err.code !== 'ENOENT') {
1034
+ this.log.error(`Error unlinking old matter storage file: ${err}`);
1035
+ }
1036
+ }
1037
+ try {
1038
+ const dir = path.join(this.matterbridgeDirectory, 'matterstorage' + (getParameter('profile') ? '.' + getParameter('profile') : ''));
1039
+ this.log.info(`Removing matter node storage directory: ${dir}`);
1040
+ await fs.rm(dir, { recursive: true });
1041
+ const backup = path.join(this.matterbridgeDirectory, 'matterstorage' + (getParameter('profile') ? '.' + getParameter('profile') : '') + '.backup');
1042
+ this.log.info(`Removing matter node storage backup directory: ${backup}`);
1043
+ await fs.rm(backup, { recursive: true });
1044
+ }
1045
+ catch (err) {
1046
+ if (err instanceof Error && err.code !== 'ENOENT') {
1047
+ this.log.error(`Error removing matter storage directory: ${err}`);
1048
+ }
1049
+ }
1050
+ try {
1051
+ const dir = path.join(this.matterbridgeDirectory, 'storage' + (getParameter('profile') ? '.' + getParameter('profile') : ''));
1052
+ this.log.info(`Removing storage directory: ${dir}`);
1053
+ await fs.rm(dir, { recursive: true });
1054
+ const backup = path.join(this.matterbridgeDirectory, 'storage' + (getParameter('profile') ? '.' + getParameter('profile') : '') + '.backup');
1055
+ this.log.info(`Removing storage backup directory: ${backup}`);
1056
+ await fs.rm(backup, { recursive: true });
1057
+ }
1058
+ catch (err) {
1059
+ if (err instanceof Error && err.code !== 'ENOENT') {
1060
+ this.log.error(`Error removing storage directory: ${err}`);
1061
+ }
1062
+ }
1063
+ this.log.info('Factory reset done! Remove all paired fabrics from the controllers.');
1064
+ }
1066
1065
  this.deregisterProcesslHandlers();
1067
1066
  if (restart) {
1068
1067
  if (message === 'updating...') {
@@ -1525,7 +1524,7 @@ export class Matterbridge extends EventEmitter {
1525
1524
  });
1526
1525
  };
1527
1526
  try {
1528
- await withTimeout(matterServerNode.close(), 5000);
1527
+ await withTimeout(matterServerNode.close(), 30000);
1529
1528
  this.log.info(`Closed ${matterServerNode.id} server node`);
1530
1529
  }
1531
1530
  catch (error) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "files": {
3
3
  "main.css": "./static/css/main.cf25d33e.css",
4
- "main.js": "./static/js/main.1c3bc5a8.js",
4
+ "main.js": "./static/js/main.0dc7cf45.js",
5
5
  "static/js/453.abd36b29.chunk.js": "./static/js/453.abd36b29.chunk.js",
6
6
  "static/media/roboto-latin-700-normal.woff2": "./static/media/roboto-latin-700-normal.4535474e1cf8598695ad.woff2",
7
7
  "static/media/roboto-latin-500-normal.woff2": "./static/media/roboto-latin-500-normal.7077203b1982951ecf76.woff2",
@@ -61,11 +61,11 @@
61
61
  "static/media/roboto-greek-ext-400-normal.woff": "./static/media/roboto-greek-ext-400-normal.16eb83b4a3b1ea994243.woff",
62
62
  "index.html": "./index.html",
63
63
  "main.cf25d33e.css.map": "./static/css/main.cf25d33e.css.map",
64
- "main.1c3bc5a8.js.map": "./static/js/main.1c3bc5a8.js.map",
64
+ "main.0dc7cf45.js.map": "./static/js/main.0dc7cf45.js.map",
65
65
  "453.abd36b29.chunk.js.map": "./static/js/453.abd36b29.chunk.js.map"
66
66
  },
67
67
  "entrypoints": [
68
68
  "static/css/main.cf25d33e.css",
69
- "static/js/main.1c3bc5a8.js"
69
+ "static/js/main.0dc7cf45.js"
70
70
  ]
71
71
  }
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.1c3bc5a8.js"></script><link href="./static/css/main.cf25d33e.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><base href="./"><link rel="icon" href="./matterbridge 32x32.png"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>Matterbridge</title><link rel="manifest" href="./manifest.json"/><script defer="defer" src="./static/js/main.0dc7cf45.js"></script><link href="./static/css/main.cf25d33e.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>