matterbridge 2.1.6-dev.4 → 2.1.6-dev.6

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
@@ -1,4 +1,4 @@
1
- # <img src="https://github.com/Luligu/matterbridge/blob/main/frontend/public/matterbridge%2064x64.png" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge changelog
1
+ # <img src="frontend/public/matterbridge.svg" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge changelog
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
@@ -33,22 +33,24 @@ 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.6] - 2025-02-15
36
+ ## [2.1.6] - 2025-02-18
37
37
 
38
38
  ### Added
39
39
 
40
- - [docker]: Added health check directly in the docker image. No need to change configuration.
40
+ - [docker]: Added health check directly in the docker image. No need to change configuration of docker compose.
41
41
  - [platform]: Saving in the storage the selects for faster loading of plugins.
42
42
  - [icon]: Added matterbridge svg icon (thanks: https://github.com/robvanoostenrijk https://github.com/stuntguy3000).
43
43
  - [frontend]: Added processUptime.
44
44
  - [frontend]: Frontend v.2.4.2.
45
45
  - [PluginManager]: Refactor PluginManager to optimize memory and load time.
46
+ - [frontend]: Added Share fabrics and Stop sharing to the menu. This allows to pair other controllers without the need to share from the first controller.
46
47
 
47
48
  ### Changed
48
49
 
49
50
  - [package]: Update matter.js to 0.12.4-alpha.0-20250212-b2729c9eb
50
51
  - [package]: Update matter.js to 0.12.4-alpha.0-20250213-1187f81eb
51
52
  - [package]: Update matter.js to 0.12.4-alpha.0-20250215-5af08a8d6
53
+ - [package]: Update matter.js to 0.12.4-alpha.0-20250217-b0bba5179
52
54
 
53
55
  <a href="https://www.buymeacoffee.com/luligugithub">
54
56
  <img src="./yellow-button.png" alt="Buy me a coffee" width="120">
@@ -259,7 +261,7 @@ matterbridge-hass v. 0.0.8
259
261
 
260
262
  ### Added
261
263
 
262
- - [edge]: Added guide https://github.com/Luligu/matterbridge/blob/dev/README-EDGE.md.
264
+ - [edge]: Added guide [README-EDGE.md](README-EDGE.md).
263
265
  - [storage]: Added conversion from old matter storage to the new api format with fabrics, resumptionRecords, network, commissioning, operationalCredentials, acl and parts number. The conversion is triggered every time you shutdown or restart matterbridge till the new storage has been used with matterbridge edge.
264
266
  - [storage]: Added conversion for child endpoint numbers.
265
267
  - [storage]: Added conversion for childbridge mode.
@@ -396,7 +398,7 @@ It is possible that some controllers see them as new devices or need time to rea
396
398
  ### Added
397
399
 
398
400
  - [matter.js]: Almost completed the phase 2 of migration to edge (matter.js new API).
399
- - [nginx]: Added the route /matterbridge/ to be used with nginx proxy server https://github.com/Luligu/matterbridge/blob/dev/README-NGINX.md.
401
+ - [nginx]: Added the route /matterbridge/ to be used with nginx proxy server [README-NGINX.md](README-NGINX.md).
400
402
  - [config]: Config and schema are loaded before loading the plugin to allow to configure the plugin even when it throws error on load.
401
403
  - [config]: Added version to the config.
402
404
  - [frontend]: Added badge "edge" when running in edge mode.
@@ -600,7 +602,7 @@ It is possible that some controllers see them as new devices or need time to rea
600
602
 
601
603
  ### Breaking Changes for developers
602
604
 
603
- - please read this [Development guide lines](https://github.com/Luligu/matterbridge/blob/main/README-DEV.md)
605
+ - please read this [Development guide lines](README-DEV.md)
604
606
 
605
607
  ### Added
606
608
 
package/README-DEV.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src="https://github.com/Luligu/matterbridge/blob/main/frontend/public/matterbridge%2064x64.png" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
1
+ # <img src="frontend/public/matterbridge.svg" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
4
4
  [![npm downloads](https://img.shields.io/npm/dt/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
package/README-DOCKER.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src="https://github.com/Luligu/matterbridge/blob/main/frontend/public/matterbridge%2064x64.png" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
1
+ # <img src="frontend/public/matterbridge.svg" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
4
4
  [![npm downloads](https://img.shields.io/npm/dt/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
package/README-EDGE.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src="https://github.com/Luligu/matterbridge/blob/main/frontend/public/matterbridge%2064x64.png" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge edge
1
+ # <img src="frontend/public/matterbridge.svg" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge edge
2
2
 
3
3
  Matterbridge Edge is the version of Matterbridge running with the new Matter.js API.
4
4
 
package/README-NGINX.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src="https://github.com/Luligu/matterbridge/blob/main/frontend/public/matterbridge%2064x64.png" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
1
+ # <img src="frontend/public/matterbridge.svg" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
4
4
  [![npm downloads](https://img.shields.io/npm/dt/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
package/README-PODMAN.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src="https://github.com/Luligu/matterbridge/blob/main/frontend/public/matterbridge%2064x64.png" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
1
+ # <img src="frontend/public/matterbridge.svg" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
4
4
  [![npm downloads](https://img.shields.io/npm/dt/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
package/README-SERVICE.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src="https://github.com/Luligu/matterbridge/blob/main/frontend/public/matterbridge%2064x64.png" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
1
+ # <img src="frontend/public/matterbridge.svg" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
4
4
  [![npm downloads](https://img.shields.io/npm/dt/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src="https://github.com/Luligu/matterbridge/blob/main/frontend/public/matterbridge%2064x64.png" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
1
+ # <img src="frontend/public/matterbridge.svg" alt="Matterbridge Logo" width="64px" height="64px">&nbsp;&nbsp;&nbsp;Matterbridge
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
4
4
  [![npm downloads](https://img.shields.io/npm/dt/matterbridge.svg)](https://www.npmjs.com/package/matterbridge)
@@ -121,34 +121,34 @@ To use the frontend with ssl place the certificates in the .matterbridge/certs d
121
121
  From the frontend you can do all operations in an easy way.
122
122
 
123
123
  Home page:
124
- ![See the screenshot here](https://github.com/Luligu/matterbridge/blob/main/screenshot/Screenshot%20home.jpg)
124
+ ![See the screenshot here](screenshot/Screenshot%20home.jpg)
125
125
 
126
126
  Devices page:
127
- [See the screenshot here](https://github.com/Luligu/matterbridge/blob/main/screenshot/Screenshot%20devices.jpg)
127
+ [See the screenshot here](screenshot/Screenshot%20devices.jpg)
128
128
 
129
129
  Logs page:
130
- [See the screenshot here](https://github.com/Luligu/matterbridge/blob/main/screenshot/Screenshot%20logs.jpg)
130
+ [See the screenshot here](screenshot/Screenshot%20logs.jpg)
131
131
 
132
132
  Config editor:
133
- [See the screenshot here](https://github.com/Luligu/matterbridge/blob/main/screenshot/Screenshot%20config%20editor.jpg)
133
+ [See the screenshot here](screenshot/Screenshot%20config%20editor.jpg)
134
134
 
135
135
  ## Advanced configurations
136
136
 
137
137
  ### Run matterbridge as a daemon with systemctl (Linux only)
138
138
 
139
- [Service configurations](https://github.com/Luligu/matterbridge/blob/main/README-SERVICE.md)
139
+ [Service configurations](README-SERVICE.md)
140
140
 
141
141
  ### Run matterbridge with docker and docker compose
142
142
 
143
- [Docker configurations](https://github.com/Luligu/matterbridge/blob/main/README-DOCKER.md)
143
+ [Docker configurations](README-DOCKER.md)
144
144
 
145
145
  ### Run matterbridge with podman
146
146
 
147
- [Podman configurations](https://github.com/Luligu/matterbridge/blob/main/README-PODMAN.md)
147
+ [Podman configurations](README-PODMAN.md)
148
148
 
149
149
  ### Run matterbridge with nginx
150
150
 
151
- [Nginx configurations](https://github.com/Luligu/matterbridge/blob/main/README-NGINX.md)
151
+ [Nginx configurations](README-NGINX.md)
152
152
 
153
153
  ### Run matterbridge as an home assistant add-on with the official add-on
154
154
 
@@ -160,14 +160,14 @@ The other Home Assistant Community Add-ons and plugins are not verified to work
160
160
 
161
161
  ## Development
162
162
 
163
- [Development](https://github.com/Luligu/matterbridge/blob/main/README-DEV.md)
163
+ [Development](README-DEV.md)
164
164
 
165
165
  ## Plugins
166
166
 
167
167
  ### Shelly
168
168
 
169
169
  <a href="https://github.com/Luligu/matterbridge-shelly">
170
- <img src="https://github.com/Luligu/matterbridge/blob/dev/screenshot/Shelly.png" alt="Shelly plugin logo" width="100" />
170
+ <img src="screenshot/Shelly.svg" alt="Shelly plugin logo" width="100" />
171
171
  </a>
172
172
 
173
173
  Matterbridge shelly plugin allows you to expose all Shelly Gen 1, Gen 2, Gen 3 and BLU devices to Matter.
@@ -196,7 +196,7 @@ Features:
196
196
  ### Zigbee2MQTT
197
197
 
198
198
  <a href="https://github.com/Luligu/matterbridge-zigbee2mqtt">
199
- <img src="https://github.com/Luligu/matterbridge/blob/dev/screenshot/Zigbee2MQTT.png" alt="Zigbee2MQTT plugin logo" width="100" />
199
+ <img src="screenshot/Zigbee2MQTT.svg" alt="Zigbee2MQTT plugin logo" width="100" />
200
200
  </a>
201
201
 
202
202
  Matterbridge zigbee2mqtt is a matterbridge production-level plugin that expose all zigbee2mqtt devices and groups to Matter.
@@ -206,7 +206,7 @@ No hub or dedicated hardware needed.
206
206
  ### Somfy tahoma
207
207
 
208
208
  <a href="https://github.com/Luligu/matterbridge-somfy-tahoma">
209
- <img src="https://github.com/Luligu/matterbridge/blob/dev/screenshot/Somfy.png" alt="Somfy plugin logo" width="100" />
209
+ <img src="screenshot/Somfy.svg" alt="Somfy plugin logo" width="100" />
210
210
  </a>
211
211
 
212
212
  Matterbridge Somfy Tahoma is a matterbridge production-level plugin that expose the Somfy Tahoma screen devices to Matter.
@@ -351,7 +351,7 @@ Place your own certificates in the `.matterbridge/cert` directory:
351
351
  - `key.pem`
352
352
  - `ca.pem` (optional)
353
353
 
354
- ![image](https://github.com/user-attachments/assets/846785ca-6f5c-458b-b786-a6417a4da319)
354
+ ![image](screenshot/Screenshot%20Certificates.png)
355
355
 
356
356
  ### Change the command line
357
357
 
@@ -365,7 +365,7 @@ matterbridge -ssl -frontend 443
365
365
 
366
366
  If the certificate are correctly configured, you will be able to connect with https to the frontend.
367
367
 
368
- ![image](https://github.com/user-attachments/assets/9c38776d-064f-4d91-9359-a2cd3319b1ff)
368
+ ![image](screenshot/Screenshot%20Browser%20Secured.png)
369
369
 
370
370
  ## How to send the debug log files
371
371
 
@@ -373,9 +373,9 @@ If the certificate are correctly configured, you will be able to connect with ht
373
373
 
374
374
  In the frontend, go to settings and enable debug mode as shown below:
375
375
 
376
- ![Debug Matterbridge Settings](https://github.com/user-attachments/assets/83181dc2-969a-4b71-aff4-f1498fa1d665)
376
+ ![Debug Matterbridge Settings](screenshot/Screenshot%20Matterbridge%20Logger%20Debug.png)
377
377
 
378
- ![Debug Matter Settings](https://github.com/user-attachments/assets/617961a9-7cb0-46cf-9878-981f61738f8c)
378
+ ![Debug Matter Settings](screenshot/Screenshot%20Matter%20Logger%20Debug.png)
379
379
 
380
380
  ### Restart
381
381
 
@@ -383,7 +383,7 @@ Wait a few minutes to allow the logs to to accumulate.
383
383
 
384
384
  Then, from the dots menu in the frontend, download the `matterbridge.log` and `matter.log` files.
385
385
 
386
- ![image](https://github.com/user-attachments/assets/04ba65f6-594a-4ff8-9732-3df049f5a33e)
386
+ ![image](screenshot/Screenshot%20Debug%20Download%20Logs.png)
387
387
 
388
388
  # Known general issues
389
389
 
package/dist/cli.js CHANGED
@@ -1,62 +1,48 @@
1
1
  #!/usr/bin/env node
2
2
  import { Matterbridge } from './matterbridge.js';
3
- import { EventEmitter } from 'events';
3
+ import { getIntParameter, hasParameter } from './utils/export.js';
4
+ import { AnsiLogger, BRIGHT, CYAN, db, YELLOW } from './logger/export.js';
5
+ import { EventEmitter } from 'node:events';
4
6
  export const cliEmitter = new EventEmitter();
5
7
  export let instance;
6
8
  let session;
7
9
  let memoryCheckInterval;
8
10
  let prevCpus;
9
11
  export let lastCpuUsage = 0;
10
- const cli = '\u001B[32m';
11
- const er = '\u001B[38;5;9m';
12
- const rs = '\u001B[40;0m';
13
- const db = '\u001B[38;5;245m';
14
- const CYAN = '\u001B[36m';
15
- const YELLOW = '\u001B[33m';
16
- const BRIGHT = '\u001B[1m';
17
- async function main() {
18
- await startCpuMemoryCheck();
19
- if (process.argv.includes('-inspector'))
20
- await startInspector();
21
- if (process.argv.includes('-debug'))
22
- console.log(cli + `CLI: Matterbridge.loadInstance() called` + rs);
23
- instance = await Matterbridge.loadInstance(true);
24
- registerHandlers();
25
- if (process.argv.includes('-debug'))
26
- console.log(cli + `CLI: Matterbridge.loadInstance() exited` + rs);
27
- }
12
+ let peakCpu = 0;
13
+ let peakRss = 0;
14
+ const log = new AnsiLogger({ logName: 'Cli', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
15
+ const formatMemoryUsage = (bytes) => {
16
+ if (bytes >= 1024 ** 3) {
17
+ return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
18
+ }
19
+ else if (bytes >= 1024 ** 2) {
20
+ return `${(bytes / 1024 ** 2).toFixed(2)} MB`;
21
+ }
22
+ else {
23
+ return `${(bytes / 1024).toFixed(2)} KB`;
24
+ }
25
+ };
26
+ const formatOsUpTime = (seconds) => {
27
+ if (seconds >= 86400) {
28
+ const days = Math.floor(seconds / 86400);
29
+ return `${days} day${days !== 1 ? 's' : ''}`;
30
+ }
31
+ if (seconds >= 3600) {
32
+ const hours = Math.floor(seconds / 3600);
33
+ return `${hours} hour${hours !== 1 ? 's' : ''}`;
34
+ }
35
+ if (seconds >= 60) {
36
+ const minutes = Math.floor(seconds / 60);
37
+ return `${minutes} minute${minutes !== 1 ? 's' : ''}`;
38
+ }
39
+ return `${seconds} second${seconds !== 1 ? 's' : ''}`;
40
+ };
28
41
  async function startCpuMemoryCheck() {
29
42
  const os = await import('node:os');
30
- if (process.argv.includes('-debug'))
31
- console.log(cli + `CLI: Cpu memory check started` + rs);
43
+ log.debug(`Cpu memory check started`);
32
44
  prevCpus = os.cpus();
33
45
  clearInterval(memoryCheckInterval);
34
- const formatMemoryUsage = (bytes) => {
35
- if (bytes >= 1024 ** 3) {
36
- return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
37
- }
38
- else if (bytes >= 1024 ** 2) {
39
- return `${(bytes / 1024 ** 2).toFixed(2)} MB`;
40
- }
41
- else {
42
- return `${(bytes / 1024).toFixed(2)} KB`;
43
- }
44
- };
45
- const formatOsUpTime = (seconds) => {
46
- if (seconds >= 86400) {
47
- const days = Math.floor(seconds / 86400);
48
- return `${days} day${days !== 1 ? 's' : ''}`;
49
- }
50
- if (seconds >= 3600) {
51
- const hours = Math.floor(seconds / 3600);
52
- return `${hours} hour${hours !== 1 ? 's' : ''}`;
53
- }
54
- if (seconds >= 60) {
55
- const minutes = Math.floor(seconds / 60);
56
- return `${minutes} minute${minutes !== 1 ? 's' : ''}`;
57
- }
58
- return `${seconds} second${seconds !== 1 ? 's' : ''}`;
59
- };
60
46
  const interval = () => {
61
47
  const systemUptime = formatOsUpTime(Math.floor(os.uptime()));
62
48
  const processUptime = formatOsUpTime(Math.floor(process.uptime()));
@@ -69,13 +55,14 @@ async function startCpuMemoryCheck() {
69
55
  const heapUsed = formatMemoryUsage(memoryUsageRaw.heapUsed);
70
56
  const external = formatMemoryUsage(memoryUsageRaw.external);
71
57
  const arrayBuffers = formatMemoryUsage(memoryUsageRaw.arrayBuffers);
58
+ if (memoryUsageRaw.rss > peakRss)
59
+ peakRss = memoryUsageRaw.rss;
72
60
  cliEmitter.emit('memory', totalMememory, freeMemory, rss, heapTotal, heapUsed, external, arrayBuffers);
73
61
  const currCpus = os.cpus();
74
62
  let cpuUsageLog;
75
63
  if (currCpus.length !== prevCpus.length) {
76
64
  prevCpus = currCpus;
77
- if (process.argv.includes('-debug'))
78
- console.log(cli + `CLI: Cpu check length failed, resetting previous cpus` + rs);
65
+ log.debug(`Cpu check length failed, resetting previous cpus`);
79
66
  return;
80
67
  }
81
68
  let totalIdle = 0, totalTick = 0;
@@ -88,59 +75,63 @@ async function startCpuMemoryCheck() {
88
75
  });
89
76
  const cpuUsage = 100 - (totalIdle / totalTick) * 100;
90
77
  if (totalTick === 0 || isNaN(cpuUsage) || !isFinite(cpuUsage) || cpuUsage <= 0) {
91
- if (process.argv.includes('-debug') && lastCpuUsage != 0)
92
- console.log(cli + `CLI: Cpu check failed, using previous cpus` + rs);
78
+ if (lastCpuUsage != 0)
79
+ log.debug(`Cpu check failed, using previous cpus`);
93
80
  cpuUsageLog = lastCpuUsage.toFixed(2);
94
81
  }
95
82
  else {
96
83
  cpuUsageLog = cpuUsage.toFixed(2);
97
84
  lastCpuUsage = cpuUsage;
85
+ if (lastCpuUsage > peakCpu)
86
+ peakCpu = lastCpuUsage;
98
87
  cliEmitter.emit('cpu', lastCpuUsage);
99
88
  }
100
89
  prevCpus = currCpus;
101
- if (process.argv.includes('-debug'))
102
- console.log(`${YELLOW}${BRIGHT}Cpu usage:${db} ${CYAN}${cpuUsageLog.padStart(6, ' ')} %${db} ${YELLOW}${BRIGHT}Memory usage:${db} rss ${CYAN}${rss}${db} heapTotal ${CYAN}${heapTotal}${db} heapUsed ${CYAN}${heapUsed}${db} external ${external} arrayBuffers ${arrayBuffers}` +
103
- rs);
90
+ log.debug(`***${YELLOW}${BRIGHT}Cpu usage:${db} ${CYAN}${cpuUsageLog.padStart(6, ' ')} %${db} ${YELLOW}${BRIGHT}Memory usage:${db} rss ${CYAN}${rss}${db} heapTotal ${CYAN}${heapTotal}${db} heapUsed ${CYAN}${heapUsed}${db} external ${external} arrayBuffers ${arrayBuffers}`);
104
91
  };
105
92
  interval();
106
- memoryCheckInterval = setInterval(interval, 10 * 1000);
93
+ memoryCheckInterval = setInterval(interval, getIntParameter('memoryinterval') ?? 10 * 1000);
107
94
  }
108
95
  async function stopCpuMemoryCheck() {
109
- if (process.argv.includes('-debug'))
110
- console.log(cli + `CLI: Cpu memory check stopped` + rs);
96
+ log.debug(`***Cpu memory check stopped. Peak cpu: ${CYAN}${peakCpu.toFixed(2)} %${db}. Peak rss: ${CYAN}${formatMemoryUsage(peakRss)}${db}.`);
111
97
  clearInterval(memoryCheckInterval);
112
98
  }
113
99
  async function startInspector() {
114
100
  const { Session } = await import('node:inspector');
115
- if (process.argv.includes('-debug'))
116
- console.log(cli + `CLI: Starting heap sampling...` + rs);
101
+ log.debug(`Starting heap sampling...`);
117
102
  session = new Session();
118
103
  session.connect();
119
- session.post('HeapProfiler.startSampling', {}, (err) => {
120
- if (err)
121
- console.error(err);
122
- else
123
- console.log(cli + `CLI: Heap sampling started` + rs);
104
+ await new Promise((resolve, reject) => {
105
+ session?.post('HeapProfiler.startSampling', {}, (err) => (err ? reject(err) : resolve()));
124
106
  });
107
+ log.debug(`Started heap sampling`);
125
108
  }
126
109
  async function stopInspector() {
127
110
  const { writeFileSync } = await import('node:fs');
128
- if (process.argv.includes('-debug'))
129
- console.log(cli + `CLI: Stopping heap sampling...` + rs);
130
- session?.post('HeapProfiler.stopSampling', (err, result) => {
131
- if (err) {
132
- console.error(err);
133
- }
134
- else {
135
- const profile = JSON.stringify(result.profile, null, 2);
136
- writeFileSync('heap-sampling-profile.heapsnapshot', profile);
137
- console.log(cli + `CLI: Heap sampling profile saved to heap-sampling-profile.heapsnapshot` + rs);
138
- }
139
- session?.disconnect();
111
+ log.debug(`Stopping heap sampling...`);
112
+ if (!session) {
113
+ log.error('No active inspector session.');
114
+ return;
115
+ }
116
+ try {
117
+ const result = await new Promise((resolve, reject) => {
118
+ session?.post('HeapProfiler.stopSampling', (err, result) => (err ? reject(err) : resolve(result)));
119
+ });
120
+ const profile = JSON.stringify(result.profile);
121
+ writeFileSync('Heap-sampling-profile.heapprofile', profile);
122
+ log.debug('Heap sampling profile saved to Heap-sampling-profile.heapprofile');
123
+ }
124
+ catch (err) {
125
+ log.error(`Failed to stop heap sampling: ${err instanceof Error ? err.message : err}`);
126
+ }
127
+ finally {
128
+ session.disconnect();
140
129
  session = undefined;
141
- });
130
+ log.debug(`Stopped heap sampling`);
131
+ }
142
132
  }
143
133
  function registerHandlers() {
134
+ log.debug('Registering event handlers...');
144
135
  if (instance)
145
136
  instance.on('shutdown', async () => shutdown());
146
137
  if (instance)
@@ -151,38 +142,49 @@ function registerHandlers() {
151
142
  instance.on('startmemorycheck', async () => start());
152
143
  if (instance)
153
144
  instance.on('stopmemorycheck', async () => stop());
145
+ log.debug('Registered event handlers');
154
146
  }
155
147
  async function shutdown() {
156
- if (process.argv.includes('-debug'))
157
- console.log(cli + 'CLI: received shutdown event, exiting...' + rs);
158
- if (process.argv.includes('-inspector'))
148
+ log.debug('Received shutdown event, exiting...');
149
+ if (hasParameter('inspect'))
159
150
  await stopInspector();
160
151
  await stopCpuMemoryCheck();
161
152
  process.exit(0);
162
153
  }
163
154
  async function restart() {
164
- if (process.argv.includes('-debug'))
165
- console.log(cli + 'CLI: received restart event, loading...' + rs);
155
+ log.debug('Received restart event, loading...');
166
156
  instance = await Matterbridge.loadInstance(true);
167
157
  registerHandlers();
168
158
  }
169
159
  async function update() {
170
- if (process.argv.includes('-debug'))
171
- console.log(cli + 'CLI: received update event, updating...' + rs);
160
+ log.debug('Received update event, updating...');
172
161
  instance = await Matterbridge.loadInstance(true);
173
162
  registerHandlers();
174
163
  }
175
164
  async function start() {
176
- if (process.argv.includes('-debug'))
177
- console.log(cli + 'CLI: received start memory check event' + rs);
165
+ log.debug('Received start memory check event');
178
166
  startCpuMemoryCheck();
179
167
  }
180
168
  async function stop() {
181
- if (process.argv.includes('-debug'))
182
- console.log(cli + 'CLI: received stop memory check event' + rs);
169
+ log.debug('Received stop memory check event');
183
170
  stopCpuMemoryCheck();
184
171
  }
172
+ async function main() {
173
+ log.debug(`Cli main() started`);
174
+ await startCpuMemoryCheck();
175
+ if (hasParameter('inspect'))
176
+ await startInspector();
177
+ log.debug(`***Matterbridge.loadInstance(true) called`);
178
+ instance = await Matterbridge.loadInstance(true);
179
+ log.debug(`***Matterbridge.loadInstance(true) exited`);
180
+ if (!instance || instance.shutdown) {
181
+ shutdown();
182
+ }
183
+ else {
184
+ registerHandlers();
185
+ }
186
+ }
185
187
  process.title = 'matterbridge';
186
188
  main().catch((error) => {
187
- console.error(er + `CLI: Matterbridge.loadInstance() failed with error: ${error}` + rs);
189
+ log.error(`Matterbridge.loadInstance() failed with error: ${error instanceof Error ? error.message : error}`);
188
190
  });
package/dist/frontend.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import { EndpointServer, Logger, LogLevel as MatterLogLevel, LogFormat as MatterLogFormat } from '@matter/main';
2
- import { createServer } from 'http';
2
+ import { createServer } from 'node:http';
3
3
  import https from 'https';
4
4
  import express from 'express';
5
5
  import WebSocket, { WebSocketServer } from 'ws';
6
- import os from 'os';
7
- import path from 'path';
8
- import { promises as fs } from 'fs';
6
+ import os from 'node:os';
7
+ import path from 'node:path';
8
+ import { promises as fs } from 'node:fs';
9
9
  import { AnsiLogger, stringify, debugStringify, CYAN, db, er, nf, rs, UNDERLINE, UNDERLINEOFF, wr, YELLOW } from './logger/export.js';
10
- import { createZip, deepCopy, hasParameter, isValidNumber, isValidObject, isValidString } from './utils/utils.js';
10
+ import { createZip, deepCopy, isValidNumber, isValidObject, isValidString } from './utils/export.js';
11
11
  import { plg } from './matterbridgeTypes.js';
12
+ import { hasParameter } from './utils/export.js';
12
13
  export const WS_ID_LOG = 0;
13
14
  export const WS_ID_REFRESH_NEEDED = 1;
14
15
  export const WS_ID_RESTART_NEEDED = 2;
@@ -236,7 +237,7 @@ export class Frontend {
236
237
  space_available_size: this.formatMemoryUsage(space.space_available_size),
237
238
  physical_space_size: this.formatMemoryUsage(space.physical_space_size),
238
239
  }));
239
- const { default: module } = await import('module');
240
+ const { default: module } = await import('node:module');
240
241
  const loadedModules = module._cache ? Object.keys(module._cache).sort() : [];
241
242
  const memoryReport = {
242
243
  memoryUsage,
@@ -1086,9 +1087,22 @@ export class Frontend {
1086
1087
  }
1087
1088
  else if (data.method === '/api/advertise') {
1088
1089
  const pairingCodes = await this.matterbridge.advertiseServerNode(this.matterbridge.serverNode);
1090
+ this.matterbridge.matterbridgeInformation.matterbridgeAdvertise = true;
1091
+ this.matterbridge.matterbridgeQrPairingCode = pairingCodes?.qrPairingCode;
1092
+ this.matterbridge.matterbridgeManualPairingCode = pairingCodes?.manualPairingCode;
1093
+ this.wssSendRefreshRequired();
1094
+ this.wssSendSnackbarMessage(`Started fabrics share`, 0);
1089
1095
  client.send(JSON.stringify({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, response: pairingCodes }));
1090
1096
  return;
1091
1097
  }
1098
+ else if (data.method === '/api/stopadvertise') {
1099
+ await this.matterbridge.stopAdvertiseServerNode(this.matterbridge.serverNode);
1100
+ this.matterbridge.matterbridgeInformation.matterbridgeAdvertise = false;
1101
+ this.wssSendRefreshRequired();
1102
+ this.wssSendSnackbarMessage(`Stopped fabrics share`, 0);
1103
+ client.send(JSON.stringify({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src }));
1104
+ return;
1105
+ }
1092
1106
  else if (data.method === '/api/settings') {
1093
1107
  client.send(JSON.stringify({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, response: await this.getApiSettings() }));
1094
1108
  return;
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { Matterbridge } from './matterbridge.js';
2
+ import { hasParameter } from './utils/export.js';
3
+ import { AnsiLogger } from './logger/export.js';
2
4
  export { SemanticNamespace, ClosureTag, CompassDirectionTag, CompassLocationTag, DirectionTag, ElectricalMeasurementTag, LaundryTag, LevelTag, LocationTag, NumberTag, PositionTag, PowerSourceTag, RefrigeratorTag, RoomAirConditionerTag, SwitchesTag, } from '@matter/main';
3
5
  export * from '@matter/main/clusters';
4
6
  export * from '@matter/main/types';
@@ -11,16 +13,12 @@ export * from './matterbridgeDeviceTypes.js';
11
13
  export * from './matterbridgePlatform.js';
12
14
  export * from './matterbridgeAccessoryPlatform.js';
13
15
  export * from './matterbridgeDynamicPlatform.js';
14
- const cli = '\u001B[32m';
15
- const er = '\u001B[38;5;9m';
16
- const rs = '\u001B[40;0m';
16
+ const log = new AnsiLogger({ logName: 'Main', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
17
17
  async function main() {
18
- if (process.argv.includes('-debug'))
19
- console.log(cli + 'MAIN: Matterbridge.loadInstance() called' + rs);
18
+ log.debug('***Matterbridge.loadInstance() called');
20
19
  await Matterbridge.loadInstance();
21
- if (process.argv.includes('-debug'))
22
- console.log(cli + 'MAIN: Matterbridge.loadInstance() exited' + rs);
20
+ log.debug('***Matterbridge.loadInstance() exited');
23
21
  }
24
22
  main().catch((error) => {
25
- console.error(er + `MAIN: Matterbridge.loadInstance() failed with error: ${error}` + rs);
23
+ log.error(`Matterbridge.loadInstance() failed with error: ${error instanceof Error ? error.message : error}`);
26
24
  });