matterbridge 3.0.5 → 3.0.6-dev-20250610-56cd483
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 +18 -0
- package/README.md +1 -1
- package/dist/cli.js +2 -62
- package/dist/cluster/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -23
- package/dist/deviceManager.js +1 -94
- package/dist/evse.js +9 -60
- package/dist/frontend.js +22 -379
- package/dist/helpers.js +0 -51
- package/dist/index.js +1 -28
- package/dist/laundryWasher.js +7 -92
- package/dist/logger/export.js +0 -1
- package/dist/matter/behaviors.js +0 -2
- package/dist/matter/clusters.js +0 -2
- package/dist/matter/devices.js +0 -2
- package/dist/matter/endpoints.js +0 -2
- package/dist/matter/export.js +0 -2
- package/dist/matter/types.js +0 -2
- package/dist/matterbridge.js +101 -879
- package/dist/matterbridgeAccessoryPlatform.js +0 -34
- package/dist/matterbridgeBehaviors.js +1 -49
- package/dist/matterbridgeDeviceTypes.js +15 -578
- package/dist/matterbridgeDynamicPlatform.js +0 -34
- package/dist/matterbridgeEndpoint.js +24 -924
- package/dist/matterbridgeEndpointHelpers.js +10 -172
- package/dist/matterbridgePlatform.js +7 -225
- package/dist/matterbridgeTypes.js +0 -24
- package/dist/pluginManager.js +5 -272
- package/dist/roboticVacuumCleaner.js +6 -81
- package/dist/shelly.js +8 -156
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -53
- package/dist/utils/colorUtils.js +2 -205
- package/dist/utils/commandLine.js +0 -53
- package/dist/utils/copyDirectory.js +16 -37
- package/dist/utils/createDirectory.js +21 -0
- package/dist/utils/createZip.js +2 -42
- package/dist/utils/deepCopy.js +0 -38
- package/dist/utils/deepEqual.js +1 -71
- package/dist/utils/export.js +1 -1
- package/dist/utils/hex.js +0 -57
- package/dist/utils/isvalid.js +0 -100
- package/dist/utils/network.js +5 -76
- package/dist/utils/spawn.js +68 -0
- package/dist/utils/wait.js +11 -59
- package/dist/waterHeater.js +2 -62
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- package/dist/cli.d.ts +0 -29
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cluster/export.d.ts +0 -2
- package/dist/cluster/export.d.ts.map +0 -1
- package/dist/cluster/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -27
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -114
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/evse.d.ts +0 -63
- package/dist/evse.d.ts.map +0 -1
- package/dist/evse.js.map +0 -1
- package/dist/frontend.d.ts +0 -256
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/helpers.d.ts +0 -47
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -37
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/laundryWasher.d.ts +0 -243
- package/dist/laundryWasher.d.ts.map +0 -1
- package/dist/laundryWasher.js.map +0 -1
- package/dist/logger/export.d.ts +0 -2
- package/dist/logger/export.d.ts.map +0 -1
- package/dist/logger/export.js.map +0 -1
- package/dist/matter/behaviors.d.ts +0 -2
- package/dist/matter/behaviors.d.ts.map +0 -1
- package/dist/matter/behaviors.js.map +0 -1
- package/dist/matter/clusters.d.ts +0 -2
- package/dist/matter/clusters.d.ts.map +0 -1
- package/dist/matter/clusters.js.map +0 -1
- package/dist/matter/devices.d.ts +0 -2
- package/dist/matter/devices.d.ts.map +0 -1
- package/dist/matter/devices.js.map +0 -1
- package/dist/matter/endpoints.d.ts +0 -2
- package/dist/matter/endpoints.d.ts.map +0 -1
- package/dist/matter/endpoints.js.map +0 -1
- package/dist/matter/export.d.ts +0 -5
- package/dist/matter/export.d.ts.map +0 -1
- package/dist/matter/export.js.map +0 -1
- package/dist/matter/types.d.ts +0 -3
- package/dist/matter/types.d.ts.map +0 -1
- package/dist/matter/types.js.map +0 -1
- package/dist/matterbridge.d.ts +0 -449
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -40
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -1379
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -644
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -40
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1079
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -2749
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -294
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -196
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -273
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/roboticVacuumCleaner.d.ts +0 -102
- package/dist/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/roboticVacuumCleaner.js.map +0 -1
- package/dist/shelly.d.ts +0 -153
- package/dist/shelly.d.ts.map +0 -1
- package/dist/shelly.js.map +0 -1
- package/dist/storage/export.d.ts +0 -2
- package/dist/storage/export.d.ts.map +0 -1
- package/dist/storage/export.js.map +0 -1
- package/dist/update.d.ts +0 -58
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -61
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -58
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -32
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -38
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -31
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -53
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/export.d.ts +0 -11
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -48
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -102
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/network.d.ts +0 -69
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -52
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
- package/dist/waterHeater.d.ts +0 -90
- package/dist/waterHeater.d.ts.map +0 -1
- package/dist/waterHeater.js.map +0 -1
package/dist/matterbridge.js
CHANGED
|
@@ -1,37 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the class Matterbridge.
|
|
3
|
-
*
|
|
4
|
-
* @file matterbridge.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @date 2023-12-29
|
|
7
|
-
* @version 1.5.3
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2023, 2024, 2025 Luca Liguori.
|
|
10
|
-
*
|
|
11
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
12
|
-
* you may not use this file except in compliance with the License.
|
|
13
|
-
* You may obtain a copy of the License at
|
|
14
|
-
*
|
|
15
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
-
* See the License for the specific language governing permissions and
|
|
21
|
-
* limitations under the License. *
|
|
22
|
-
*/
|
|
23
|
-
// Node.js modules
|
|
24
1
|
import os from 'node:os';
|
|
25
2
|
import path from 'node:path';
|
|
26
3
|
import { promises as fs } from 'node:fs';
|
|
27
4
|
import EventEmitter from 'node:events';
|
|
28
5
|
import { inspect } from 'node:util';
|
|
29
|
-
// AnsiLogger module
|
|
30
6
|
import { AnsiLogger, UNDERLINE, UNDERLINEOFF, YELLOW, db, debugStringify, BRIGHT, RESET, er, nf, rs, wr, RED, GREEN, zb, CYAN } from './logger/export.js';
|
|
31
|
-
// NodeStorage module
|
|
32
7
|
import { NodeStorageManager } from './storage/export.js';
|
|
33
|
-
|
|
34
|
-
import { getParameter, getIntParameter, hasParameter, copyDirectory, withTimeout, waiter, isValidString, parseVersionString, isValidNumber } from './utils/export.js';
|
|
8
|
+
import { getParameter, getIntParameter, hasParameter, copyDirectory, withTimeout, waiter, isValidString, parseVersionString, isValidNumber, createDirectory } from './utils/export.js';
|
|
35
9
|
import { logInterfaces, getGlobalNodeModules } from './utils/network.js';
|
|
36
10
|
import { dev, plg, typ } from './matterbridgeTypes.js';
|
|
37
11
|
import { PluginManager } from './pluginManager.js';
|
|
@@ -40,15 +14,12 @@ import { MatterbridgeEndpoint } from './matterbridgeEndpoint.js';
|
|
|
40
14
|
import { bridge } from './matterbridgeDeviceTypes.js';
|
|
41
15
|
import { Frontend } from './frontend.js';
|
|
42
16
|
import { addVirtualDevices } from './helpers.js';
|
|
43
|
-
|
|
17
|
+
import spawn from './utils/spawn.js';
|
|
44
18
|
import { DeviceTypeId, Endpoint, Logger, LogLevel as MatterLogLevel, LogFormat as MatterLogFormat, VendorId, StorageService, Environment, ServerNode, UINT32_MAX, UINT16_MAX, } from '@matter/main';
|
|
45
19
|
import { DeviceCommissioner, FabricAction, MdnsService, PaseClient } from '@matter/main/protocol';
|
|
46
20
|
import { AggregatorEndpoint } from '@matter/main/endpoints';
|
|
47
21
|
import { BasicInformationServer } from '@matter/main/behaviors/basic-information';
|
|
48
22
|
import { BridgedDeviceBasicInformationServer } from '@matter/main/behaviors/bridged-device-basic-information';
|
|
49
|
-
/**
|
|
50
|
-
* Represents the Matterbridge application.
|
|
51
|
-
*/
|
|
52
23
|
export class Matterbridge extends EventEmitter {
|
|
53
24
|
systemInformation = {
|
|
54
25
|
interfaceName: '',
|
|
@@ -96,7 +67,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
96
67
|
shellySysUpdate: false,
|
|
97
68
|
shellyMainUpdate: false,
|
|
98
69
|
profile: getParameter('profile'),
|
|
99
|
-
loggerLevel: "info"
|
|
70
|
+
loggerLevel: "info",
|
|
100
71
|
fileLogger: false,
|
|
101
72
|
matterLoggerLevel: MatterLogLevel.INFO,
|
|
102
73
|
matterFileLogger: false,
|
|
@@ -135,11 +106,9 @@ export class Matterbridge extends EventEmitter {
|
|
|
135
106
|
plugins;
|
|
136
107
|
devices;
|
|
137
108
|
frontend = new Frontend(this);
|
|
138
|
-
// Matterbridge storage
|
|
139
109
|
nodeStorage;
|
|
140
110
|
nodeContext;
|
|
141
111
|
nodeStorageName = 'storage' + (getParameter('profile') ? '.' + getParameter('profile') : '');
|
|
142
|
-
// Cleanup
|
|
143
112
|
hasCleanupStarted = false;
|
|
144
113
|
initialized = false;
|
|
145
114
|
execRunningCount = 0;
|
|
@@ -148,26 +117,24 @@ export class Matterbridge extends EventEmitter {
|
|
|
148
117
|
checkUpdateTimeout;
|
|
149
118
|
configureTimeout;
|
|
150
119
|
reachabilityTimeout;
|
|
120
|
+
endAdvertiseTimeout;
|
|
151
121
|
sigintHandler;
|
|
152
122
|
sigtermHandler;
|
|
153
123
|
exceptionHandler;
|
|
154
124
|
rejectionHandler;
|
|
155
|
-
// Matter environment
|
|
156
125
|
environment = Environment.default;
|
|
157
|
-
// Matter storage
|
|
158
126
|
matterStorageName = 'matterstorage' + (getParameter('profile') ? '.' + getParameter('profile') : '');
|
|
159
127
|
matterStorageService;
|
|
160
128
|
matterStorageManager;
|
|
161
129
|
matterbridgeContext;
|
|
162
130
|
controllerContext;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
certification; // device certification
|
|
131
|
+
mdnsInterface;
|
|
132
|
+
ipv4address;
|
|
133
|
+
ipv6address;
|
|
134
|
+
port;
|
|
135
|
+
passcode;
|
|
136
|
+
discriminator;
|
|
137
|
+
certification;
|
|
171
138
|
serverNode;
|
|
172
139
|
aggregatorNode;
|
|
173
140
|
aggregatorVendorId = VendorId(getIntParameter('vendorId') ?? 0xfff1);
|
|
@@ -175,50 +142,21 @@ export class Matterbridge extends EventEmitter {
|
|
|
175
142
|
aggregatorProductId = getIntParameter('productId') ?? 0x8000;
|
|
176
143
|
aggregatorProductName = getParameter('productName') ?? 'Matterbridge aggregator';
|
|
177
144
|
static instance;
|
|
178
|
-
// We load asyncronously so is private
|
|
179
145
|
constructor() {
|
|
180
146
|
super();
|
|
181
147
|
}
|
|
182
|
-
/**
|
|
183
|
-
* Emits an event of the specified type with the provided arguments.
|
|
184
|
-
*
|
|
185
|
-
* @template K - The type of the event.
|
|
186
|
-
* @param {K} eventName - The name of the event to emit.
|
|
187
|
-
* @param {...MatterbridgeEvent[K]} args - The arguments to pass to the event listeners.
|
|
188
|
-
* @returns {boolean} - Returns true if the event had listeners, false otherwise.
|
|
189
|
-
*/
|
|
190
148
|
emit(eventName, ...args) {
|
|
191
149
|
return super.emit(eventName, ...args);
|
|
192
150
|
}
|
|
193
|
-
/**
|
|
194
|
-
* Registers an event listener for the specified event type.
|
|
195
|
-
*
|
|
196
|
-
* @template K - The type of the event.
|
|
197
|
-
* @param {K} eventName - The name of the event to listen for.
|
|
198
|
-
* @param {(...args: MatterbridgeEvent[K]) => void} listener - The callback function to invoke when the event is emitted.
|
|
199
|
-
* @returns {this} - Returns the instance of the Matterbridge class.
|
|
200
|
-
*/
|
|
201
151
|
on(eventName, listener) {
|
|
202
152
|
return super.on(eventName, listener);
|
|
203
153
|
}
|
|
204
|
-
/**
|
|
205
|
-
* Retrieves the list of Matterbridge devices.
|
|
206
|
-
* @returns {MatterbridgeEndpoint[]} An array of MatterbridgeDevice objects.
|
|
207
|
-
*/
|
|
208
154
|
getDevices() {
|
|
209
155
|
return this.devices.array();
|
|
210
156
|
}
|
|
211
|
-
/**
|
|
212
|
-
* Retrieves the list of registered plugins.
|
|
213
|
-
* @returns {RegisteredPlugin[]} An array of RegisteredPlugin objects.
|
|
214
|
-
*/
|
|
215
157
|
getPlugins() {
|
|
216
158
|
return this.plugins.array();
|
|
217
159
|
}
|
|
218
|
-
/**
|
|
219
|
-
* Set the logger logLevel for the Matterbridge classes and call onChangeLoggerLevel() for each plugin.
|
|
220
|
-
* @param {LogLevel} logLevel The logger logLevel to set.
|
|
221
|
-
*/
|
|
222
160
|
async setLogLevel(logLevel) {
|
|
223
161
|
if (this.log)
|
|
224
162
|
this.log.logLevel = logLevel;
|
|
@@ -232,31 +170,19 @@ export class Matterbridge extends EventEmitter {
|
|
|
232
170
|
for (const plugin of this.plugins) {
|
|
233
171
|
if (!plugin.platform || !plugin.platform.log || !plugin.platform.config)
|
|
234
172
|
continue;
|
|
235
|
-
plugin.platform.log.logLevel = plugin.platform.config.debug === true ? "debug"
|
|
236
|
-
await plugin.platform.onChangeLoggerLevel(plugin.platform.config.debug === true ? "debug"
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
callbackLogLevel = "debug" /* LogLevel.DEBUG */;
|
|
173
|
+
plugin.platform.log.logLevel = plugin.platform.config.debug === true ? "debug" : this.log.logLevel;
|
|
174
|
+
await plugin.platform.onChangeLoggerLevel(plugin.platform.config.debug === true ? "debug" : this.log.logLevel);
|
|
175
|
+
}
|
|
176
|
+
let callbackLogLevel = "notice";
|
|
177
|
+
if (this.matterbridgeInformation.loggerLevel === "info" || this.matterbridgeInformation.matterLoggerLevel === MatterLogLevel.INFO)
|
|
178
|
+
callbackLogLevel = "info";
|
|
179
|
+
if (this.matterbridgeInformation.loggerLevel === "debug" || this.matterbridgeInformation.matterLoggerLevel === MatterLogLevel.DEBUG)
|
|
180
|
+
callbackLogLevel = "debug";
|
|
244
181
|
AnsiLogger.setGlobalCallback(this.frontend.wssSendMessage.bind(this.frontend), callbackLogLevel);
|
|
245
182
|
this.log.debug(`WebSocketServer logger global callback set to ${callbackLogLevel}`);
|
|
246
183
|
}
|
|
247
|
-
/** ***********************************************************************************************************************************/
|
|
248
|
-
/** loadInstance() and cleanup() methods */
|
|
249
|
-
/** ***********************************************************************************************************************************/
|
|
250
|
-
/**
|
|
251
|
-
* Loads an instance of the Matterbridge class.
|
|
252
|
-
* If an instance already exists, return that instance.
|
|
253
|
-
*
|
|
254
|
-
* @param {boolean} initialize - Whether to initialize the Matterbridge instance after loading. Defaults to false.
|
|
255
|
-
* @returns The loaded Matterbridge instance.
|
|
256
|
-
*/
|
|
257
184
|
static async loadInstance(initialize = false) {
|
|
258
185
|
if (!Matterbridge.instance) {
|
|
259
|
-
// eslint-disable-next-line no-console
|
|
260
186
|
if (hasParameter('debug'))
|
|
261
187
|
console.log(GREEN + 'Creating a new instance of Matterbridge.', initialize ? 'Initializing...' : 'Not initializing...', rs);
|
|
262
188
|
Matterbridge.instance = new Matterbridge();
|
|
@@ -265,14 +191,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
265
191
|
}
|
|
266
192
|
return Matterbridge.instance;
|
|
267
193
|
}
|
|
268
|
-
/**
|
|
269
|
-
* Call cleanup().
|
|
270
|
-
*
|
|
271
|
-
* @deprecated This method is deprecated and is ONLY used for jest tests.
|
|
272
|
-
*/
|
|
273
194
|
async destroyInstance() {
|
|
274
195
|
this.log.info(`Destroy instance...`);
|
|
275
|
-
// Save server nodes to close
|
|
276
196
|
const servers = [];
|
|
277
197
|
if (this.bridgeMode === 'bridge') {
|
|
278
198
|
if (this.serverNode)
|
|
@@ -284,103 +204,72 @@ export class Matterbridge extends EventEmitter {
|
|
|
284
204
|
servers.push(plugin.serverNode);
|
|
285
205
|
}
|
|
286
206
|
}
|
|
287
|
-
// Cleanup
|
|
288
207
|
await this.cleanup('destroying instance...', false);
|
|
289
|
-
// Close servers mdns service
|
|
290
208
|
this.log.info(`Dispose ${servers.length} MdnsService...`);
|
|
291
209
|
for (const server of servers) {
|
|
292
210
|
await server.env.get(MdnsService)[Symbol.asyncDispose]();
|
|
293
211
|
this.log.info(`Closed ${server.id} MdnsService`);
|
|
294
212
|
}
|
|
295
|
-
// Wait for the cleanup to finish
|
|
296
213
|
await new Promise((resolve) => {
|
|
297
214
|
setTimeout(resolve, 500);
|
|
298
215
|
});
|
|
299
216
|
}
|
|
300
|
-
/**
|
|
301
|
-
* Initializes the Matterbridge application.
|
|
302
|
-
*
|
|
303
|
-
* @remarks
|
|
304
|
-
* This method performs the necessary setup and initialization steps for the Matterbridge application.
|
|
305
|
-
* It displays the help information if the 'help' parameter is provided, sets up the logger, checks the
|
|
306
|
-
* node version, registers signal handlers, initializes storage, and parses the command line.
|
|
307
|
-
*
|
|
308
|
-
* @returns A Promise that resolves when the initialization is complete.
|
|
309
|
-
*/
|
|
310
217
|
async initialize() {
|
|
311
|
-
// Emit the initialize_started event
|
|
312
218
|
this.emit('initialize_started');
|
|
313
|
-
|
|
314
|
-
this.log = new AnsiLogger({ logName: 'Matterbridge', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: hasParameter('debug') ? "debug" /* LogLevel.DEBUG */ : "info" /* LogLevel.INFO */ });
|
|
315
|
-
// Set the restart mode
|
|
219
|
+
this.log = new AnsiLogger({ logName: 'Matterbridge', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
|
|
316
220
|
if (hasParameter('service'))
|
|
317
221
|
this.restartMode = 'service';
|
|
318
222
|
if (hasParameter('docker'))
|
|
319
223
|
this.restartMode = 'docker';
|
|
320
|
-
// Set the matterbridge home directory
|
|
321
224
|
this.homeDirectory = getParameter('homedir') ?? os.homedir();
|
|
322
225
|
this.matterbridgeInformation.homeDirectory = this.homeDirectory;
|
|
323
|
-
await
|
|
324
|
-
// Set the matterbridge directory
|
|
226
|
+
await createDirectory(this.homeDirectory, 'Matterbridge Home Directory', this.log);
|
|
325
227
|
this.matterbridgeDirectory = path.join(this.homeDirectory, '.matterbridge');
|
|
326
228
|
this.matterbridgeInformation.matterbridgeDirectory = this.matterbridgeDirectory;
|
|
327
|
-
await
|
|
328
|
-
await
|
|
329
|
-
await
|
|
330
|
-
// Set the matterbridge plugin directory
|
|
229
|
+
await createDirectory(this.matterbridgeDirectory, 'Matterbridge Directory', this.log);
|
|
230
|
+
await createDirectory(path.join(this.matterbridgeDirectory, 'certs'), 'Matterbridge Frontend Certificate Directory', this.log);
|
|
231
|
+
await createDirectory(path.join(this.matterbridgeDirectory, 'uploads'), 'Matterbridge Frontend Uploads Directory', this.log);
|
|
331
232
|
this.matterbridgePluginDirectory = path.join(this.homeDirectory, 'Matterbridge');
|
|
332
233
|
this.matterbridgeInformation.matterbridgePluginDirectory = this.matterbridgePluginDirectory;
|
|
333
|
-
await
|
|
334
|
-
// Set the matterbridge cert directory
|
|
234
|
+
await createDirectory(this.matterbridgePluginDirectory, 'Matterbridge Plugin Directory', this.log);
|
|
335
235
|
this.matterbridgeCertDirectory = path.join(this.homeDirectory, '.mattercert');
|
|
336
236
|
this.matterbridgeInformation.matterbridgeCertDirectory = this.matterbridgeCertDirectory;
|
|
337
|
-
await
|
|
338
|
-
// Set the matterbridge root directory
|
|
237
|
+
await createDirectory(this.matterbridgeCertDirectory, 'Matterbridge Matter Certificate Directory', this.log);
|
|
339
238
|
const { fileURLToPath } = await import('node:url');
|
|
340
239
|
const currentFileDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
341
240
|
this.rootDirectory = path.resolve(currentFileDirectory, '../');
|
|
342
241
|
this.matterbridgeInformation.rootDirectory = this.rootDirectory;
|
|
343
|
-
// Setup the matter environment
|
|
344
242
|
this.environment.vars.set('log.level', MatterLogLevel.INFO);
|
|
345
243
|
this.environment.vars.set('log.format', MatterLogFormat.ANSI);
|
|
346
244
|
this.environment.vars.set('path.root', path.join(this.matterbridgeDirectory, this.matterStorageName));
|
|
347
245
|
this.environment.vars.set('runtime.signals', false);
|
|
348
246
|
this.environment.vars.set('runtime.exitcode', false);
|
|
349
|
-
// Register process handlers
|
|
350
247
|
this.registerProcessHandlers();
|
|
351
|
-
// Initialize nodeStorage and nodeContext
|
|
352
248
|
try {
|
|
353
249
|
this.log.debug(`Creating node storage manager: ${CYAN}${this.nodeStorageName}${db}`);
|
|
354
250
|
this.nodeStorage = new NodeStorageManager({ dir: path.join(this.matterbridgeDirectory, this.nodeStorageName), writeQueue: false, expiredInterval: undefined, logging: false });
|
|
355
251
|
this.log.debug('Creating node storage context for matterbridge');
|
|
356
252
|
this.nodeContext = await this.nodeStorage.createStorage('matterbridge');
|
|
357
|
-
// TODO: Remove this code when node-persist-manager is updated
|
|
358
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
359
253
|
const keys = (await this.nodeStorage?.storage.keys());
|
|
360
254
|
for (const key of keys) {
|
|
361
255
|
this.log.debug(`Checking node storage manager key: ${CYAN}${key}${db}`);
|
|
362
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
363
256
|
await this.nodeStorage?.storage.get(key);
|
|
364
257
|
}
|
|
365
258
|
const storages = await this.nodeStorage.getStorageNames();
|
|
366
259
|
for (const storage of storages) {
|
|
367
260
|
this.log.debug(`Checking storage: ${CYAN}${storage}${db}`);
|
|
368
261
|
const nodeContext = await this.nodeStorage?.createStorage(storage);
|
|
369
|
-
// TODO: Remove this code when node-persist-manager is updated
|
|
370
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
371
262
|
const keys = (await nodeContext?.storage.keys());
|
|
372
263
|
keys.forEach(async (key) => {
|
|
373
264
|
this.log.debug(`Checking key: ${CYAN}${storage}:${key}${db}`);
|
|
374
265
|
await nodeContext?.get(key);
|
|
375
266
|
});
|
|
376
267
|
}
|
|
377
|
-
// Creating a backup of the node storage since it is not corrupted
|
|
378
268
|
this.log.debug('Creating node storage backup...');
|
|
379
269
|
await copyDirectory(path.join(this.matterbridgeDirectory, this.nodeStorageName), path.join(this.matterbridgeDirectory, this.nodeStorageName + '.backup'));
|
|
380
270
|
this.log.debug('Created node storage backup');
|
|
381
271
|
}
|
|
382
272
|
catch (error) {
|
|
383
|
-
// Restoring the backup of the node storage since it is corrupted
|
|
384
273
|
this.log.error(`Error creating node storage manager and context: ${error instanceof Error ? error.message : error}`);
|
|
385
274
|
if (hasParameter('norestore')) {
|
|
386
275
|
this.log.fatal(`The matterbridge node storage is corrupted. Parameter -norestore found: exiting...`);
|
|
@@ -395,19 +284,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
395
284
|
this.log.fatal('Fatal error creating node storage manager and context for matterbridge');
|
|
396
285
|
throw new Error('Fatal error creating node storage manager and context for matterbridge');
|
|
397
286
|
}
|
|
398
|
-
// Set the first port to use for the commissioning server (will be incremented in childbridge mode)
|
|
399
287
|
this.port = getIntParameter('port') ?? (await this.nodeContext.get('matterport', 5540)) ?? 5540;
|
|
400
|
-
// Set the first passcode to use for the commissioning server (will be incremented in childbridge mode)
|
|
401
288
|
this.passcode = getIntParameter('passcode') ?? (await this.nodeContext.get('matterpasscode')) ?? PaseClient.generateRandomPasscode();
|
|
402
|
-
// Set the first discriminator to use for the commissioning server (will be incremented in childbridge mode)
|
|
403
289
|
this.discriminator = getIntParameter('discriminator') ?? (await this.nodeContext.get('matterdiscriminator')) ?? PaseClient.generateRandomDiscriminator();
|
|
404
|
-
// Certificate management
|
|
405
290
|
const pairingFilePath = path.join(this.matterbridgeCertDirectory, 'pairing.json');
|
|
406
291
|
try {
|
|
407
292
|
await fs.access(pairingFilePath, fs.constants.R_OK);
|
|
408
293
|
const pairingFileContent = await fs.readFile(pairingFilePath, 'utf8');
|
|
409
294
|
const pairingFileJson = JSON.parse(pairingFileContent);
|
|
410
|
-
// Set the vendorId, vendorName, productId and productName if they are present in the pairing file
|
|
411
295
|
if (isValidNumber(pairingFileJson.vendorId))
|
|
412
296
|
this.aggregatorVendorId = VendorId(pairingFileJson.vendorId);
|
|
413
297
|
if (isValidString(pairingFileJson.vendorName, 3))
|
|
@@ -416,20 +300,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
416
300
|
this.aggregatorProductId = VendorId(pairingFileJson.productId);
|
|
417
301
|
if (isValidString(pairingFileJson.productName, 3))
|
|
418
302
|
this.aggregatorProductName = pairingFileJson.productName;
|
|
419
|
-
// Override the passcode and discriminator if they are present in the pairing file
|
|
420
303
|
if (isValidNumber(pairingFileJson.passcode) && isValidNumber(pairingFileJson.discriminator)) {
|
|
421
304
|
this.passcode = pairingFileJson.passcode;
|
|
422
305
|
this.discriminator = pairingFileJson.discriminator;
|
|
423
306
|
this.log.info(`Pairing file ${CYAN}${pairingFilePath}${nf} found. Using passcode ${CYAN}${this.passcode}${nf} and discriminator ${CYAN}${this.discriminator}${nf} from pairing file.`);
|
|
424
307
|
}
|
|
425
|
-
// Set the certification if it is present in the pairing file
|
|
426
308
|
if (pairingFileJson.privateKey && pairingFileJson.certificate && pairingFileJson.intermediateCertificate && pairingFileJson.declaration) {
|
|
427
309
|
const hexStringToUint8Array = (hexString) => {
|
|
428
310
|
const matches = hexString.match(/.{1,2}/g);
|
|
429
311
|
return matches ? new Uint8Array(matches.map((byte) => parseInt(byte, 16))) : new Uint8Array();
|
|
430
312
|
};
|
|
431
|
-
// const hexString = Buffer.from('Test string', 'utf-8').toString('hex');
|
|
432
|
-
// console.log(hexString, Buffer.from(hexStringToUint8Array(hexString)).toString('utf-8'));
|
|
433
313
|
this.certification = {
|
|
434
314
|
privateKey: hexStringToUint8Array(pairingFileJson.privateKey),
|
|
435
315
|
certificate: hexStringToUint8Array(pairingFileJson.certificate),
|
|
@@ -442,44 +322,41 @@ export class Matterbridge extends EventEmitter {
|
|
|
442
322
|
catch (error) {
|
|
443
323
|
this.log.debug(`Pairing file ${CYAN}${pairingFilePath}${db} not found: ${error instanceof Error ? error.message : error}`);
|
|
444
324
|
}
|
|
445
|
-
// Store the passcode, discriminator and port in the node context
|
|
446
325
|
await this.nodeContext.set('matterport', this.port);
|
|
447
326
|
await this.nodeContext.set('matterpasscode', this.passcode);
|
|
448
327
|
await this.nodeContext.set('matterdiscriminator', this.discriminator);
|
|
449
328
|
this.log.debug(`Initializing server node for Matterbridge on port ${this.port} with passcode ${this.passcode} and discriminator ${this.discriminator}`);
|
|
450
|
-
// Set matterbridge logger level (context: matterbridgeLogLevel)
|
|
451
329
|
if (hasParameter('logger')) {
|
|
452
330
|
const level = getParameter('logger');
|
|
453
331
|
if (level === 'debug') {
|
|
454
|
-
this.log.logLevel = "debug"
|
|
332
|
+
this.log.logLevel = "debug";
|
|
455
333
|
}
|
|
456
334
|
else if (level === 'info') {
|
|
457
|
-
this.log.logLevel = "info"
|
|
335
|
+
this.log.logLevel = "info";
|
|
458
336
|
}
|
|
459
337
|
else if (level === 'notice') {
|
|
460
|
-
this.log.logLevel = "notice"
|
|
338
|
+
this.log.logLevel = "notice";
|
|
461
339
|
}
|
|
462
340
|
else if (level === 'warn') {
|
|
463
|
-
this.log.logLevel = "warn"
|
|
341
|
+
this.log.logLevel = "warn";
|
|
464
342
|
}
|
|
465
343
|
else if (level === 'error') {
|
|
466
|
-
this.log.logLevel = "error"
|
|
344
|
+
this.log.logLevel = "error";
|
|
467
345
|
}
|
|
468
346
|
else if (level === 'fatal') {
|
|
469
|
-
this.log.logLevel = "fatal"
|
|
347
|
+
this.log.logLevel = "fatal";
|
|
470
348
|
}
|
|
471
349
|
else {
|
|
472
350
|
this.log.warn(`Invalid matterbridge logger level: ${level}. Using default level "info".`);
|
|
473
|
-
this.log.logLevel = "info"
|
|
351
|
+
this.log.logLevel = "info";
|
|
474
352
|
}
|
|
475
353
|
}
|
|
476
354
|
else {
|
|
477
|
-
this.log.logLevel = await this.nodeContext.get('matterbridgeLogLevel', this.matterbridgeInformation.shellyBoard ? "notice"
|
|
355
|
+
this.log.logLevel = await this.nodeContext.get('matterbridgeLogLevel', this.matterbridgeInformation.shellyBoard ? "notice" : "info");
|
|
478
356
|
}
|
|
479
357
|
this.frontend.logLevel = this.log.logLevel;
|
|
480
358
|
MatterbridgeEndpoint.logLevel = this.log.logLevel;
|
|
481
359
|
this.matterbridgeInformation.loggerLevel = this.log.logLevel;
|
|
482
|
-
// Create the file logger for matterbridge (context: matterbridgeFileLog)
|
|
483
360
|
if (hasParameter('filelogger') || (await this.nodeContext.get('matterbridgeFileLog', false))) {
|
|
484
361
|
AnsiLogger.setGlobalLogfile(path.join(this.matterbridgeDirectory, this.matterbrideLoggerFile), this.log.logLevel, true);
|
|
485
362
|
this.matterbridgeInformation.fileLogger = true;
|
|
@@ -488,7 +365,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
488
365
|
this.log.debug(`Matterbridge logLevel: ${this.log.logLevel} fileLoger: ${this.matterbridgeInformation.fileLogger}.`);
|
|
489
366
|
if (this.profile !== undefined)
|
|
490
367
|
this.log.debug(`Matterbridge profile: ${this.profile}.`);
|
|
491
|
-
// Set matter.js logger level, format and logger (context: matterLogLevel)
|
|
492
368
|
if (hasParameter('matterlogger')) {
|
|
493
369
|
const level = getParameter('matterlogger');
|
|
494
370
|
if (level === 'debug') {
|
|
@@ -520,7 +396,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
520
396
|
Logger.format = MatterLogFormat.ANSI;
|
|
521
397
|
Logger.setLogger('default', this.createMatterLogger());
|
|
522
398
|
this.matterbridgeInformation.matterLoggerLevel = Logger.defaultLogLevel;
|
|
523
|
-
// Create the file logger for matter.js (context: matterFileLog)
|
|
524
399
|
if (hasParameter('matterfilelogger') || (await this.nodeContext.get('matterFileLog', false))) {
|
|
525
400
|
this.matterbridgeInformation.matterFileLogger = true;
|
|
526
401
|
Logger.addLogger('matterfilelogger', await this.createMatterFileLogger(path.join(this.matterbridgeDirectory, this.matterLoggerFile), true), {
|
|
@@ -529,7 +404,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
529
404
|
});
|
|
530
405
|
}
|
|
531
406
|
this.log.debug(`Matter logLevel: ${Logger.defaultLogLevel} fileLoger: ${this.matterbridgeInformation.matterFileLogger}.`);
|
|
532
|
-
// Log network interfaces
|
|
533
407
|
const networkInterfaces = os.networkInterfaces();
|
|
534
408
|
const availableAddresses = Object.entries(networkInterfaces);
|
|
535
409
|
const availableInterfaces = Object.keys(networkInterfaces);
|
|
@@ -541,7 +415,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
541
415
|
});
|
|
542
416
|
}
|
|
543
417
|
}
|
|
544
|
-
// Set the interface to use for matter server node mdnsInterface
|
|
545
418
|
if (hasParameter('mdnsinterface')) {
|
|
546
419
|
this.mdnsInterface = getParameter('mdnsinterface');
|
|
547
420
|
}
|
|
@@ -550,7 +423,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
550
423
|
if (this.mdnsInterface === '')
|
|
551
424
|
this.mdnsInterface = undefined;
|
|
552
425
|
}
|
|
553
|
-
// Validate mdnsInterface
|
|
554
426
|
if (this.mdnsInterface) {
|
|
555
427
|
if (!availableInterfaces.includes(this.mdnsInterface)) {
|
|
556
428
|
this.log.error(`Invalid mdnsInterface: ${this.mdnsInterface}. Available interfaces are: ${availableInterfaces.join(', ')}. Using all available interfaces.`);
|
|
@@ -563,7 +435,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
563
435
|
}
|
|
564
436
|
if (this.mdnsInterface)
|
|
565
437
|
this.environment.vars.set('mdns.networkInterface', this.mdnsInterface);
|
|
566
|
-
// Set the listeningAddressIpv4 for the matter commissioning server
|
|
567
438
|
if (hasParameter('ipv4address')) {
|
|
568
439
|
this.ipv4address = getParameter('ipv4address');
|
|
569
440
|
}
|
|
@@ -572,7 +443,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
572
443
|
if (this.ipv4address === '')
|
|
573
444
|
this.ipv4address = undefined;
|
|
574
445
|
}
|
|
575
|
-
// Validate ipv4address
|
|
576
446
|
if (this.ipv4address) {
|
|
577
447
|
let isValid = false;
|
|
578
448
|
for (const [ifaceName, ifaces] of availableAddresses) {
|
|
@@ -588,7 +458,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
588
458
|
await this.nodeContext.remove('matteripv4address');
|
|
589
459
|
}
|
|
590
460
|
}
|
|
591
|
-
// Set the listeningAddressIpv6 for the matter commissioning server
|
|
592
461
|
if (hasParameter('ipv6address')) {
|
|
593
462
|
this.ipv6address = getParameter('ipv6address');
|
|
594
463
|
}
|
|
@@ -597,7 +466,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
597
466
|
if (this.ipv6address === '')
|
|
598
467
|
this.ipv6address = undefined;
|
|
599
468
|
}
|
|
600
|
-
// Validate ipv6address
|
|
601
469
|
if (this.ipv6address) {
|
|
602
470
|
let isValid = false;
|
|
603
471
|
for (const [ifaceName, ifaces] of availableAddresses) {
|
|
@@ -618,7 +486,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
618
486
|
await this.nodeContext.remove('matteripv6address');
|
|
619
487
|
}
|
|
620
488
|
}
|
|
621
|
-
// Initialize the virtual mode
|
|
622
489
|
if (hasParameter('novirtual')) {
|
|
623
490
|
this.matterbridgeInformation.virtualMode = 'disabled';
|
|
624
491
|
await this.nodeContext.set('virtualmode', 'disabled');
|
|
@@ -627,22 +494,17 @@ export class Matterbridge extends EventEmitter {
|
|
|
627
494
|
this.matterbridgeInformation.virtualMode = (await this.nodeContext.get('virtualmode', 'outlet'));
|
|
628
495
|
}
|
|
629
496
|
this.log.debug(`Virtual mode ${this.matterbridgeInformation.virtualMode}.`);
|
|
630
|
-
// Initialize PluginManager
|
|
631
497
|
this.plugins = new PluginManager(this);
|
|
632
498
|
await this.plugins.loadFromStorage();
|
|
633
499
|
this.plugins.logLevel = this.log.logLevel;
|
|
634
|
-
// Initialize DeviceManager
|
|
635
500
|
this.devices = new DeviceManager(this, this.nodeContext);
|
|
636
501
|
this.devices.logLevel = this.log.logLevel;
|
|
637
|
-
// Get the plugins from node storage and create the plugins node storage contexts
|
|
638
502
|
for (const plugin of this.plugins) {
|
|
639
503
|
const packageJson = await this.plugins.parse(plugin);
|
|
640
504
|
if (packageJson === null && !hasParameter('add') && !hasParameter('remove') && !hasParameter('enable') && !hasParameter('disable') && !hasParameter('reset') && !hasParameter('factoryreset')) {
|
|
641
|
-
// Try to reinstall the plugin from npm (for Docker pull and external plugins)
|
|
642
|
-
// We don't do this when the add and other parameters are set because we shut down the process after adding the plugin
|
|
643
505
|
this.log.info(`Error parsing plugin ${plg}${plugin.name}${nf}. Trying to reinstall it from npm.`);
|
|
644
506
|
try {
|
|
645
|
-
await
|
|
507
|
+
await spawn.spawnCommand(this, 'npm', ['install', '-g', plugin.name, '--omit=dev', '--verbose']);
|
|
646
508
|
this.log.info(`Plugin ${plg}${plugin.name}${nf} reinstalled.`);
|
|
647
509
|
plugin.error = false;
|
|
648
510
|
}
|
|
@@ -661,7 +523,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
661
523
|
await plugin.nodeContext.set('description', plugin.description);
|
|
662
524
|
await plugin.nodeContext.set('author', plugin.author);
|
|
663
525
|
}
|
|
664
|
-
// Log system info and create .matterbridge directory
|
|
665
526
|
await this.logNodeAndSystemInfo();
|
|
666
527
|
this.log.notice(`Matterbridge version ${this.matterbridgeVersion} ` +
|
|
667
528
|
`${hasParameter('bridge') || (!hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'bridge') ? 'mode bridge ' : ''}` +
|
|
@@ -669,7 +530,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
669
530
|
`${hasParameter('controller') ? 'mode controller ' : ''}` +
|
|
670
531
|
`${this.restartMode !== '' ? 'restart mode ' + this.restartMode + ' ' : ''}` +
|
|
671
532
|
`running on ${this.systemInformation.osType} (v.${this.systemInformation.osRelease}) platform ${this.systemInformation.osPlatform} arch ${this.systemInformation.osArch}`);
|
|
672
|
-
// Check node version and throw error
|
|
673
533
|
const minNodeVersion = 18;
|
|
674
534
|
const nodeVersion = process.versions.node;
|
|
675
535
|
const versionMajor = parseInt(nodeVersion.split('.')[0]);
|
|
@@ -677,17 +537,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
677
537
|
this.log.error(`Node version ${versionMajor} is not supported. Please upgrade to ${minNodeVersion} or above.`);
|
|
678
538
|
throw new Error(`Node version ${versionMajor} is not supported. Please upgrade to ${minNodeVersion} or above.`);
|
|
679
539
|
}
|
|
680
|
-
// Parse command line
|
|
681
540
|
await this.parseCommandLine();
|
|
682
|
-
// Emit the initialize_completed event
|
|
683
541
|
this.emit('initialize_completed');
|
|
684
542
|
this.initialized = true;
|
|
685
543
|
}
|
|
686
|
-
/**
|
|
687
|
-
* Parses the command line arguments and performs the corresponding actions.
|
|
688
|
-
* @private
|
|
689
|
-
* @returns {Promise<void>} A promise that resolves when the command line arguments have been processed, or the process exits.
|
|
690
|
-
*/
|
|
691
544
|
async parseCommandLine() {
|
|
692
545
|
if (hasParameter('help')) {
|
|
693
546
|
this.log.info(`\nUsage: matterbridge [options]\n
|
|
@@ -809,7 +662,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
809
662
|
this.shutdown = true;
|
|
810
663
|
return;
|
|
811
664
|
}
|
|
812
|
-
// Start the matter storage and create the matterbridge context
|
|
813
665
|
try {
|
|
814
666
|
await this.startMatterStorage();
|
|
815
667
|
}
|
|
@@ -817,14 +669,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
817
669
|
this.log.fatal(`Fatal error creating matter storage: ${error instanceof Error ? error.message : error}`);
|
|
818
670
|
throw new Error(`Fatal error creating matter storage: ${error instanceof Error ? error.message : error}`);
|
|
819
671
|
}
|
|
820
|
-
// Clear the matterbridge context if the reset parameter is set
|
|
821
672
|
if (hasParameter('reset') && getParameter('reset') === undefined) {
|
|
822
673
|
this.initialized = true;
|
|
823
674
|
await this.shutdownProcessAndReset();
|
|
824
675
|
this.shutdown = true;
|
|
825
676
|
return;
|
|
826
677
|
}
|
|
827
|
-
// Clear matterbridge plugin context if the reset parameter is set
|
|
828
678
|
if (hasParameter('reset') && getParameter('reset') !== undefined) {
|
|
829
679
|
this.log.debug(`Reset plugin ${getParameter('reset')}`);
|
|
830
680
|
const plugin = this.plugins.get(getParameter('reset'));
|
|
@@ -849,37 +699,30 @@ export class Matterbridge extends EventEmitter {
|
|
|
849
699
|
this.shutdown = true;
|
|
850
700
|
return;
|
|
851
701
|
}
|
|
852
|
-
// Initialize frontend
|
|
853
702
|
if (getIntParameter('frontend') !== 0 || getIntParameter('frontend') === undefined)
|
|
854
703
|
await this.frontend.start(getIntParameter('frontend'));
|
|
855
|
-
// Check in 30 seconds the latest and dev versions of matterbridge and the plugins
|
|
856
704
|
this.checkUpdateTimeout = setTimeout(async () => {
|
|
857
705
|
const { checkUpdates } = await import('./update.js');
|
|
858
706
|
checkUpdates(this);
|
|
859
707
|
}, 30 * 1000).unref();
|
|
860
|
-
// Check each 12 hours the latest and dev versions of matterbridge and the plugins
|
|
861
708
|
this.checkUpdateInterval = setInterval(async () => {
|
|
862
709
|
const { checkUpdates } = await import('./update.js');
|
|
863
710
|
checkUpdates(this);
|
|
864
711
|
}, 12 * 60 * 60 * 1000).unref();
|
|
865
|
-
// Start the matterbridge in mode test
|
|
866
712
|
if (hasParameter('test')) {
|
|
867
713
|
this.bridgeMode = 'bridge';
|
|
868
714
|
MatterbridgeEndpoint.bridgeMode = 'bridge';
|
|
869
715
|
return;
|
|
870
716
|
}
|
|
871
|
-
// Start the matterbridge in mode controller
|
|
872
717
|
if (hasParameter('controller')) {
|
|
873
718
|
this.bridgeMode = 'controller';
|
|
874
719
|
await this.startController();
|
|
875
720
|
return;
|
|
876
721
|
}
|
|
877
|
-
// Check if the bridge mode is set and start matterbridge in bridge mode if not set
|
|
878
722
|
if (!hasParameter('bridge') && !hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === '') {
|
|
879
723
|
this.log.info('Setting default matterbridge start mode to bridge');
|
|
880
724
|
await this.nodeContext?.set('bridgeMode', 'bridge');
|
|
881
725
|
}
|
|
882
|
-
// Start matterbridge in bridge mode
|
|
883
726
|
if (hasParameter('bridge') || (!hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'bridge')) {
|
|
884
727
|
this.bridgeMode = 'bridge';
|
|
885
728
|
MatterbridgeEndpoint.bridgeMode = 'bridge';
|
|
@@ -887,7 +730,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
887
730
|
await this.startBridge();
|
|
888
731
|
return;
|
|
889
732
|
}
|
|
890
|
-
// Start matterbridge in childbridge mode
|
|
891
733
|
if (hasParameter('childbridge') || (!hasParameter('bridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'childbridge')) {
|
|
892
734
|
this.bridgeMode = 'childbridge';
|
|
893
735
|
MatterbridgeEndpoint.bridgeMode = 'childbridge';
|
|
@@ -896,20 +738,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
896
738
|
return;
|
|
897
739
|
}
|
|
898
740
|
}
|
|
899
|
-
/**
|
|
900
|
-
* Asynchronously loads and starts the registered plugins.
|
|
901
|
-
*
|
|
902
|
-
* This method is responsible for initializing and staarting all enabled plugins.
|
|
903
|
-
* It ensures that each plugin is properly loaded and started before the bridge starts.
|
|
904
|
-
*
|
|
905
|
-
* @returns {Promise<void>} A promise that resolves when all plugins have been loaded and started.
|
|
906
|
-
*/
|
|
907
741
|
async startPlugins() {
|
|
908
|
-
// Check, load and start the plugins
|
|
909
742
|
for (const plugin of this.plugins) {
|
|
910
743
|
plugin.configJson = await this.plugins.loadConfig(plugin);
|
|
911
744
|
plugin.schemaJson = await this.plugins.loadSchema(plugin);
|
|
912
|
-
// Check if the plugin is available
|
|
913
745
|
if (!(await this.plugins.resolve(plugin.path))) {
|
|
914
746
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not found or not validated. Disabling it.`);
|
|
915
747
|
plugin.enabled = false;
|
|
@@ -929,14 +761,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
929
761
|
plugin.addedDevices = undefined;
|
|
930
762
|
plugin.qrPairingCode = undefined;
|
|
931
763
|
plugin.manualPairingCode = undefined;
|
|
932
|
-
this.plugins.load(plugin, true, 'Matterbridge is starting');
|
|
764
|
+
this.plugins.load(plugin, true, 'Matterbridge is starting');
|
|
933
765
|
}
|
|
934
766
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
935
767
|
}
|
|
936
|
-
/**
|
|
937
|
-
* Registers the process handlers for uncaughtException, unhandledRejection, SIGINT and SIGTERM.
|
|
938
|
-
* When either of these signals are received, the cleanup method is called with an appropriate message.
|
|
939
|
-
*/
|
|
940
768
|
registerProcessHandlers() {
|
|
941
769
|
this.log.debug(`Registering uncaughtException and unhandledRejection handlers...`);
|
|
942
770
|
process.removeAllListeners('uncaughtException');
|
|
@@ -963,9 +791,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
963
791
|
};
|
|
964
792
|
process.on('SIGTERM', this.sigtermHandler);
|
|
965
793
|
}
|
|
966
|
-
/**
|
|
967
|
-
* Deregisters the process uncaughtException, unhandledRejection, SIGINT and SIGTERM signal handlers.
|
|
968
|
-
*/
|
|
969
794
|
deregisterProcessHandlers() {
|
|
970
795
|
this.log.debug(`Deregistering uncaughtException and unhandledRejection handlers...`);
|
|
971
796
|
if (this.exceptionHandler)
|
|
@@ -982,17 +807,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
982
807
|
process.off('SIGTERM', this.sigtermHandler);
|
|
983
808
|
this.sigtermHandler = undefined;
|
|
984
809
|
}
|
|
985
|
-
/**
|
|
986
|
-
* Logs the node and system information.
|
|
987
|
-
*/
|
|
988
810
|
async logNodeAndSystemInfo() {
|
|
989
|
-
// IP address information
|
|
990
811
|
const networkInterfaces = os.networkInterfaces();
|
|
991
812
|
this.systemInformation.interfaceName = '';
|
|
992
813
|
this.systemInformation.ipv4Address = '';
|
|
993
814
|
this.systemInformation.ipv6Address = '';
|
|
994
815
|
for (const [interfaceName, interfaceDetails] of Object.entries(networkInterfaces)) {
|
|
995
|
-
// this.log.debug(`Checking interface: '${interfaceName}' for '${this.mdnsInterface}'`);
|
|
996
816
|
if (this.mdnsInterface && interfaceName !== this.mdnsInterface)
|
|
997
817
|
continue;
|
|
998
818
|
if (!interfaceDetails) {
|
|
@@ -1018,22 +838,19 @@ export class Matterbridge extends EventEmitter {
|
|
|
1018
838
|
break;
|
|
1019
839
|
}
|
|
1020
840
|
}
|
|
1021
|
-
// Node information
|
|
1022
841
|
this.systemInformation.nodeVersion = process.versions.node;
|
|
1023
842
|
const versionMajor = parseInt(this.systemInformation.nodeVersion.split('.')[0]);
|
|
1024
843
|
const versionMinor = parseInt(this.systemInformation.nodeVersion.split('.')[1]);
|
|
1025
844
|
const versionPatch = parseInt(this.systemInformation.nodeVersion.split('.')[2]);
|
|
1026
|
-
// Host system information
|
|
1027
845
|
this.systemInformation.hostname = os.hostname();
|
|
1028
846
|
this.systemInformation.user = os.userInfo().username;
|
|
1029
|
-
this.systemInformation.osType = os.type();
|
|
1030
|
-
this.systemInformation.osRelease = os.release();
|
|
1031
|
-
this.systemInformation.osPlatform = os.platform();
|
|
1032
|
-
this.systemInformation.osArch = os.arch();
|
|
1033
|
-
this.systemInformation.totalMemory = (os.totalmem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
1034
|
-
this.systemInformation.freeMemory = (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
1035
|
-
this.systemInformation.systemUptime = (os.uptime() / 60 / 60).toFixed(2) + ' hours';
|
|
1036
|
-
// Log the system information
|
|
847
|
+
this.systemInformation.osType = os.type();
|
|
848
|
+
this.systemInformation.osRelease = os.release();
|
|
849
|
+
this.systemInformation.osPlatform = os.platform();
|
|
850
|
+
this.systemInformation.osArch = os.arch();
|
|
851
|
+
this.systemInformation.totalMemory = (os.totalmem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
852
|
+
this.systemInformation.freeMemory = (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
853
|
+
this.systemInformation.systemUptime = (os.uptime() / 60 / 60).toFixed(2) + ' hours';
|
|
1037
854
|
this.log.debug('Host System Information:');
|
|
1038
855
|
this.log.debug(`- Hostname: ${this.systemInformation.hostname}`);
|
|
1039
856
|
this.log.debug(`- User: ${this.systemInformation.user}`);
|
|
@@ -1049,17 +866,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
1049
866
|
this.log.debug(`- Total Memory: ${this.systemInformation.totalMemory}`);
|
|
1050
867
|
this.log.debug(`- Free Memory: ${this.systemInformation.freeMemory}`);
|
|
1051
868
|
this.log.debug(`- System Uptime: ${this.systemInformation.systemUptime}`);
|
|
1052
|
-
// Log directories
|
|
1053
869
|
this.log.debug(`Root Directory: ${this.rootDirectory}`);
|
|
1054
870
|
this.log.debug(`Home Directory: ${this.homeDirectory}`);
|
|
1055
871
|
this.log.debug(`Matterbridge Directory: ${this.matterbridgeDirectory}`);
|
|
1056
872
|
this.log.debug(`Matterbridge Plugin Directory: ${this.matterbridgePluginDirectory}`);
|
|
1057
873
|
this.log.debug(`Matterbridge Matter Certificate Directory: ${this.matterbridgeCertDirectory}`);
|
|
1058
|
-
// Global node_modules directory
|
|
1059
874
|
if (this.nodeContext)
|
|
1060
875
|
this.globalModulesDirectory = this.matterbridgeInformation.globalModulesDirectory = await this.nodeContext.get('globalModulesDirectory', '');
|
|
1061
876
|
if (this.globalModulesDirectory === '') {
|
|
1062
|
-
// First run of Matterbridge so the node storage is empty
|
|
1063
877
|
try {
|
|
1064
878
|
this.execRunningCount++;
|
|
1065
879
|
this.matterbridgeInformation.globalModulesDirectory = this.globalModulesDirectory = await getGlobalNodeModules();
|
|
@@ -1073,84 +887,53 @@ export class Matterbridge extends EventEmitter {
|
|
|
1073
887
|
}
|
|
1074
888
|
else
|
|
1075
889
|
this.log.debug(`Global node_modules Directory: ${this.globalModulesDirectory}`);
|
|
1076
|
-
/* removed cause is too expensive for the shelly board and not really needed. Why should the globalModulesDirectory change?
|
|
1077
|
-
else {
|
|
1078
|
-
this.getGlobalNodeModules()
|
|
1079
|
-
.then(async (globalModulesDirectory) => {
|
|
1080
|
-
this.globalModulesDirectory = globalModulesDirectory;
|
|
1081
|
-
this.matterbridgeInformation.globalModulesDirectory = this.globalModulesDirectory;
|
|
1082
|
-
this.log.debug(`Global node_modules Directory: ${this.globalModulesDirectory}`);
|
|
1083
|
-
await this.nodeContext?.set<string>('globalModulesDirectory', this.globalModulesDirectory);
|
|
1084
|
-
})
|
|
1085
|
-
.catch((error) => {
|
|
1086
|
-
this.log.error(`Error getting global node_modules directory: ${error}`);
|
|
1087
|
-
});
|
|
1088
|
-
}*/
|
|
1089
|
-
// Matterbridge version
|
|
1090
890
|
const packageJson = JSON.parse(await fs.readFile(path.join(this.rootDirectory, 'package.json'), 'utf-8'));
|
|
1091
891
|
this.matterbridgeVersion = this.matterbridgeLatestVersion = this.matterbridgeDevVersion = packageJson.version;
|
|
1092
892
|
this.matterbridgeInformation.matterbridgeVersion = this.matterbridgeInformation.matterbridgeLatestVersion = this.matterbridgeInformation.matterbridgeDevVersion = packageJson.version;
|
|
1093
893
|
this.log.debug(`Matterbridge Version: ${this.matterbridgeVersion}`);
|
|
1094
|
-
// Matterbridge latest version (will be set in the checkUpdate function)
|
|
1095
894
|
if (this.nodeContext)
|
|
1096
895
|
this.matterbridgeLatestVersion = this.matterbridgeInformation.matterbridgeLatestVersion = await this.nodeContext.get('matterbridgeLatestVersion', this.matterbridgeVersion);
|
|
1097
896
|
this.log.debug(`Matterbridge Latest Version: ${this.matterbridgeLatestVersion}`);
|
|
1098
|
-
// Matterbridge dev version (will be set in the checkUpdate function)
|
|
1099
897
|
if (this.nodeContext)
|
|
1100
898
|
this.matterbridgeDevVersion = this.matterbridgeInformation.matterbridgeDevVersion = await this.nodeContext.get('matterbridgeDevVersion', this.matterbridgeVersion);
|
|
1101
899
|
this.log.debug(`Matterbridge Dev Version: ${this.matterbridgeDevVersion}`);
|
|
1102
|
-
// Current working directory
|
|
1103
900
|
const currentDir = process.cwd();
|
|
1104
901
|
this.log.debug(`Current Working Directory: ${currentDir}`);
|
|
1105
|
-
// Command line arguments (excluding 'node' and the script name)
|
|
1106
902
|
const cmdArgs = process.argv.slice(2).join(' ');
|
|
1107
903
|
this.log.debug(`Command Line Arguments: ${cmdArgs}`);
|
|
1108
904
|
}
|
|
1109
|
-
/**
|
|
1110
|
-
* Creates a MatterLogger function to show the matter.js log messages in AnsiLogger (for the frontend).
|
|
1111
|
-
*
|
|
1112
|
-
* @returns {Function} The MatterLogger function.
|
|
1113
|
-
*/
|
|
1114
905
|
createMatterLogger() {
|
|
1115
|
-
const matterLogger = new AnsiLogger({ logName: 'Matter', logTimestampFormat: 4
|
|
906
|
+
const matterLogger = new AnsiLogger({ logName: 'Matter', logTimestampFormat: 4, logLevel: "debug" });
|
|
1116
907
|
return (level, formattedLog) => {
|
|
1117
908
|
const logger = formattedLog.slice(44, 44 + 20).trim();
|
|
1118
909
|
const message = formattedLog.slice(65);
|
|
1119
910
|
matterLogger.logName = logger;
|
|
1120
911
|
switch (level) {
|
|
1121
912
|
case MatterLogLevel.DEBUG:
|
|
1122
|
-
matterLogger.log("debug"
|
|
913
|
+
matterLogger.log("debug", message);
|
|
1123
914
|
break;
|
|
1124
915
|
case MatterLogLevel.INFO:
|
|
1125
|
-
matterLogger.log("info"
|
|
916
|
+
matterLogger.log("info", message);
|
|
1126
917
|
break;
|
|
1127
918
|
case MatterLogLevel.NOTICE:
|
|
1128
|
-
matterLogger.log("notice"
|
|
919
|
+
matterLogger.log("notice", message);
|
|
1129
920
|
break;
|
|
1130
921
|
case MatterLogLevel.WARN:
|
|
1131
|
-
matterLogger.log("warn"
|
|
922
|
+
matterLogger.log("warn", message);
|
|
1132
923
|
break;
|
|
1133
924
|
case MatterLogLevel.ERROR:
|
|
1134
|
-
matterLogger.log("error"
|
|
925
|
+
matterLogger.log("error", message);
|
|
1135
926
|
break;
|
|
1136
927
|
case MatterLogLevel.FATAL:
|
|
1137
|
-
matterLogger.log("fatal"
|
|
928
|
+
matterLogger.log("fatal", message);
|
|
1138
929
|
break;
|
|
1139
930
|
default:
|
|
1140
|
-
matterLogger.log("debug"
|
|
931
|
+
matterLogger.log("debug", message);
|
|
1141
932
|
break;
|
|
1142
933
|
}
|
|
1143
934
|
};
|
|
1144
935
|
}
|
|
1145
|
-
/**
|
|
1146
|
-
* Creates a Matter File Logger.
|
|
1147
|
-
*
|
|
1148
|
-
* @param {string} filePath - The path to the log file.
|
|
1149
|
-
* @param {boolean} [unlink=false] - Whether to unlink the log file before creating a new one.
|
|
1150
|
-
* @returns {Function} - A function that logs formatted messages to the log file.
|
|
1151
|
-
*/
|
|
1152
936
|
async createMatterFileLogger(filePath, unlink = false) {
|
|
1153
|
-
// 2024-08-21 08:55:19.488 DEBUG InteractionMessenger Sending DataReport chunk with 28 attributes and 0 events: 1004 bytes
|
|
1154
937
|
let fileSize = 0;
|
|
1155
938
|
if (unlink) {
|
|
1156
939
|
try {
|
|
@@ -1199,25 +982,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
1199
982
|
}
|
|
1200
983
|
};
|
|
1201
984
|
}
|
|
1202
|
-
/**
|
|
1203
|
-
* Restarts the process by exiting the current instance and loading a new instance.
|
|
1204
|
-
*/
|
|
1205
985
|
async restartProcess() {
|
|
1206
986
|
await this.cleanup('restarting...', true);
|
|
1207
987
|
}
|
|
1208
|
-
/**
|
|
1209
|
-
* Shut down the process by exiting the current process.
|
|
1210
|
-
*/
|
|
1211
988
|
async shutdownProcess() {
|
|
1212
989
|
await this.cleanup('shutting down...', false);
|
|
1213
990
|
}
|
|
1214
|
-
/**
|
|
1215
|
-
* Update matterbridge and and shut down the process.
|
|
1216
|
-
*/
|
|
1217
991
|
async updateProcess() {
|
|
1218
992
|
this.log.info('Updating matterbridge...');
|
|
1219
993
|
try {
|
|
1220
|
-
await
|
|
994
|
+
await spawn.spawnCommand(this, 'npm', ['install', '-g', 'matterbridge', '--omit=dev', '--verbose']);
|
|
1221
995
|
this.log.info('Matterbridge has been updated. Full restart required.');
|
|
1222
996
|
}
|
|
1223
997
|
catch (error) {
|
|
@@ -1226,73 +1000,52 @@ export class Matterbridge extends EventEmitter {
|
|
|
1226
1000
|
this.frontend.wssSendRestartRequired();
|
|
1227
1001
|
await this.cleanup('updating...', false);
|
|
1228
1002
|
}
|
|
1229
|
-
/**
|
|
1230
|
-
* Unregister all devices and shut down the process.
|
|
1231
|
-
*/
|
|
1232
1003
|
async unregisterAndShutdownProcess() {
|
|
1233
1004
|
this.log.info('Unregistering all devices and shutting down...');
|
|
1234
1005
|
for (const plugin of this.plugins) {
|
|
1235
1006
|
await this.removeAllBridgedEndpoints(plugin.name, 250);
|
|
1236
1007
|
}
|
|
1237
1008
|
this.log.debug('Waiting for the MessageExchange to finish...');
|
|
1238
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1009
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1239
1010
|
this.log.debug('Cleaning up and shutting down...');
|
|
1240
1011
|
await this.cleanup('unregistered all devices and shutting down...', false);
|
|
1241
1012
|
}
|
|
1242
|
-
/**
|
|
1243
|
-
* Reset commissioning and shut down the process.
|
|
1244
|
-
*/
|
|
1245
1013
|
async shutdownProcessAndReset() {
|
|
1246
1014
|
await this.cleanup('shutting down with reset...', false);
|
|
1247
1015
|
}
|
|
1248
|
-
/**
|
|
1249
|
-
* Factory reset and shut down the process.
|
|
1250
|
-
*/
|
|
1251
1016
|
async shutdownProcessAndFactoryReset() {
|
|
1252
1017
|
await this.cleanup('shutting down with factory reset...', false);
|
|
1253
1018
|
}
|
|
1254
|
-
/**
|
|
1255
|
-
* Cleans up the Matterbridge instance.
|
|
1256
|
-
* @param {string} message - The cleanup message.
|
|
1257
|
-
* @param {boolean} [restart=false] - Indicates whether to restart the instance after cleanup. Default is `false`.
|
|
1258
|
-
* @returns A promise that resolves when the cleanup is completed.
|
|
1259
|
-
*/
|
|
1260
1019
|
async cleanup(message, restart = false) {
|
|
1261
1020
|
if (this.initialized && !this.hasCleanupStarted) {
|
|
1262
1021
|
this.emit('cleanup_started');
|
|
1263
1022
|
this.hasCleanupStarted = true;
|
|
1264
1023
|
this.log.info(message);
|
|
1265
|
-
// Clear the start matter interval
|
|
1266
1024
|
if (this.startMatterInterval) {
|
|
1267
1025
|
clearInterval(this.startMatterInterval);
|
|
1268
1026
|
this.startMatterInterval = undefined;
|
|
1269
1027
|
this.log.debug('Start matter interval cleared');
|
|
1270
1028
|
}
|
|
1271
|
-
// Clear the check update timeout
|
|
1272
1029
|
if (this.checkUpdateTimeout) {
|
|
1273
1030
|
clearInterval(this.checkUpdateTimeout);
|
|
1274
1031
|
this.checkUpdateTimeout = undefined;
|
|
1275
1032
|
this.log.debug('Check update timeout cleared');
|
|
1276
1033
|
}
|
|
1277
|
-
// Clear the check update interval
|
|
1278
1034
|
if (this.checkUpdateInterval) {
|
|
1279
1035
|
clearInterval(this.checkUpdateInterval);
|
|
1280
1036
|
this.checkUpdateInterval = undefined;
|
|
1281
1037
|
this.log.debug('Check update interval cleared');
|
|
1282
1038
|
}
|
|
1283
|
-
// Clear the configure timeout
|
|
1284
1039
|
if (this.configureTimeout) {
|
|
1285
1040
|
clearTimeout(this.configureTimeout);
|
|
1286
1041
|
this.configureTimeout = undefined;
|
|
1287
1042
|
this.log.debug('Matterbridge configure timeout cleared');
|
|
1288
1043
|
}
|
|
1289
|
-
// Clear the reachability timeout
|
|
1290
1044
|
if (this.reachabilityTimeout) {
|
|
1291
1045
|
clearTimeout(this.reachabilityTimeout);
|
|
1292
1046
|
this.reachabilityTimeout = undefined;
|
|
1293
1047
|
this.log.debug('Matterbridge reachability timeout cleared');
|
|
1294
1048
|
}
|
|
1295
|
-
// Calling the shutdown method of each plugin and clear the plugins reachability timeout
|
|
1296
1049
|
for (const plugin of this.plugins) {
|
|
1297
1050
|
if (!plugin.enabled || plugin.error)
|
|
1298
1051
|
continue;
|
|
@@ -1303,10 +1056,9 @@ export class Matterbridge extends EventEmitter {
|
|
|
1303
1056
|
this.log.debug(`Plugin ${plg}${plugin.name}${db} reachability timeout cleared`);
|
|
1304
1057
|
}
|
|
1305
1058
|
}
|
|
1306
|
-
// Stop matter server nodes
|
|
1307
1059
|
this.log.notice(`Stopping matter server nodes in ${this.bridgeMode} mode...`);
|
|
1308
1060
|
this.log.debug('Waiting for the MessageExchange to finish...');
|
|
1309
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1061
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1310
1062
|
if (this.bridgeMode === 'bridge') {
|
|
1311
1063
|
if (this.serverNode) {
|
|
1312
1064
|
await this.stopServerNode(this.serverNode);
|
|
@@ -1322,7 +1074,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1322
1074
|
}
|
|
1323
1075
|
}
|
|
1324
1076
|
this.log.notice('Stopped matter server nodes');
|
|
1325
|
-
// Matter commisioning reset
|
|
1326
1077
|
if (message === 'shutting down with reset...') {
|
|
1327
1078
|
this.log.info('Resetting Matterbridge commissioning information...');
|
|
1328
1079
|
await this.matterStorageManager?.createContext('events')?.clearAll();
|
|
@@ -1332,36 +1083,18 @@ export class Matterbridge extends EventEmitter {
|
|
|
1332
1083
|
await this.matterbridgeContext?.clearAll();
|
|
1333
1084
|
this.log.info('Matter storage reset done! Remove the bridge from the controller.');
|
|
1334
1085
|
}
|
|
1335
|
-
// Stop matter storage
|
|
1336
1086
|
await this.stopMatterStorage();
|
|
1337
|
-
// Stop the frontend
|
|
1338
1087
|
await this.frontend.stop();
|
|
1339
|
-
// Remove the matterfilelogger
|
|
1340
1088
|
try {
|
|
1341
1089
|
Logger.removeLogger('matterfilelogger');
|
|
1342
1090
|
}
|
|
1343
1091
|
catch (error) {
|
|
1344
1092
|
this.log.debug(`Error removing the matterfilelogger for file ${CYAN}${path.join(this.matterbridgeDirectory, this.matterLoggerFile)}${db}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1345
1093
|
}
|
|
1346
|
-
// Close the matterbridge node storage and context
|
|
1347
1094
|
if (this.nodeStorage && this.nodeContext) {
|
|
1348
|
-
/*
|
|
1349
|
-
TODO: Implement serialization of registered devices in edge mode
|
|
1350
|
-
this.log.info('Saving registered devices...');
|
|
1351
|
-
const serializedRegisteredDevices: SerializedMatterbridgeEndpoint[] = [];
|
|
1352
|
-
this.devices.forEach(async (device) => {
|
|
1353
|
-
const serializedMatterbridgeDevice = MatterbridgeEndpoint.serialize(device);
|
|
1354
|
-
// this.log.info(`- ${serializedMatterbridgeDevice.deviceName}${rs}\n`, serializedMatterbridgeDevice);
|
|
1355
|
-
if (serializedMatterbridgeDevice) serializedRegisteredDevices.push(serializedMatterbridgeDevice);
|
|
1356
|
-
});
|
|
1357
|
-
await this.nodeContext.set<SerializedMatterbridgeEndpoint[]>('devices', serializedRegisteredDevices);
|
|
1358
|
-
this.log.info(`Saved registered devices (${serializedRegisteredDevices?.length})`);
|
|
1359
|
-
*/
|
|
1360
|
-
// Clear nodeContext and nodeStorage (they just need 1000ms to write the data to disk)
|
|
1361
1095
|
this.log.debug(`Closing node storage context for ${plg}Matterbridge${db}...`);
|
|
1362
1096
|
await this.nodeContext.close();
|
|
1363
1097
|
this.nodeContext = undefined;
|
|
1364
|
-
// Clear nodeContext for each plugin (they just need 1000ms to write the data to disk)
|
|
1365
1098
|
for (const plugin of this.plugins) {
|
|
1366
1099
|
if (plugin.nodeContext) {
|
|
1367
1100
|
this.log.debug(`Closing node storage context for plugin ${plg}${plugin.name}${db}...`);
|
|
@@ -1378,10 +1111,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
1378
1111
|
}
|
|
1379
1112
|
this.plugins.clear();
|
|
1380
1113
|
this.devices.clear();
|
|
1381
|
-
// Factory reset
|
|
1382
1114
|
if (message === 'shutting down with factory reset...') {
|
|
1383
1115
|
try {
|
|
1384
|
-
// Delete matter storage directory with its subdirectories and backup
|
|
1385
1116
|
const dir = path.join(this.matterbridgeDirectory, this.matterStorageName);
|
|
1386
1117
|
this.log.info(`Removing matter storage directory: ${dir}`);
|
|
1387
1118
|
await fs.rm(dir, { recursive: true });
|
|
@@ -1395,7 +1126,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1395
1126
|
}
|
|
1396
1127
|
}
|
|
1397
1128
|
try {
|
|
1398
|
-
// Delete matterbridge storage directory with its subdirectories and backup
|
|
1399
1129
|
const dir = path.join(this.matterbridgeDirectory, this.nodeStorageName);
|
|
1400
1130
|
this.log.info(`Removing matterbridge storage directory: ${dir}`);
|
|
1401
1131
|
await fs.rm(dir, { recursive: true });
|
|
@@ -1410,13 +1140,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
1410
1140
|
}
|
|
1411
1141
|
this.log.info('Factory reset done! Remove all paired fabrics from the controllers.');
|
|
1412
1142
|
}
|
|
1413
|
-
// Deregisters the process handlers
|
|
1414
1143
|
this.deregisterProcessHandlers();
|
|
1415
1144
|
if (restart) {
|
|
1416
1145
|
if (message === 'updating...') {
|
|
1417
1146
|
this.log.info('Cleanup completed. Updating...');
|
|
1418
1147
|
Matterbridge.instance = undefined;
|
|
1419
|
-
this.emit('update');
|
|
1148
|
+
this.emit('update');
|
|
1420
1149
|
}
|
|
1421
1150
|
else if (message === 'restarting...') {
|
|
1422
1151
|
this.log.info('Cleanup completed. Restarting...');
|
|
@@ -1437,14 +1166,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1437
1166
|
this.log.debug('Cleanup already started...');
|
|
1438
1167
|
}
|
|
1439
1168
|
}
|
|
1440
|
-
/**
|
|
1441
|
-
* Creates and configures the server node for an accessory plugin for a given device.
|
|
1442
|
-
*
|
|
1443
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
1444
|
-
* @param {MatterbridgeEndpoint} device - The device to associate with the plugin.
|
|
1445
|
-
* @param {boolean} [start=false] - Whether to start the server node after adding the device.
|
|
1446
|
-
* @returns {Promise<void>} A promise that resolves when the server node for the accessory plugin is created and configured.
|
|
1447
|
-
*/
|
|
1448
1169
|
async createAccessoryPlugin(plugin, device, start = false) {
|
|
1449
1170
|
if (!plugin.locked && device.deviceName && device.vendorId && device.productId && device.vendorName && device.productName) {
|
|
1450
1171
|
plugin.locked = true;
|
|
@@ -1458,13 +1179,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1458
1179
|
await this.startServerNode(plugin.serverNode);
|
|
1459
1180
|
}
|
|
1460
1181
|
}
|
|
1461
|
-
/**
|
|
1462
|
-
* Creates and configures the server node for a dynamic plugin.
|
|
1463
|
-
*
|
|
1464
|
-
* @param {RegisteredPlugin} plugin - The plugin to configure.
|
|
1465
|
-
* @param {boolean} [start=false] - Whether to start the server node after adding the aggregator node.
|
|
1466
|
-
* @returns {Promise<void>} A promise that resolves when the server node for the dynamic plugin is created and configured.
|
|
1467
|
-
*/
|
|
1468
1182
|
async createDynamicPlugin(plugin, start = false) {
|
|
1469
1183
|
if (!plugin.locked) {
|
|
1470
1184
|
plugin.locked = true;
|
|
@@ -1477,13 +1191,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1477
1191
|
await this.startServerNode(plugin.serverNode);
|
|
1478
1192
|
}
|
|
1479
1193
|
}
|
|
1480
|
-
/**
|
|
1481
|
-
* Starts the Matterbridge in bridge mode.
|
|
1482
|
-
* @private
|
|
1483
|
-
* @returns {Promise<void>} A promise that resolves when the Matterbridge is started.
|
|
1484
|
-
*/
|
|
1485
1194
|
async startBridge() {
|
|
1486
|
-
// Plugins are configured by a timer when matter server is started and plugin.configured is set to true
|
|
1487
1195
|
if (!this.matterStorageManager)
|
|
1488
1196
|
throw new Error('No storage manager initialized');
|
|
1489
1197
|
if (!this.matterbridgeContext)
|
|
@@ -1522,9 +1230,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1522
1230
|
clearInterval(this.startMatterInterval);
|
|
1523
1231
|
this.startMatterInterval = undefined;
|
|
1524
1232
|
this.log.debug('Cleared startMatterInterval interval for Matterbridge');
|
|
1525
|
-
// Start the Matter server node
|
|
1526
1233
|
this.startServerNode(this.serverNode);
|
|
1527
|
-
// Configure the plugins
|
|
1528
1234
|
this.configureTimeout = setTimeout(async () => {
|
|
1529
1235
|
for (const plugin of this.plugins) {
|
|
1530
1236
|
if (!plugin.enabled || !plugin.loaded || !plugin.started || plugin.error)
|
|
@@ -1542,7 +1248,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1542
1248
|
}
|
|
1543
1249
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
1544
1250
|
}, 30 * 1000);
|
|
1545
|
-
// Setting reachability to true
|
|
1546
1251
|
this.reachabilityTimeout = setTimeout(() => {
|
|
1547
1252
|
this.log.info(`Setting reachability to true for ${plg}Matterbridge${db}`);
|
|
1548
1253
|
if (this.aggregatorNode)
|
|
@@ -1551,11 +1256,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1551
1256
|
}, 60 * 1000);
|
|
1552
1257
|
}, 1000);
|
|
1553
1258
|
}
|
|
1554
|
-
/**
|
|
1555
|
-
* Starts the Matterbridge in childbridge mode.
|
|
1556
|
-
* @private
|
|
1557
|
-
* @returns {Promise<void>} A promise that resolves when the Matterbridge is started.
|
|
1558
|
-
*/
|
|
1559
1259
|
async startChildbridge() {
|
|
1560
1260
|
if (!this.matterStorageManager)
|
|
1561
1261
|
throw new Error('No storage manager initialized');
|
|
@@ -1593,7 +1293,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1593
1293
|
clearInterval(this.startMatterInterval);
|
|
1594
1294
|
this.startMatterInterval = undefined;
|
|
1595
1295
|
this.log.debug('Cleared startMatterInterval interval in childbridge mode');
|
|
1596
|
-
// Configure the plugins
|
|
1597
1296
|
this.configureTimeout = setTimeout(async () => {
|
|
1598
1297
|
for (const plugin of this.plugins) {
|
|
1599
1298
|
if (!plugin.enabled || !plugin.loaded || !plugin.started || plugin.error)
|
|
@@ -1630,9 +1329,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1630
1329
|
this.log.error(`Node storage context not found for plugin ${plg}${plugin.name}${er}`);
|
|
1631
1330
|
continue;
|
|
1632
1331
|
}
|
|
1633
|
-
// Start the Matter server node
|
|
1634
1332
|
this.startServerNode(plugin.serverNode);
|
|
1635
|
-
// Setting reachability to true
|
|
1636
1333
|
plugin.reachabilityTimeout = setTimeout(() => {
|
|
1637
1334
|
this.log.info(`Setting reachability to true for ${plg}${plugin.name}${nf} type ${plugin.type} server node ${plugin.serverNode !== undefined} aggregator node ${plugin.aggregatorNode !== undefined} device ${plugin.device !== undefined}`);
|
|
1638
1335
|
if (plugin.type === 'DynamicPlatform' && plugin.aggregatorNode)
|
|
@@ -1642,226 +1339,9 @@ export class Matterbridge extends EventEmitter {
|
|
|
1642
1339
|
}
|
|
1643
1340
|
}, 1000);
|
|
1644
1341
|
}
|
|
1645
|
-
/**
|
|
1646
|
-
* Starts the Matterbridge controller.
|
|
1647
|
-
* @private
|
|
1648
|
-
* @returns {Promise<void>} A promise that resolves when the Matterbridge is started.
|
|
1649
|
-
*/
|
|
1650
1342
|
async startController() {
|
|
1651
|
-
if (!this.matterStorageManager) {
|
|
1652
|
-
this.log.error('No storage manager initialized');
|
|
1653
|
-
await this.cleanup('No storage manager initialized');
|
|
1654
|
-
return;
|
|
1655
|
-
}
|
|
1656
|
-
this.log.info('Creating context: mattercontrollerContext');
|
|
1657
|
-
this.controllerContext = this.matterStorageManager.createContext('mattercontrollerContext');
|
|
1658
|
-
if (!this.controllerContext) {
|
|
1659
|
-
this.log.error('No storage context mattercontrollerContext initialized');
|
|
1660
|
-
await this.cleanup('No storage context mattercontrollerContext initialized');
|
|
1661
|
-
return;
|
|
1662
|
-
}
|
|
1663
|
-
this.log.debug('Starting matterbridge in mode', this.bridgeMode);
|
|
1664
|
-
/*
|
|
1665
|
-
this.matterServer = await this.createMatterServer(this.storageManager);
|
|
1666
|
-
this.log.info('Creating matter commissioning controller');
|
|
1667
|
-
this.commissioningController = new CommissioningController({
|
|
1668
|
-
autoConnect: false,
|
|
1669
|
-
});
|
|
1670
|
-
this.log.info('Adding matter commissioning controller to matter server');
|
|
1671
|
-
await this.matterServer.addCommissioningController(this.commissioningController);
|
|
1672
|
-
|
|
1673
|
-
this.log.info('Starting matter server');
|
|
1674
|
-
await this.matterServer.start();
|
|
1675
|
-
this.log.info('Matter server started');
|
|
1676
|
-
const commissioningOptions: ControllerCommissioningFlowOptions = {
|
|
1677
|
-
regulatoryLocation: GeneralCommissioning.RegulatoryLocationType.IndoorOutdoor,
|
|
1678
|
-
regulatoryCountryCode: 'XX',
|
|
1679
|
-
};
|
|
1680
|
-
const commissioningController = new CommissioningController({
|
|
1681
|
-
environment: {
|
|
1682
|
-
environment,
|
|
1683
|
-
id: uniqueId,
|
|
1684
|
-
},
|
|
1685
|
-
autoConnect: false, // Do not auto connect to the commissioned nodes
|
|
1686
|
-
adminFabricLabel,
|
|
1687
|
-
});
|
|
1688
|
-
|
|
1689
|
-
if (hasParameter('pairingcode')) {
|
|
1690
|
-
this.log.info('Pairing device with pairingcode:', getParameter('pairingcode'));
|
|
1691
|
-
const pairingCode = getParameter('pairingcode');
|
|
1692
|
-
const ip = this.controllerContext.has('ip') ? this.controllerContext.get<string>('ip') : undefined;
|
|
1693
|
-
const port = this.controllerContext.has('port') ? this.controllerContext.get<number>('port') : undefined;
|
|
1694
|
-
|
|
1695
|
-
let longDiscriminator, setupPin, shortDiscriminator;
|
|
1696
|
-
if (pairingCode !== undefined) {
|
|
1697
|
-
const pairingCodeCodec = ManualPairingCodeCodec.decode(pairingCode);
|
|
1698
|
-
shortDiscriminator = pairingCodeCodec.shortDiscriminator;
|
|
1699
|
-
longDiscriminator = undefined;
|
|
1700
|
-
setupPin = pairingCodeCodec.passcode;
|
|
1701
|
-
this.log.info(`Data extracted from pairing code: ${Logger.toJSON(pairingCodeCodec)}`);
|
|
1702
|
-
} else {
|
|
1703
|
-
longDiscriminator = await this.controllerContext.get('longDiscriminator', 3840);
|
|
1704
|
-
if (longDiscriminator > 4095) throw new Error('Discriminator value must be less than 4096');
|
|
1705
|
-
setupPin = this.controllerContext.get('pin', 20202021);
|
|
1706
|
-
}
|
|
1707
|
-
if ((shortDiscriminator === undefined && longDiscriminator === undefined) || setupPin === undefined) {
|
|
1708
|
-
throw new Error('Please specify the longDiscriminator of the device to commission with -longDiscriminator or provide a valid passcode with -passcode');
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
const options = {
|
|
1712
|
-
commissioning: commissioningOptions,
|
|
1713
|
-
discovery: {
|
|
1714
|
-
knownAddress: ip !== undefined && port !== undefined ? { ip, port, type: 'udp' } : undefined,
|
|
1715
|
-
identifierData: longDiscriminator !== undefined ? { longDiscriminator } : shortDiscriminator !== undefined ? { shortDiscriminator } : {},
|
|
1716
|
-
},
|
|
1717
|
-
passcode: setupPin,
|
|
1718
|
-
} as NodeCommissioningOptions;
|
|
1719
|
-
this.log.info('Commissioning with options:', options);
|
|
1720
|
-
const nodeId = await this.commissioningController.commissionNode(options);
|
|
1721
|
-
this.log.info(`Commissioning successfully done with nodeId: ${nodeId}`);
|
|
1722
|
-
this.log.info('ActiveSessionInformation:', this.commissioningController.getActiveSessionInformation());
|
|
1723
|
-
} // (hasParameter('pairingcode'))
|
|
1724
|
-
|
|
1725
|
-
if (hasParameter('unpairall')) {
|
|
1726
|
-
this.log.info('***Commissioning controller unpairing all nodes...');
|
|
1727
|
-
const nodeIds = this.commissioningController.getCommissionedNodes();
|
|
1728
|
-
for (const nodeId of nodeIds) {
|
|
1729
|
-
this.log.info('***Commissioning controller unpairing node:', nodeId);
|
|
1730
|
-
await this.commissioningController.removeNode(nodeId);
|
|
1731
|
-
}
|
|
1732
|
-
return;
|
|
1733
|
-
}
|
|
1734
|
-
|
|
1735
|
-
if (hasParameter('discover')) {
|
|
1736
|
-
// const discover = await this.commissioningController.discoverCommissionableDevices({ productId: 0x8000, deviceType: 0xfff1 });
|
|
1737
|
-
// console.log(discover);
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
if (!this.commissioningController.isCommissioned()) {
|
|
1741
|
-
this.log.info('***Commissioning controller is not commissioned: use matterbridge -controller -pairingcode [pairingcode] to commission a device');
|
|
1742
|
-
return;
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
|
-
const nodeIds = this.commissioningController.getCommissionedNodes();
|
|
1746
|
-
this.log.info(`***Commissioning controller is commissioned ${this.commissioningController.isCommissioned()} and has ${nodeIds.length} nodes commisioned: `);
|
|
1747
|
-
for (const nodeId of nodeIds) {
|
|
1748
|
-
this.log.info(`***Connecting to commissioned node: ${nodeId}`);
|
|
1749
|
-
|
|
1750
|
-
const node = await this.commissioningController.connectNode(nodeId, {
|
|
1751
|
-
autoSubscribe: false,
|
|
1752
|
-
attributeChangedCallback: (peerNodeId, { path: { nodeId, clusterId, endpointId, attributeName }, value }) =>
|
|
1753
|
-
this.log.info(`***Commissioning controller attributeChangedCallback ${peerNodeId}: attribute ${nodeId}/${endpointId}/${clusterId}/${attributeName} changed to ${Logger.toJSON(value)}`),
|
|
1754
|
-
eventTriggeredCallback: (peerNodeId, { path: { nodeId, clusterId, endpointId, eventName }, events }) =>
|
|
1755
|
-
this.log.info(`***Commissioning controller eventTriggeredCallback ${peerNodeId}: Event ${nodeId}/${endpointId}/${clusterId}/${eventName} triggered with ${Logger.toJSON(events)}`),
|
|
1756
|
-
stateInformationCallback: (peerNodeId, info) => {
|
|
1757
|
-
switch (info) {
|
|
1758
|
-
case NodeStateInformation.Connected:
|
|
1759
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} connected`);
|
|
1760
|
-
break;
|
|
1761
|
-
case NodeStateInformation.Disconnected:
|
|
1762
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} disconnected`);
|
|
1763
|
-
break;
|
|
1764
|
-
case NodeStateInformation.Reconnecting:
|
|
1765
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} reconnecting`);
|
|
1766
|
-
break;
|
|
1767
|
-
case NodeStateInformation.WaitingForDeviceDiscovery:
|
|
1768
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} waiting for device discovery`);
|
|
1769
|
-
break;
|
|
1770
|
-
case NodeStateInformation.StructureChanged:
|
|
1771
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} structure changed`);
|
|
1772
|
-
break;
|
|
1773
|
-
case NodeStateInformation.Decommissioned:
|
|
1774
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} decommissioned`);
|
|
1775
|
-
break;
|
|
1776
|
-
default:
|
|
1777
|
-
this.log.info(`***Commissioning controller stateInformationCallback ${peerNodeId}: Node ${nodeId} NodeStateInformation.${info}`);
|
|
1778
|
-
break;
|
|
1779
|
-
}
|
|
1780
|
-
},
|
|
1781
|
-
});
|
|
1782
|
-
|
|
1783
|
-
node.logStructure();
|
|
1784
|
-
|
|
1785
|
-
// Get the interaction client
|
|
1786
|
-
this.log.info('Getting the interaction client');
|
|
1787
|
-
const interactionClient = await node.getInteractionClient();
|
|
1788
|
-
let cluster;
|
|
1789
|
-
let attributes;
|
|
1790
|
-
|
|
1791
|
-
// Log BasicInformationCluster
|
|
1792
|
-
cluster = BasicInformationCluster;
|
|
1793
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1794
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1795
|
-
});
|
|
1796
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1797
|
-
attributes.forEach((attribute) => {
|
|
1798
|
-
this.log.info(
|
|
1799
|
-
`- endpoint ${or}${attribute.path.endpointId}${nf} cluster ${hk}${getClusterNameById(attribute.path.clusterId)}${nf} (${hk}0x${attribute.path.clusterId.toString(16)}${nf}) attribute ${zb}${attribute.path.attributeName}${nf} (${zb}0x${attribute.path.attributeId.toString(16)}${nf}): ${typeof attribute.value === 'object' ? stringify(attribute.value) : attribute.value}`,
|
|
1800
|
-
);
|
|
1801
|
-
});
|
|
1802
|
-
|
|
1803
|
-
// Log PowerSourceCluster
|
|
1804
|
-
cluster = PowerSourceCluster;
|
|
1805
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1806
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1807
|
-
});
|
|
1808
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1809
|
-
attributes.forEach((attribute) => {
|
|
1810
|
-
this.log.info(
|
|
1811
|
-
`- endpoint ${or}${attribute.path.endpointId}${nf} cluster ${hk}${getClusterNameById(attribute.path.clusterId)}${nf} (${hk}0x${attribute.path.clusterId.toString(16)}${nf}) attribute ${zb}${attribute.path.attributeName}${nf} (${zb}0x${attribute.path.attributeId.toString(16)}${nf}): ${typeof attribute.value === 'object' ? stringify(attribute.value) : attribute.value}`,
|
|
1812
|
-
);
|
|
1813
|
-
});
|
|
1814
|
-
|
|
1815
|
-
// Log ThreadNetworkDiagnostics
|
|
1816
|
-
cluster = ThreadNetworkDiagnosticsCluster;
|
|
1817
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1818
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1819
|
-
});
|
|
1820
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1821
|
-
attributes.forEach((attribute) => {
|
|
1822
|
-
this.log.info(
|
|
1823
|
-
`- endpoint ${or}${attribute.path.endpointId}${nf} cluster ${hk}${getClusterNameById(attribute.path.clusterId)}${nf} (${hk}0x${attribute.path.clusterId.toString(16)}${nf}) attribute ${zb}${attribute.path.attributeName}${nf} (${zb}0x${attribute.path.attributeId.toString(16)}${nf}): ${typeof attribute.value === 'object' ? stringify(attribute.value) : attribute.value}`,
|
|
1824
|
-
);
|
|
1825
|
-
});
|
|
1826
|
-
|
|
1827
|
-
// Log SwitchCluster
|
|
1828
|
-
cluster = SwitchCluster;
|
|
1829
|
-
attributes = await interactionClient.getMultipleAttributes({
|
|
1830
|
-
attributes: [{ clusterId: cluster.id }],
|
|
1831
|
-
});
|
|
1832
|
-
if (attributes.length > 0) this.log.info(`Cluster: ${idn}${cluster.name}${rs}${nf} attributes:`);
|
|
1833
|
-
attributes.forEach((attribute) => {
|
|
1834
|
-
this.log.info(
|
|
1835
|
-
`- endpoint ${or}${attribute.path.endpointId}${nf} cluster ${hk}${getClusterNameById(attribute.path.clusterId)}${nf} (${hk}0x${attribute.path.clusterId.toString(16)}${nf}) attribute ${zb}${attribute.path.attributeName}${nf} (${zb}0x${attribute.path.attributeId.toString(16)}${nf}): ${typeof attribute.value === 'object' ? stringify(attribute.value) : attribute.value}`,
|
|
1836
|
-
);
|
|
1837
|
-
});
|
|
1838
|
-
|
|
1839
|
-
this.log.info('Subscribing to all attributes and events');
|
|
1840
|
-
await node.subscribeAllAttributesAndEvents({
|
|
1841
|
-
ignoreInitialTriggers: false,
|
|
1842
|
-
attributeChangedCallback: ({ path: { nodeId, clusterId, endpointId, attributeName }, version, value }) =>
|
|
1843
|
-
this.log.info(
|
|
1844
|
-
`***${db}Commissioning controller attributeChangedCallback version ${version}: attribute ${BLUE}${nodeId}${db}/${or}${endpointId}${db}/${hk}${getClusterNameById(clusterId)}${db}/${zb}${attributeName}${db} changed to ${typeof value === 'object' ? debugStringify(value ?? { none: true }) : value}`,
|
|
1845
|
-
),
|
|
1846
|
-
eventTriggeredCallback: ({ path: { nodeId, clusterId, endpointId, eventName }, events }) => {
|
|
1847
|
-
this.log.info(
|
|
1848
|
-
`***${db}Commissioning controller eventTriggeredCallback: event ${BLUE}${nodeId}${db}/${or}${endpointId}${db}/${hk}${getClusterNameById(clusterId)}${db}/${zb}${eventName}${db} triggered with ${debugStringify(events ?? { none: true })}`,
|
|
1849
|
-
);
|
|
1850
|
-
},
|
|
1851
|
-
});
|
|
1852
|
-
this.log.info('Subscribed to all attributes and events');
|
|
1853
|
-
}
|
|
1854
|
-
*/
|
|
1855
1343
|
}
|
|
1856
|
-
/** ***********************************************************************************************************************************/
|
|
1857
|
-
/** Matter.js methods */
|
|
1858
|
-
/** ***********************************************************************************************************************************/
|
|
1859
|
-
/**
|
|
1860
|
-
* Starts the matter storage process with name Matterbridge.
|
|
1861
|
-
* @returns {Promise<void>} - A promise that resolves when the storage process is started.
|
|
1862
|
-
*/
|
|
1863
1344
|
async startMatterStorage() {
|
|
1864
|
-
// Setup Matter storage
|
|
1865
1345
|
this.log.info(`Starting matter node storage...`);
|
|
1866
1346
|
this.matterStorageService = this.environment.get(StorageService);
|
|
1867
1347
|
this.log.info(`Matter node storage service created: ${this.matterStorageService.location}`);
|
|
@@ -1870,25 +1350,18 @@ export class Matterbridge extends EventEmitter {
|
|
|
1870
1350
|
this.matterbridgeContext = await this.createServerNodeContext('Matterbridge', 'Matterbridge', bridge.code, this.aggregatorVendorId, this.aggregatorVendorName, this.aggregatorProductId, this.aggregatorProductName);
|
|
1871
1351
|
this.matterbridgeInformation.matterbridgeSerialNumber = await this.matterbridgeContext.get('serialNumber', '');
|
|
1872
1352
|
this.log.info('Matter node storage started');
|
|
1873
|
-
// Backup matter storage since it is created/opened correctly
|
|
1874
1353
|
await this.backupMatterStorage(path.join(this.matterbridgeDirectory, this.matterStorageName), path.join(this.matterbridgeDirectory, this.matterStorageName + '.backup'));
|
|
1875
1354
|
}
|
|
1876
|
-
/**
|
|
1877
|
-
* Makes a backup copy of the specified matter storage directory.
|
|
1878
|
-
*
|
|
1879
|
-
* @param storageName - The name of the storage directory to be backed up.
|
|
1880
|
-
* @param backupName - The name of the backup directory to be created.
|
|
1881
|
-
* @returns {Promise<void>} A promise that resolves when the has been done.
|
|
1882
|
-
*/
|
|
1883
1355
|
async backupMatterStorage(storageName, backupName) {
|
|
1884
1356
|
this.log.info('Creating matter node storage backup...');
|
|
1885
|
-
|
|
1886
|
-
|
|
1357
|
+
try {
|
|
1358
|
+
await copyDirectory(storageName, backupName);
|
|
1359
|
+
this.log.info('Created matter node storage backup');
|
|
1360
|
+
}
|
|
1361
|
+
catch (error) {
|
|
1362
|
+
this.log.error(`Error creating matter node storage backup from ${storageName} to ${backupName}:`, error);
|
|
1363
|
+
}
|
|
1887
1364
|
}
|
|
1888
|
-
/**
|
|
1889
|
-
* Stops the matter storage.
|
|
1890
|
-
* @returns {Promise<void>} A promise that resolves when the storage is stopped.
|
|
1891
|
-
*/
|
|
1892
1365
|
async stopMatterStorage() {
|
|
1893
1366
|
this.log.info('Closing matter node storage...');
|
|
1894
1367
|
await this.matterStorageManager?.close();
|
|
@@ -1897,19 +1370,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1897
1370
|
this.matterbridgeContext = undefined;
|
|
1898
1371
|
this.log.info('Matter node storage closed');
|
|
1899
1372
|
}
|
|
1900
|
-
/**
|
|
1901
|
-
* Creates a server node storage context.
|
|
1902
|
-
*
|
|
1903
|
-
* @param {string} pluginName - The name of the plugin.
|
|
1904
|
-
* @param {string} deviceName - The name of the device.
|
|
1905
|
-
* @param {DeviceTypeId} deviceType - The device type of the device.
|
|
1906
|
-
* @param {number} vendorId - The vendor ID.
|
|
1907
|
-
* @param {string} vendorName - The vendor name.
|
|
1908
|
-
* @param {number} productId - The product ID.
|
|
1909
|
-
* @param {string} productName - The product name.
|
|
1910
|
-
* @param {string} [serialNumber] - The serial number of the device (optional).
|
|
1911
|
-
* @returns {Promise<StorageContext>} The storage context for the commissioning server.
|
|
1912
|
-
*/
|
|
1913
1373
|
async createServerNodeContext(pluginName, deviceName, deviceType, vendorId, vendorName, productId, productName, serialNumber) {
|
|
1914
1374
|
const { randomBytes } = await import('node:crypto');
|
|
1915
1375
|
if (!this.matterStorageService)
|
|
@@ -1943,15 +1403,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1943
1403
|
this.log.debug(`- hardwareVersion: ${await storageContext.get('hardwareVersion')} hardwareVersionString: ${await storageContext.get('hardwareVersionString')}`);
|
|
1944
1404
|
return storageContext;
|
|
1945
1405
|
}
|
|
1946
|
-
/**
|
|
1947
|
-
* Creates a server node.
|
|
1948
|
-
*
|
|
1949
|
-
* @param {StorageContext} storageContext - The storage context for the server node.
|
|
1950
|
-
* @param {number} [port=5540] - The port number for the server node. Defaults to 5540.
|
|
1951
|
-
* @param {number} [passcode=20242025] - The passcode for the server node. Defaults to 20242025.
|
|
1952
|
-
* @param {number} [discriminator=3850] - The discriminator for the server node. Defaults to 3850.
|
|
1953
|
-
* @returns {Promise<ServerNode<ServerNode.RootEndpoint>>} A promise that resolves to the created server node.
|
|
1954
|
-
*/
|
|
1955
1406
|
async createServerNode(storageContext, port = 5540, passcode = 20242025, discriminator = 3850) {
|
|
1956
1407
|
const storeId = await storageContext.get('storeId');
|
|
1957
1408
|
this.log.notice(`Creating server node for ${storeId} on port ${port} with passcode ${passcode} and discriminator ${discriminator}...`);
|
|
@@ -1961,37 +1412,24 @@ export class Matterbridge extends EventEmitter {
|
|
|
1961
1412
|
this.log.debug(`- uniqueId: ${await storageContext.get('uniqueId')}`);
|
|
1962
1413
|
this.log.debug(`- softwareVersion: ${await storageContext.get('softwareVersion')} softwareVersionString: ${await storageContext.get('softwareVersionString')}`);
|
|
1963
1414
|
this.log.debug(`- hardwareVersion: ${await storageContext.get('hardwareVersion')} hardwareVersionString: ${await storageContext.get('hardwareVersionString')}`);
|
|
1964
|
-
/**
|
|
1965
|
-
* Create a Matter ServerNode, which contains the Root Endpoint and all relevant data and configuration
|
|
1966
|
-
*/
|
|
1967
1415
|
const serverNode = await ServerNode.create({
|
|
1968
|
-
// Required: Give the Node a unique ID which is used to store the state of this node
|
|
1969
1416
|
id: storeId,
|
|
1970
|
-
// Provide Network relevant configuration like the port
|
|
1971
|
-
// Optional when operating only one device on a host, Default port is 5540
|
|
1972
1417
|
network: {
|
|
1973
1418
|
listeningAddressIpv4: this.ipv4address,
|
|
1974
1419
|
listeningAddressIpv6: this.ipv6address,
|
|
1975
1420
|
port,
|
|
1976
1421
|
},
|
|
1977
|
-
// Provide the certificate for the device
|
|
1978
1422
|
operationalCredentials: {
|
|
1979
1423
|
certification: this.certification,
|
|
1980
1424
|
},
|
|
1981
|
-
// Provide Commissioning relevant settings
|
|
1982
|
-
// Optional for development/testing purposes
|
|
1983
1425
|
commissioning: {
|
|
1984
1426
|
passcode,
|
|
1985
1427
|
discriminator,
|
|
1986
1428
|
},
|
|
1987
|
-
// Provide Node announcement settings
|
|
1988
|
-
// Optional: If Ommitted some development defaults are used
|
|
1989
1429
|
productDescription: {
|
|
1990
1430
|
name: await storageContext.get('deviceName'),
|
|
1991
1431
|
deviceType: DeviceTypeId(await storageContext.get('deviceType')),
|
|
1992
1432
|
},
|
|
1993
|
-
// Provide defaults for the BasicInformation cluster on the Root endpoint
|
|
1994
|
-
// Optional: If Omitted some development defaults are used
|
|
1995
1433
|
basicInformation: {
|
|
1996
1434
|
vendorId: VendorId(await storageContext.get('vendorId')),
|
|
1997
1435
|
vendorName: await storageContext.get('vendorName'),
|
|
@@ -2009,13 +1447,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
2009
1447
|
},
|
|
2010
1448
|
});
|
|
2011
1449
|
const sanitizeFabrics = (fabrics, resetSessions = false) => {
|
|
2012
|
-
// New type of fabric information: Record<FabricIndex, ExposedFabricInformation>
|
|
2013
1450
|
const sanitizedFabrics = this.sanitizeFabricInformations(Array.from(Object.values(fabrics)));
|
|
2014
1451
|
this.log.info(`Fabrics: ${debugStringify(sanitizedFabrics)}`);
|
|
2015
1452
|
if (this.bridgeMode === 'bridge') {
|
|
2016
1453
|
this.matterbridgeFabricInformations = sanitizedFabrics;
|
|
2017
1454
|
if (resetSessions)
|
|
2018
|
-
this.matterbridgeSessionInformations = undefined;
|
|
1455
|
+
this.matterbridgeSessionInformations = undefined;
|
|
2019
1456
|
this.matterbridgePaired = true;
|
|
2020
1457
|
}
|
|
2021
1458
|
if (this.bridgeMode === 'childbridge') {
|
|
@@ -2023,19 +1460,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
2023
1460
|
if (plugin) {
|
|
2024
1461
|
plugin.fabricInformations = sanitizedFabrics;
|
|
2025
1462
|
if (resetSessions)
|
|
2026
|
-
plugin.sessionInformations = undefined;
|
|
1463
|
+
plugin.sessionInformations = undefined;
|
|
2027
1464
|
plugin.paired = true;
|
|
2028
1465
|
}
|
|
2029
1466
|
}
|
|
2030
1467
|
};
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
serverNode.lifecycle.commissioned.on(() => this.log.notice(`Server node for ${storeId} was initially commissioned successfully!`));
|
|
2036
|
-
/** This event is triggered when all fabrics are removed from the device, usually it also does a factory reset then. */
|
|
1468
|
+
serverNode.lifecycle.commissioned.on(() => {
|
|
1469
|
+
this.log.notice(`Server node for ${storeId} was initially commissioned successfully!`);
|
|
1470
|
+
clearTimeout(this.endAdvertiseTimeout);
|
|
1471
|
+
});
|
|
2037
1472
|
serverNode.lifecycle.decommissioned.on(() => this.log.notice(`Server node for ${storeId} was fully decommissioned successfully!`));
|
|
2038
|
-
/** This event is triggered when the device went online. This means that it is discoverable in the network. */
|
|
2039
1473
|
serverNode.lifecycle.online.on(async () => {
|
|
2040
1474
|
this.log.notice(`Server node for ${storeId} is online`);
|
|
2041
1475
|
if (!serverNode.lifecycle.isCommissioned) {
|
|
@@ -2074,27 +1508,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
2074
1508
|
}
|
|
2075
1509
|
}
|
|
2076
1510
|
}
|
|
2077
|
-
|
|
2078
|
-
if (serverNode.lifecycle.isCommissioned)
|
|
2079
|
-
return;
|
|
2080
|
-
if (this.bridgeMode === 'bridge') {
|
|
2081
|
-
this.matterbridgeQrPairingCode = undefined;
|
|
2082
|
-
this.matterbridgeManualPairingCode = undefined;
|
|
2083
|
-
}
|
|
2084
|
-
if (this.bridgeMode === 'childbridge') {
|
|
2085
|
-
const plugin = this.plugins.get(storeId);
|
|
2086
|
-
if (plugin) {
|
|
2087
|
-
plugin.qrPairingCode = undefined;
|
|
2088
|
-
plugin.manualPairingCode = undefined;
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
this.frontend.wssSendRefreshRequired('plugins');
|
|
2092
|
-
this.frontend.wssSendRefreshRequired('settings');
|
|
2093
|
-
this.frontend.wssSendRefreshRequired('fabrics');
|
|
2094
|
-
this.frontend.wssSendRefreshRequired('sessions');
|
|
2095
|
-
this.frontend.wssSendSnackbarMessage(`Advertising on server node for ${storeId} stopped. Restart to commission.`, 0);
|
|
2096
|
-
this.log.notice(`Advertising on server node for ${storeId} stopped. Restart to commission.`);
|
|
2097
|
-
}, 15 * 60 * 1000).unref();
|
|
1511
|
+
this.startEndAdvertiseTimer(serverNode);
|
|
2098
1512
|
}
|
|
2099
1513
|
else {
|
|
2100
1514
|
this.log.notice(`Server node for ${storeId} is already commissioned. Waiting for controllers to connect ...`);
|
|
@@ -2103,8 +1517,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
2103
1517
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
2104
1518
|
this.frontend.wssSendRefreshRequired('settings');
|
|
2105
1519
|
this.frontend.wssSendSnackbarMessage(`${storeId} is online`, 5, 'success');
|
|
1520
|
+
this.emit('online', storeId);
|
|
2106
1521
|
});
|
|
2107
|
-
/** This event is triggered when the device went offline. it is not longer discoverable or connectable in the network. */
|
|
2108
1522
|
serverNode.lifecycle.offline.on(() => {
|
|
2109
1523
|
this.log.notice(`Server node for ${storeId} is offline`);
|
|
2110
1524
|
if (this.bridgeMode === 'bridge') {
|
|
@@ -2127,11 +1541,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
2127
1541
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
2128
1542
|
this.frontend.wssSendRefreshRequired('settings');
|
|
2129
1543
|
this.frontend.wssSendSnackbarMessage(`${storeId} is offline`, 5, 'warning');
|
|
1544
|
+
this.emit('offline', storeId);
|
|
2130
1545
|
});
|
|
2131
|
-
/**
|
|
2132
|
-
* This event is triggered when a fabric is added, removed or updated on the device. Use this if more granular
|
|
2133
|
-
* information is needed.
|
|
2134
|
-
*/
|
|
2135
1546
|
serverNode.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {
|
|
2136
1547
|
let action = '';
|
|
2137
1548
|
switch (fabricAction) {
|
|
@@ -2165,24 +1576,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
2165
1576
|
}
|
|
2166
1577
|
}
|
|
2167
1578
|
};
|
|
2168
|
-
/**
|
|
2169
|
-
* This event is triggered when an operative new session was opened by a Controller.
|
|
2170
|
-
* It is not triggered for the initial commissioning process, just afterwards for real connections.
|
|
2171
|
-
*/
|
|
2172
1579
|
serverNode.events.sessions.opened.on((session) => {
|
|
2173
1580
|
this.log.notice(`Session opened on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2174
1581
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
2175
1582
|
this.frontend.wssSendRefreshRequired('sessions');
|
|
2176
1583
|
});
|
|
2177
|
-
/**
|
|
2178
|
-
* This event is triggered when an operative session is closed by a Controller or because the Device goes offline.
|
|
2179
|
-
*/
|
|
2180
1584
|
serverNode.events.sessions.closed.on((session) => {
|
|
2181
1585
|
this.log.notice(`Session closed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2182
1586
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
2183
1587
|
this.frontend.wssSendRefreshRequired('sessions');
|
|
2184
1588
|
});
|
|
2185
|
-
/** This event is triggered when a subscription gets added or removed on an operative session. */
|
|
2186
1589
|
serverNode.events.sessions.subscriptionsChanged.on((session) => {
|
|
2187
1590
|
this.log.notice(`Session subscriptions changed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2188
1591
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
@@ -2191,42 +1594,52 @@ export class Matterbridge extends EventEmitter {
|
|
|
2191
1594
|
this.log.info(`Created server node for ${storeId}`);
|
|
2192
1595
|
return serverNode;
|
|
2193
1596
|
}
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
1597
|
+
startEndAdvertiseTimer(matterServerNode) {
|
|
1598
|
+
if (this.endAdvertiseTimeout) {
|
|
1599
|
+
this.log.debug(`***Clear ${matterServerNode.id} server node end advertise timer`);
|
|
1600
|
+
clearTimeout(this.endAdvertiseTimeout);
|
|
1601
|
+
}
|
|
1602
|
+
this.log.debug(`***Starting ${matterServerNode.id} server node end advertise timer`);
|
|
1603
|
+
this.endAdvertiseTimeout = setTimeout(() => {
|
|
1604
|
+
if (matterServerNode.lifecycle.isCommissioned)
|
|
1605
|
+
return;
|
|
1606
|
+
if (this.bridgeMode === 'bridge') {
|
|
1607
|
+
this.matterbridgeQrPairingCode = undefined;
|
|
1608
|
+
this.matterbridgeManualPairingCode = undefined;
|
|
1609
|
+
}
|
|
1610
|
+
if (this.bridgeMode === 'childbridge') {
|
|
1611
|
+
const plugin = this.plugins.get(matterServerNode.id);
|
|
1612
|
+
if (plugin) {
|
|
1613
|
+
plugin.qrPairingCode = undefined;
|
|
1614
|
+
plugin.manualPairingCode = undefined;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
this.frontend.wssSendRefreshRequired('plugins');
|
|
1618
|
+
this.frontend.wssSendRefreshRequired('settings');
|
|
1619
|
+
this.frontend.wssSendRefreshRequired('fabrics');
|
|
1620
|
+
this.frontend.wssSendRefreshRequired('sessions');
|
|
1621
|
+
this.frontend.wssSendSnackbarMessage(`Advertising on server node for ${matterServerNode.id} stopped. Restart to commission.`, 0);
|
|
1622
|
+
this.log.notice(`Advertising on server node for ${matterServerNode.id} stopped. Restart to commission.`);
|
|
1623
|
+
}, 15 * 60 * 1000).unref();
|
|
1624
|
+
}
|
|
2200
1625
|
async startServerNode(matterServerNode) {
|
|
2201
1626
|
if (!matterServerNode)
|
|
2202
1627
|
return;
|
|
2203
1628
|
this.log.notice(`Starting ${matterServerNode.id} server node`);
|
|
2204
1629
|
await matterServerNode.start();
|
|
2205
1630
|
}
|
|
2206
|
-
|
|
2207
|
-
* Stops the specified server node.
|
|
2208
|
-
*
|
|
2209
|
-
* @param {ServerNode} matterServerNode - The server node to stop.
|
|
2210
|
-
* @returns {Promise<void>} A promise that resolves when the server node has stopped.
|
|
2211
|
-
*/
|
|
2212
|
-
async stopServerNode(matterServerNode) {
|
|
1631
|
+
async stopServerNode(matterServerNode, timeout = 30000) {
|
|
2213
1632
|
if (!matterServerNode)
|
|
2214
1633
|
return;
|
|
2215
1634
|
this.log.notice(`Closing ${matterServerNode.id} server node`);
|
|
2216
1635
|
try {
|
|
2217
|
-
await withTimeout(matterServerNode.close(),
|
|
1636
|
+
await withTimeout(matterServerNode.close(), timeout);
|
|
2218
1637
|
this.log.info(`Closed ${matterServerNode.id} server node`);
|
|
2219
1638
|
}
|
|
2220
1639
|
catch (error) {
|
|
2221
1640
|
this.log.error(`Failed to close ${matterServerNode.id} server node: ${error instanceof Error ? error.message : error}`);
|
|
2222
1641
|
}
|
|
2223
1642
|
}
|
|
2224
|
-
/**
|
|
2225
|
-
* Advertises the specified server node.
|
|
2226
|
-
*
|
|
2227
|
-
* @param {ServerNode} [matterServerNode] - The server node to advertise.
|
|
2228
|
-
* @returns {Promise<{ qrPairingCode: string, manualPairingCode: string } | undefined>} A promise that resolves to the pairing codes if the server node is advertised, or undefined if not.
|
|
2229
|
-
*/
|
|
2230
1643
|
async advertiseServerNode(matterServerNode) {
|
|
2231
1644
|
if (matterServerNode) {
|
|
2232
1645
|
await matterServerNode.env.get(DeviceCommissioner)?.allowBasicCommissioning();
|
|
@@ -2235,46 +1648,25 @@ export class Matterbridge extends EventEmitter {
|
|
|
2235
1648
|
return { qrPairingCode, manualPairingCode };
|
|
2236
1649
|
}
|
|
2237
1650
|
}
|
|
2238
|
-
/**
|
|
2239
|
-
* Stop advertise the specified server node.
|
|
2240
|
-
*
|
|
2241
|
-
* @param {ServerNode} [matterServerNode] - The server node to advertise.
|
|
2242
|
-
* @returns {Promise<void>} A promise that resolves when the server node has stopped advertising.
|
|
2243
|
-
*/
|
|
2244
1651
|
async stopAdvertiseServerNode(matterServerNode) {
|
|
2245
1652
|
if (matterServerNode && matterServerNode.lifecycle.isOnline) {
|
|
2246
1653
|
await matterServerNode.env.get(DeviceCommissioner)?.endCommissioning();
|
|
2247
1654
|
this.log.notice(`Stopped advertising for ${matterServerNode.id}`);
|
|
2248
1655
|
}
|
|
2249
1656
|
}
|
|
2250
|
-
/**
|
|
2251
|
-
* Creates an aggregator node with the specified storage context.
|
|
2252
|
-
*
|
|
2253
|
-
* @param {StorageContext} storageContext - The storage context for the aggregator node.
|
|
2254
|
-
* @returns {Promise<Endpoint<AggregatorEndpoint>>} A promise that resolves to the created aggregator node.
|
|
2255
|
-
*/
|
|
2256
1657
|
async createAggregatorNode(storageContext) {
|
|
2257
1658
|
this.log.notice(`Creating ${await storageContext.get('storeId')} aggregator...`);
|
|
2258
1659
|
const aggregatorNode = new Endpoint(AggregatorEndpoint, { id: `${await storageContext.get('storeId')}` });
|
|
2259
1660
|
this.log.info(`Created ${await storageContext.get('storeId')} aggregator`);
|
|
2260
1661
|
return aggregatorNode;
|
|
2261
1662
|
}
|
|
2262
|
-
/**
|
|
2263
|
-
* Adds a MatterbridgeEndpoint to the specified plugin.
|
|
2264
|
-
*
|
|
2265
|
-
* @param {string} pluginName - The name of the plugin.
|
|
2266
|
-
* @param {MatterbridgeEndpoint} device - The device to add as a bridged endpoint.
|
|
2267
|
-
* @returns {Promise<void>} A promise that resolves when the bridged endpoint has been added.
|
|
2268
|
-
*/
|
|
2269
1663
|
async addBridgedEndpoint(pluginName, device) {
|
|
2270
|
-
// Check if the plugin is registered
|
|
2271
1664
|
const plugin = this.plugins.get(pluginName);
|
|
2272
1665
|
if (!plugin) {
|
|
2273
1666
|
this.log.error(`Error adding bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.id}${er}) plugin ${plg}${pluginName}${er} not found`);
|
|
2274
1667
|
return;
|
|
2275
1668
|
}
|
|
2276
1669
|
if (this.bridgeMode === 'bridge') {
|
|
2277
|
-
// Register and add the device to the matterbridge aggregator node
|
|
2278
1670
|
this.log.debug(`Adding bridged endpoint ${plg}${pluginName}${db}:${dev}${device.deviceName}${db} to Matterbridge aggregator node`);
|
|
2279
1671
|
if (!this.aggregatorNode) {
|
|
2280
1672
|
this.log.error('Aggregator node not found for Matterbridge');
|
|
@@ -2291,7 +1683,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2291
1683
|
}
|
|
2292
1684
|
}
|
|
2293
1685
|
else if (this.bridgeMode === 'childbridge') {
|
|
2294
|
-
// Register and add the device to the plugin server node
|
|
2295
1686
|
if (plugin.type === 'AccessoryPlatform') {
|
|
2296
1687
|
try {
|
|
2297
1688
|
this.log.debug(`Creating endpoint ${dev}${device.deviceName}${db} for AccessoryPlatform plugin ${plg}${plugin.name}${db} server node`);
|
|
@@ -2308,12 +1699,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
2308
1699
|
return;
|
|
2309
1700
|
}
|
|
2310
1701
|
}
|
|
2311
|
-
// Register and add the device to the plugin aggregator node
|
|
2312
1702
|
if (plugin.type === 'DynamicPlatform') {
|
|
2313
1703
|
try {
|
|
2314
1704
|
this.log.debug(`Adding bridged endpoint ${dev}${device.deviceName}${db} for DynamicPlatform plugin ${plg}${plugin.name}${db} aggregator node`);
|
|
2315
1705
|
await this.createDynamicPlugin(plugin);
|
|
2316
|
-
// Fast plugins can add another device before the server node is created
|
|
2317
1706
|
await waiter(`createDynamicPlugin(${plugin.name})`, () => plugin.serverNode?.hasParts === true);
|
|
2318
1707
|
if (!plugin.aggregatorNode) {
|
|
2319
1708
|
this.log.error(`Aggregator node not found for plugin ${plg}${plugin.name}${er}`);
|
|
@@ -2333,28 +1722,17 @@ export class Matterbridge extends EventEmitter {
|
|
|
2333
1722
|
plugin.registeredDevices++;
|
|
2334
1723
|
if (plugin.addedDevices !== undefined)
|
|
2335
1724
|
plugin.addedDevices++;
|
|
2336
|
-
// Add the device to the DeviceManager
|
|
2337
1725
|
this.devices.set(device);
|
|
2338
|
-
// Subscribe to the reachable$Changed event
|
|
2339
1726
|
await this.subscribeAttributeChanged(plugin, device);
|
|
2340
1727
|
this.log.info(`Added and registered bridged endpoint (${plugin.registeredDevices}/${plugin.addedDevices}) ${dev}${device.deviceName}${nf} (${dev}${device.id}${nf}) for plugin ${plg}${pluginName}${nf}`);
|
|
2341
1728
|
}
|
|
2342
|
-
/**
|
|
2343
|
-
* Removes a MatterbridgeEndpoint from the specified plugin.
|
|
2344
|
-
*
|
|
2345
|
-
* @param {string} pluginName - The name of the plugin.
|
|
2346
|
-
* @param {MatterbridgeEndpoint} device - The device to remove as a bridged endpoint.
|
|
2347
|
-
* @returns {Promise<void>} A promise that resolves when the bridged endpoint has been removed.
|
|
2348
|
-
*/
|
|
2349
1729
|
async removeBridgedEndpoint(pluginName, device) {
|
|
2350
1730
|
this.log.debug(`Removing bridged endpoint ${plg}${pluginName}${db}:${dev}${device.deviceName}${db} (${zb}${device.name}${db}) for plugin ${plg}${pluginName}${db}`);
|
|
2351
|
-
// Check if the plugin is registered
|
|
2352
1731
|
const plugin = this.plugins.get(pluginName);
|
|
2353
1732
|
if (!plugin) {
|
|
2354
1733
|
this.log.error(`Error removing bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.name}${er}) for plugin ${plg}${pluginName}${er}: plugin not found`);
|
|
2355
1734
|
return;
|
|
2356
1735
|
}
|
|
2357
|
-
// Register and add the device to the matterbridge aggregator node
|
|
2358
1736
|
if (this.bridgeMode === 'bridge') {
|
|
2359
1737
|
if (!this.aggregatorNode) {
|
|
2360
1738
|
this.log.error(`Error removing bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.name}${er}) for plugin ${plg}${pluginName}${er}: aggregator node not found`);
|
|
@@ -2369,7 +1747,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2369
1747
|
}
|
|
2370
1748
|
else if (this.bridgeMode === 'childbridge') {
|
|
2371
1749
|
if (plugin.type === 'AccessoryPlatform') {
|
|
2372
|
-
// Nothing to do here since the server node has no aggregator node but only the device itself
|
|
2373
1750
|
}
|
|
2374
1751
|
else if (plugin.type === 'DynamicPlatform') {
|
|
2375
1752
|
if (!plugin.aggregatorNode) {
|
|
@@ -2384,21 +1761,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
2384
1761
|
if (plugin.addedDevices !== undefined)
|
|
2385
1762
|
plugin.addedDevices--;
|
|
2386
1763
|
}
|
|
2387
|
-
// Remove the device from the DeviceManager
|
|
2388
1764
|
this.devices.remove(device);
|
|
2389
1765
|
}
|
|
2390
|
-
/**
|
|
2391
|
-
* Removes all bridged endpoints from the specified plugin.
|
|
2392
|
-
*
|
|
2393
|
-
* @param {string} pluginName - The name of the plugin.
|
|
2394
|
-
* @param {number} [delay=0] - The delay in milliseconds between removing each bridged endpoint (default: 0).
|
|
2395
|
-
* @returns {Promise<void>} A promise that resolves when all bridged endpoints have been removed.
|
|
2396
|
-
*
|
|
2397
|
-
* @remarks
|
|
2398
|
-
* This method iterates through all devices in the DeviceManager and removes each bridged endpoint associated with the specified plugin.
|
|
2399
|
-
* It also applies a delay between each removal if specified.
|
|
2400
|
-
* The delay is useful to allow the controllers to receive a single subscription for each device removed.
|
|
2401
|
-
*/
|
|
2402
1766
|
async removeAllBridgedEndpoints(pluginName, delay = 0) {
|
|
2403
1767
|
this.log.debug(`Removing all bridged endpoints for plugin ${plg}${pluginName}${db}${delay > 0 ? ` with delay ${delay} ms` : ''}`);
|
|
2404
1768
|
for (const device of this.devices.array().filter((device) => device.plugin === pluginName)) {
|
|
@@ -2409,15 +1773,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2409
1773
|
if (delay > 0)
|
|
2410
1774
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2411
1775
|
}
|
|
2412
|
-
/**
|
|
2413
|
-
* Subscribes to the attribute change event for the given device and plugin.
|
|
2414
|
-
* Specifically, it listens for changes in the 'reachable' attribute of the
|
|
2415
|
-
* BridgedDeviceBasicInformationServer cluster server of the bridged device or BasicInformationServer cluster server of server node.
|
|
2416
|
-
*
|
|
2417
|
-
* @param {RegisteredPlugin} plugin - The plugin associated with the device.
|
|
2418
|
-
* @param {MatterbridgeEndpoint} device - The device to subscribe to attribute changes for.
|
|
2419
|
-
* @returns {Promise<void>} A promise that resolves when the subscription is set up.
|
|
2420
|
-
*/
|
|
2421
1776
|
async subscribeAttributeChanged(plugin, device) {
|
|
2422
1777
|
this.log.info(`Subscribing attributes for endpoint ${dev}${device.deviceName}${nf} (${dev}${device.id}${nf}) plugin ${plg}${plugin.name}${nf}`);
|
|
2423
1778
|
if (this.bridgeMode === 'childbridge' && plugin.type === 'AccessoryPlatform' && plugin.serverNode) {
|
|
@@ -2433,12 +1788,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2433
1788
|
});
|
|
2434
1789
|
}
|
|
2435
1790
|
}
|
|
2436
|
-
/**
|
|
2437
|
-
* Sanitizes the fabric information by converting bigint properties to strings because `res.json` doesn't support bigint.
|
|
2438
|
-
*
|
|
2439
|
-
* @param {ExposedFabricInformation[]} fabricInfo - The array of exposed fabric information objects.
|
|
2440
|
-
* @returns {SanitizedExposedFabricInformation[]} An array of sanitized exposed fabric information objects.
|
|
2441
|
-
*/
|
|
2442
1791
|
sanitizeFabricInformations(fabricInfo) {
|
|
2443
1792
|
return fabricInfo.map((info) => {
|
|
2444
1793
|
return {
|
|
@@ -2452,12 +1801,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2452
1801
|
};
|
|
2453
1802
|
});
|
|
2454
1803
|
}
|
|
2455
|
-
/**
|
|
2456
|
-
* Sanitizes the session information by converting bigint properties to strings because `res.json` doesn't support bigint.
|
|
2457
|
-
*
|
|
2458
|
-
* @param {SessionInformation[]} sessionInfo - The array of session information objects.
|
|
2459
|
-
* @returns {SanitizedSessionInformation[]} An array of sanitized session information objects.
|
|
2460
|
-
*/
|
|
2461
1804
|
sanitizeSessionInformation(sessionInfo) {
|
|
2462
1805
|
return sessionInfo
|
|
2463
1806
|
.filter((session) => session.isPeerActive)
|
|
@@ -2485,20 +1828,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
2485
1828
|
};
|
|
2486
1829
|
});
|
|
2487
1830
|
}
|
|
2488
|
-
/**
|
|
2489
|
-
* Sets the reachability of the specified aggregator node bridged devices and trigger.
|
|
2490
|
-
* @param {Endpoint<AggregatorEndpoint>} aggregatorNode - The aggregator node to set the reachability for.
|
|
2491
|
-
* @param {boolean} reachable - A boolean indicating the reachability status to set.
|
|
2492
|
-
*/
|
|
2493
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2494
1831
|
async setAggregatorReachability(aggregatorNode, reachable) {
|
|
2495
|
-
/*
|
|
2496
|
-
for (const child of aggregatorNode.parts) {
|
|
2497
|
-
this.log.debug(`Setting reachability of ${(child as unknown as MatterbridgeEndpoint)?.deviceName} to ${reachable}`);
|
|
2498
|
-
await child.setStateOf(BridgedDeviceBasicInformationServer, { reachable });
|
|
2499
|
-
child.act((agent) => child.eventsOf(BridgedDeviceBasicInformationServer).reachableChanged.emit({ reachableNewValue: true }, agent.context));
|
|
2500
|
-
}
|
|
2501
|
-
*/
|
|
2502
1832
|
}
|
|
2503
1833
|
getVendorIdName = (vendorId) => {
|
|
2504
1834
|
if (!vendorId)
|
|
@@ -2541,112 +1871,4 @@ export class Matterbridge extends EventEmitter {
|
|
|
2541
1871
|
}
|
|
2542
1872
|
return vendorName;
|
|
2543
1873
|
};
|
|
2544
|
-
/**
|
|
2545
|
-
* Spawns a child process with the given command and arguments.
|
|
2546
|
-
* @param {string} command - The command to execute.
|
|
2547
|
-
* @param {string[]} args - The arguments to pass to the command (default: []).
|
|
2548
|
-
* @returns {Promise<boolean>} A promise that resolves when the child process exits successfully, or rejects if there is an error.
|
|
2549
|
-
*/
|
|
2550
|
-
async spawnCommand(command, args = []) {
|
|
2551
|
-
const { spawn } = await import('node:child_process');
|
|
2552
|
-
/*
|
|
2553
|
-
npm > npm.cmd on windows
|
|
2554
|
-
cmd.exe ['dir'] on windows
|
|
2555
|
-
await this.spawnCommand('npm', ['install', '-g', 'matterbridge']);
|
|
2556
|
-
*/
|
|
2557
|
-
const cmdLine = command + ' ' + args.join(' ');
|
|
2558
|
-
if (process.platform === 'win32' && command === 'npm') {
|
|
2559
|
-
// Must be spawn('cmd.exe', ['/c', 'npm -g install <package>']);
|
|
2560
|
-
const argstring = 'npm ' + args.join(' ');
|
|
2561
|
-
args.splice(0, args.length, '/c', argstring);
|
|
2562
|
-
command = 'cmd.exe';
|
|
2563
|
-
}
|
|
2564
|
-
// Decide when using sudo on linux
|
|
2565
|
-
// When you need sudo: Spawn stderr: npm error Error: EACCES: permission denied
|
|
2566
|
-
// When you don't need sudo: Failed to start child process "npm install -g matterbridge-eve-door": spawn sudo ENOENT
|
|
2567
|
-
if (hasParameter('sudo') || (process.platform === 'linux' && command === 'npm' && !hasParameter('docker') && !hasParameter('nosudo'))) {
|
|
2568
|
-
args.unshift(command);
|
|
2569
|
-
command = 'sudo';
|
|
2570
|
-
}
|
|
2571
|
-
this.log.debug(`Spawn command ${command} with ${debugStringify(args)}`);
|
|
2572
|
-
return new Promise((resolve, reject) => {
|
|
2573
|
-
const childProcess = spawn(command, args, {
|
|
2574
|
-
stdio: ['inherit', 'pipe', 'pipe'],
|
|
2575
|
-
});
|
|
2576
|
-
childProcess.on('error', (err) => {
|
|
2577
|
-
this.log.error(`Failed to start child process "${cmdLine}": ${err.message}`);
|
|
2578
|
-
reject(err);
|
|
2579
|
-
});
|
|
2580
|
-
childProcess.on('close', (code, signal) => {
|
|
2581
|
-
this.frontend.wssSendMessage('spawn', this.log.now(), 'Matterbridge:spawn', `child process closed with code ${code} and signal ${signal}`);
|
|
2582
|
-
if (code === 0) {
|
|
2583
|
-
if (cmdLine.startsWith('npm install -g'))
|
|
2584
|
-
this.log.notice(`Package ${cmdLine.replace('npm install -g ', '').replace('--verbose', '').replace('--omit=dev', '')} installed correctly`);
|
|
2585
|
-
this.log.debug(`Child process "${cmdLine}" closed with code ${code} and signal ${signal}`);
|
|
2586
|
-
resolve(true);
|
|
2587
|
-
}
|
|
2588
|
-
else {
|
|
2589
|
-
this.log.error(`Child process "${cmdLine}" closed with code ${code} and signal ${signal}`);
|
|
2590
|
-
reject(new Error(`Child process "${cmdLine}" closed with code ${code} and signal ${signal}`));
|
|
2591
|
-
}
|
|
2592
|
-
});
|
|
2593
|
-
childProcess.on('exit', (code, signal) => {
|
|
2594
|
-
this.frontend.wssSendMessage('spawn', this.log.now(), 'Matterbridge:spawn', `child process exited with code ${code} and signal ${signal}`);
|
|
2595
|
-
if (code === 0) {
|
|
2596
|
-
this.log.debug(`Child process "${cmdLine}" exited with code ${code} and signal ${signal}`);
|
|
2597
|
-
resolve(true);
|
|
2598
|
-
}
|
|
2599
|
-
else {
|
|
2600
|
-
this.log.error(`Child process "${cmdLine}" exited with code ${code} and signal ${signal}`);
|
|
2601
|
-
reject(new Error(`Child process "${cmdLine}" exited with code ${code} and signal ${signal}`));
|
|
2602
|
-
}
|
|
2603
|
-
});
|
|
2604
|
-
childProcess.on('disconnect', () => {
|
|
2605
|
-
this.log.debug(`Child process "${cmdLine}" has been disconnected from the parent`);
|
|
2606
|
-
resolve(true);
|
|
2607
|
-
});
|
|
2608
|
-
if (childProcess.stdout) {
|
|
2609
|
-
childProcess.stdout.on('data', (data) => {
|
|
2610
|
-
const message = data.toString().trim();
|
|
2611
|
-
this.log.debug(`Spawn output (stdout): ${message}`);
|
|
2612
|
-
this.frontend.wssSendMessage('spawn', this.log.now(), 'Matterbridge:spawn', message);
|
|
2613
|
-
});
|
|
2614
|
-
}
|
|
2615
|
-
if (childProcess.stderr) {
|
|
2616
|
-
childProcess.stderr.on('data', (data) => {
|
|
2617
|
-
const message = data.toString().trim();
|
|
2618
|
-
this.log.debug(`Spawn verbose (stderr): ${message}`);
|
|
2619
|
-
this.frontend.wssSendMessage('spawn', this.log.now(), 'Matterbridge:spawn', message);
|
|
2620
|
-
});
|
|
2621
|
-
}
|
|
2622
|
-
});
|
|
2623
|
-
}
|
|
2624
|
-
/**
|
|
2625
|
-
* Creates a directory at the specified path if it doesn't already exist.
|
|
2626
|
-
*
|
|
2627
|
-
* @param {string} path - The path to the directory to create.
|
|
2628
|
-
* @param {string} name - The name of the directory.
|
|
2629
|
-
* @returns {Promise<void>} A promise that resolves when the directory has been created or already exists.
|
|
2630
|
-
*/
|
|
2631
|
-
async createDirectory(path, name) {
|
|
2632
|
-
try {
|
|
2633
|
-
await fs.access(path);
|
|
2634
|
-
this.log.debug(`Directory ${name} already exists at path: ${path}`);
|
|
2635
|
-
}
|
|
2636
|
-
catch (err) {
|
|
2637
|
-
if (err.code === 'ENOENT') {
|
|
2638
|
-
try {
|
|
2639
|
-
await fs.mkdir(path, { recursive: true });
|
|
2640
|
-
this.log.info(`Created ${name}: ${path}`);
|
|
2641
|
-
}
|
|
2642
|
-
catch (err) {
|
|
2643
|
-
this.log.error(`Error creating dir ${name} path ${path}: ${err}`);
|
|
2644
|
-
}
|
|
2645
|
-
}
|
|
2646
|
-
else {
|
|
2647
|
-
this.log.error(`Error accessing dir ${name} path ${path}: ${err}`);
|
|
2648
|
-
}
|
|
2649
|
-
}
|
|
2650
|
-
}
|
|
2651
1874
|
}
|
|
2652
|
-
//# sourceMappingURL=matterbridge.js.map
|