matterbridge 3.0.5 → 3.0.6-dev-20250611-6f49811
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 +16 -67
- 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 +103 -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 +30 -930
- 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,74 @@ export class Matterbridge extends EventEmitter {
|
|
|
284
204
|
servers.push(plugin.serverNode);
|
|
285
205
|
}
|
|
286
206
|
}
|
|
287
|
-
|
|
207
|
+
await Promise.resolve();
|
|
288
208
|
await this.cleanup('destroying instance...', false);
|
|
289
|
-
// Close servers mdns service
|
|
290
209
|
this.log.info(`Dispose ${servers.length} MdnsService...`);
|
|
291
210
|
for (const server of servers) {
|
|
292
211
|
await server.env.get(MdnsService)[Symbol.asyncDispose]();
|
|
293
212
|
this.log.info(`Closed ${server.id} MdnsService`);
|
|
294
213
|
}
|
|
295
|
-
|
|
214
|
+
await Promise.resolve();
|
|
296
215
|
await new Promise((resolve) => {
|
|
297
216
|
setTimeout(resolve, 500);
|
|
298
217
|
});
|
|
299
218
|
}
|
|
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
219
|
async initialize() {
|
|
311
|
-
// Emit the initialize_started event
|
|
312
220
|
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
|
|
221
|
+
this.log = new AnsiLogger({ logName: 'Matterbridge', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
|
|
316
222
|
if (hasParameter('service'))
|
|
317
223
|
this.restartMode = 'service';
|
|
318
224
|
if (hasParameter('docker'))
|
|
319
225
|
this.restartMode = 'docker';
|
|
320
|
-
// Set the matterbridge home directory
|
|
321
226
|
this.homeDirectory = getParameter('homedir') ?? os.homedir();
|
|
322
227
|
this.matterbridgeInformation.homeDirectory = this.homeDirectory;
|
|
323
|
-
await
|
|
324
|
-
// Set the matterbridge directory
|
|
228
|
+
await createDirectory(this.homeDirectory, 'Matterbridge Home Directory', this.log);
|
|
325
229
|
this.matterbridgeDirectory = path.join(this.homeDirectory, '.matterbridge');
|
|
326
230
|
this.matterbridgeInformation.matterbridgeDirectory = this.matterbridgeDirectory;
|
|
327
|
-
await
|
|
328
|
-
await
|
|
329
|
-
await
|
|
330
|
-
// Set the matterbridge plugin directory
|
|
231
|
+
await createDirectory(this.matterbridgeDirectory, 'Matterbridge Directory', this.log);
|
|
232
|
+
await createDirectory(path.join(this.matterbridgeDirectory, 'certs'), 'Matterbridge Frontend Certificate Directory', this.log);
|
|
233
|
+
await createDirectory(path.join(this.matterbridgeDirectory, 'uploads'), 'Matterbridge Frontend Uploads Directory', this.log);
|
|
331
234
|
this.matterbridgePluginDirectory = path.join(this.homeDirectory, 'Matterbridge');
|
|
332
235
|
this.matterbridgeInformation.matterbridgePluginDirectory = this.matterbridgePluginDirectory;
|
|
333
|
-
await
|
|
334
|
-
// Set the matterbridge cert directory
|
|
236
|
+
await createDirectory(this.matterbridgePluginDirectory, 'Matterbridge Plugin Directory', this.log);
|
|
335
237
|
this.matterbridgeCertDirectory = path.join(this.homeDirectory, '.mattercert');
|
|
336
238
|
this.matterbridgeInformation.matterbridgeCertDirectory = this.matterbridgeCertDirectory;
|
|
337
|
-
await
|
|
338
|
-
// Set the matterbridge root directory
|
|
239
|
+
await createDirectory(this.matterbridgeCertDirectory, 'Matterbridge Matter Certificate Directory', this.log);
|
|
339
240
|
const { fileURLToPath } = await import('node:url');
|
|
340
241
|
const currentFileDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
341
242
|
this.rootDirectory = path.resolve(currentFileDirectory, '../');
|
|
342
243
|
this.matterbridgeInformation.rootDirectory = this.rootDirectory;
|
|
343
|
-
// Setup the matter environment
|
|
344
244
|
this.environment.vars.set('log.level', MatterLogLevel.INFO);
|
|
345
245
|
this.environment.vars.set('log.format', MatterLogFormat.ANSI);
|
|
346
246
|
this.environment.vars.set('path.root', path.join(this.matterbridgeDirectory, this.matterStorageName));
|
|
347
247
|
this.environment.vars.set('runtime.signals', false);
|
|
348
248
|
this.environment.vars.set('runtime.exitcode', false);
|
|
349
|
-
// Register process handlers
|
|
350
249
|
this.registerProcessHandlers();
|
|
351
|
-
// Initialize nodeStorage and nodeContext
|
|
352
250
|
try {
|
|
353
251
|
this.log.debug(`Creating node storage manager: ${CYAN}${this.nodeStorageName}${db}`);
|
|
354
252
|
this.nodeStorage = new NodeStorageManager({ dir: path.join(this.matterbridgeDirectory, this.nodeStorageName), writeQueue: false, expiredInterval: undefined, logging: false });
|
|
355
253
|
this.log.debug('Creating node storage context for matterbridge');
|
|
356
254
|
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
255
|
const keys = (await this.nodeStorage?.storage.keys());
|
|
360
256
|
for (const key of keys) {
|
|
361
257
|
this.log.debug(`Checking node storage manager key: ${CYAN}${key}${db}`);
|
|
362
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
363
258
|
await this.nodeStorage?.storage.get(key);
|
|
364
259
|
}
|
|
365
260
|
const storages = await this.nodeStorage.getStorageNames();
|
|
366
261
|
for (const storage of storages) {
|
|
367
262
|
this.log.debug(`Checking storage: ${CYAN}${storage}${db}`);
|
|
368
263
|
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
264
|
const keys = (await nodeContext?.storage.keys());
|
|
372
265
|
keys.forEach(async (key) => {
|
|
373
266
|
this.log.debug(`Checking key: ${CYAN}${storage}:${key}${db}`);
|
|
374
267
|
await nodeContext?.get(key);
|
|
375
268
|
});
|
|
376
269
|
}
|
|
377
|
-
// Creating a backup of the node storage since it is not corrupted
|
|
378
270
|
this.log.debug('Creating node storage backup...');
|
|
379
271
|
await copyDirectory(path.join(this.matterbridgeDirectory, this.nodeStorageName), path.join(this.matterbridgeDirectory, this.nodeStorageName + '.backup'));
|
|
380
272
|
this.log.debug('Created node storage backup');
|
|
381
273
|
}
|
|
382
274
|
catch (error) {
|
|
383
|
-
// Restoring the backup of the node storage since it is corrupted
|
|
384
275
|
this.log.error(`Error creating node storage manager and context: ${error instanceof Error ? error.message : error}`);
|
|
385
276
|
if (hasParameter('norestore')) {
|
|
386
277
|
this.log.fatal(`The matterbridge node storage is corrupted. Parameter -norestore found: exiting...`);
|
|
@@ -395,19 +286,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
395
286
|
this.log.fatal('Fatal error creating node storage manager and context for matterbridge');
|
|
396
287
|
throw new Error('Fatal error creating node storage manager and context for matterbridge');
|
|
397
288
|
}
|
|
398
|
-
// Set the first port to use for the commissioning server (will be incremented in childbridge mode)
|
|
399
289
|
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
290
|
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
291
|
this.discriminator = getIntParameter('discriminator') ?? (await this.nodeContext.get('matterdiscriminator')) ?? PaseClient.generateRandomDiscriminator();
|
|
404
|
-
// Certificate management
|
|
405
292
|
const pairingFilePath = path.join(this.matterbridgeCertDirectory, 'pairing.json');
|
|
406
293
|
try {
|
|
407
294
|
await fs.access(pairingFilePath, fs.constants.R_OK);
|
|
408
295
|
const pairingFileContent = await fs.readFile(pairingFilePath, 'utf8');
|
|
409
296
|
const pairingFileJson = JSON.parse(pairingFileContent);
|
|
410
|
-
// Set the vendorId, vendorName, productId and productName if they are present in the pairing file
|
|
411
297
|
if (isValidNumber(pairingFileJson.vendorId))
|
|
412
298
|
this.aggregatorVendorId = VendorId(pairingFileJson.vendorId);
|
|
413
299
|
if (isValidString(pairingFileJson.vendorName, 3))
|
|
@@ -416,20 +302,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
416
302
|
this.aggregatorProductId = VendorId(pairingFileJson.productId);
|
|
417
303
|
if (isValidString(pairingFileJson.productName, 3))
|
|
418
304
|
this.aggregatorProductName = pairingFileJson.productName;
|
|
419
|
-
// Override the passcode and discriminator if they are present in the pairing file
|
|
420
305
|
if (isValidNumber(pairingFileJson.passcode) && isValidNumber(pairingFileJson.discriminator)) {
|
|
421
306
|
this.passcode = pairingFileJson.passcode;
|
|
422
307
|
this.discriminator = pairingFileJson.discriminator;
|
|
423
308
|
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
309
|
}
|
|
425
|
-
// Set the certification if it is present in the pairing file
|
|
426
310
|
if (pairingFileJson.privateKey && pairingFileJson.certificate && pairingFileJson.intermediateCertificate && pairingFileJson.declaration) {
|
|
427
311
|
const hexStringToUint8Array = (hexString) => {
|
|
428
312
|
const matches = hexString.match(/.{1,2}/g);
|
|
429
313
|
return matches ? new Uint8Array(matches.map((byte) => parseInt(byte, 16))) : new Uint8Array();
|
|
430
314
|
};
|
|
431
|
-
// const hexString = Buffer.from('Test string', 'utf-8').toString('hex');
|
|
432
|
-
// console.log(hexString, Buffer.from(hexStringToUint8Array(hexString)).toString('utf-8'));
|
|
433
315
|
this.certification = {
|
|
434
316
|
privateKey: hexStringToUint8Array(pairingFileJson.privateKey),
|
|
435
317
|
certificate: hexStringToUint8Array(pairingFileJson.certificate),
|
|
@@ -442,44 +324,41 @@ export class Matterbridge extends EventEmitter {
|
|
|
442
324
|
catch (error) {
|
|
443
325
|
this.log.debug(`Pairing file ${CYAN}${pairingFilePath}${db} not found: ${error instanceof Error ? error.message : error}`);
|
|
444
326
|
}
|
|
445
|
-
// Store the passcode, discriminator and port in the node context
|
|
446
327
|
await this.nodeContext.set('matterport', this.port);
|
|
447
328
|
await this.nodeContext.set('matterpasscode', this.passcode);
|
|
448
329
|
await this.nodeContext.set('matterdiscriminator', this.discriminator);
|
|
449
330
|
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
331
|
if (hasParameter('logger')) {
|
|
452
332
|
const level = getParameter('logger');
|
|
453
333
|
if (level === 'debug') {
|
|
454
|
-
this.log.logLevel = "debug"
|
|
334
|
+
this.log.logLevel = "debug";
|
|
455
335
|
}
|
|
456
336
|
else if (level === 'info') {
|
|
457
|
-
this.log.logLevel = "info"
|
|
337
|
+
this.log.logLevel = "info";
|
|
458
338
|
}
|
|
459
339
|
else if (level === 'notice') {
|
|
460
|
-
this.log.logLevel = "notice"
|
|
340
|
+
this.log.logLevel = "notice";
|
|
461
341
|
}
|
|
462
342
|
else if (level === 'warn') {
|
|
463
|
-
this.log.logLevel = "warn"
|
|
343
|
+
this.log.logLevel = "warn";
|
|
464
344
|
}
|
|
465
345
|
else if (level === 'error') {
|
|
466
|
-
this.log.logLevel = "error"
|
|
346
|
+
this.log.logLevel = "error";
|
|
467
347
|
}
|
|
468
348
|
else if (level === 'fatal') {
|
|
469
|
-
this.log.logLevel = "fatal"
|
|
349
|
+
this.log.logLevel = "fatal";
|
|
470
350
|
}
|
|
471
351
|
else {
|
|
472
352
|
this.log.warn(`Invalid matterbridge logger level: ${level}. Using default level "info".`);
|
|
473
|
-
this.log.logLevel = "info"
|
|
353
|
+
this.log.logLevel = "info";
|
|
474
354
|
}
|
|
475
355
|
}
|
|
476
356
|
else {
|
|
477
|
-
this.log.logLevel = await this.nodeContext.get('matterbridgeLogLevel', this.matterbridgeInformation.shellyBoard ? "notice"
|
|
357
|
+
this.log.logLevel = await this.nodeContext.get('matterbridgeLogLevel', this.matterbridgeInformation.shellyBoard ? "notice" : "info");
|
|
478
358
|
}
|
|
479
359
|
this.frontend.logLevel = this.log.logLevel;
|
|
480
360
|
MatterbridgeEndpoint.logLevel = this.log.logLevel;
|
|
481
361
|
this.matterbridgeInformation.loggerLevel = this.log.logLevel;
|
|
482
|
-
// Create the file logger for matterbridge (context: matterbridgeFileLog)
|
|
483
362
|
if (hasParameter('filelogger') || (await this.nodeContext.get('matterbridgeFileLog', false))) {
|
|
484
363
|
AnsiLogger.setGlobalLogfile(path.join(this.matterbridgeDirectory, this.matterbrideLoggerFile), this.log.logLevel, true);
|
|
485
364
|
this.matterbridgeInformation.fileLogger = true;
|
|
@@ -488,7 +367,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
488
367
|
this.log.debug(`Matterbridge logLevel: ${this.log.logLevel} fileLoger: ${this.matterbridgeInformation.fileLogger}.`);
|
|
489
368
|
if (this.profile !== undefined)
|
|
490
369
|
this.log.debug(`Matterbridge profile: ${this.profile}.`);
|
|
491
|
-
// Set matter.js logger level, format and logger (context: matterLogLevel)
|
|
492
370
|
if (hasParameter('matterlogger')) {
|
|
493
371
|
const level = getParameter('matterlogger');
|
|
494
372
|
if (level === 'debug') {
|
|
@@ -520,7 +398,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
520
398
|
Logger.format = MatterLogFormat.ANSI;
|
|
521
399
|
Logger.setLogger('default', this.createMatterLogger());
|
|
522
400
|
this.matterbridgeInformation.matterLoggerLevel = Logger.defaultLogLevel;
|
|
523
|
-
// Create the file logger for matter.js (context: matterFileLog)
|
|
524
401
|
if (hasParameter('matterfilelogger') || (await this.nodeContext.get('matterFileLog', false))) {
|
|
525
402
|
this.matterbridgeInformation.matterFileLogger = true;
|
|
526
403
|
Logger.addLogger('matterfilelogger', await this.createMatterFileLogger(path.join(this.matterbridgeDirectory, this.matterLoggerFile), true), {
|
|
@@ -529,7 +406,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
529
406
|
});
|
|
530
407
|
}
|
|
531
408
|
this.log.debug(`Matter logLevel: ${Logger.defaultLogLevel} fileLoger: ${this.matterbridgeInformation.matterFileLogger}.`);
|
|
532
|
-
// Log network interfaces
|
|
533
409
|
const networkInterfaces = os.networkInterfaces();
|
|
534
410
|
const availableAddresses = Object.entries(networkInterfaces);
|
|
535
411
|
const availableInterfaces = Object.keys(networkInterfaces);
|
|
@@ -541,7 +417,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
541
417
|
});
|
|
542
418
|
}
|
|
543
419
|
}
|
|
544
|
-
// Set the interface to use for matter server node mdnsInterface
|
|
545
420
|
if (hasParameter('mdnsinterface')) {
|
|
546
421
|
this.mdnsInterface = getParameter('mdnsinterface');
|
|
547
422
|
}
|
|
@@ -550,7 +425,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
550
425
|
if (this.mdnsInterface === '')
|
|
551
426
|
this.mdnsInterface = undefined;
|
|
552
427
|
}
|
|
553
|
-
// Validate mdnsInterface
|
|
554
428
|
if (this.mdnsInterface) {
|
|
555
429
|
if (!availableInterfaces.includes(this.mdnsInterface)) {
|
|
556
430
|
this.log.error(`Invalid mdnsInterface: ${this.mdnsInterface}. Available interfaces are: ${availableInterfaces.join(', ')}. Using all available interfaces.`);
|
|
@@ -563,7 +437,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
563
437
|
}
|
|
564
438
|
if (this.mdnsInterface)
|
|
565
439
|
this.environment.vars.set('mdns.networkInterface', this.mdnsInterface);
|
|
566
|
-
// Set the listeningAddressIpv4 for the matter commissioning server
|
|
567
440
|
if (hasParameter('ipv4address')) {
|
|
568
441
|
this.ipv4address = getParameter('ipv4address');
|
|
569
442
|
}
|
|
@@ -572,7 +445,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
572
445
|
if (this.ipv4address === '')
|
|
573
446
|
this.ipv4address = undefined;
|
|
574
447
|
}
|
|
575
|
-
// Validate ipv4address
|
|
576
448
|
if (this.ipv4address) {
|
|
577
449
|
let isValid = false;
|
|
578
450
|
for (const [ifaceName, ifaces] of availableAddresses) {
|
|
@@ -588,7 +460,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
588
460
|
await this.nodeContext.remove('matteripv4address');
|
|
589
461
|
}
|
|
590
462
|
}
|
|
591
|
-
// Set the listeningAddressIpv6 for the matter commissioning server
|
|
592
463
|
if (hasParameter('ipv6address')) {
|
|
593
464
|
this.ipv6address = getParameter('ipv6address');
|
|
594
465
|
}
|
|
@@ -597,7 +468,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
597
468
|
if (this.ipv6address === '')
|
|
598
469
|
this.ipv6address = undefined;
|
|
599
470
|
}
|
|
600
|
-
// Validate ipv6address
|
|
601
471
|
if (this.ipv6address) {
|
|
602
472
|
let isValid = false;
|
|
603
473
|
for (const [ifaceName, ifaces] of availableAddresses) {
|
|
@@ -618,7 +488,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
618
488
|
await this.nodeContext.remove('matteripv6address');
|
|
619
489
|
}
|
|
620
490
|
}
|
|
621
|
-
// Initialize the virtual mode
|
|
622
491
|
if (hasParameter('novirtual')) {
|
|
623
492
|
this.matterbridgeInformation.virtualMode = 'disabled';
|
|
624
493
|
await this.nodeContext.set('virtualmode', 'disabled');
|
|
@@ -627,22 +496,17 @@ export class Matterbridge extends EventEmitter {
|
|
|
627
496
|
this.matterbridgeInformation.virtualMode = (await this.nodeContext.get('virtualmode', 'outlet'));
|
|
628
497
|
}
|
|
629
498
|
this.log.debug(`Virtual mode ${this.matterbridgeInformation.virtualMode}.`);
|
|
630
|
-
// Initialize PluginManager
|
|
631
499
|
this.plugins = new PluginManager(this);
|
|
632
500
|
await this.plugins.loadFromStorage();
|
|
633
501
|
this.plugins.logLevel = this.log.logLevel;
|
|
634
|
-
// Initialize DeviceManager
|
|
635
502
|
this.devices = new DeviceManager(this, this.nodeContext);
|
|
636
503
|
this.devices.logLevel = this.log.logLevel;
|
|
637
|
-
// Get the plugins from node storage and create the plugins node storage contexts
|
|
638
504
|
for (const plugin of this.plugins) {
|
|
639
505
|
const packageJson = await this.plugins.parse(plugin);
|
|
640
506
|
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
507
|
this.log.info(`Error parsing plugin ${plg}${plugin.name}${nf}. Trying to reinstall it from npm.`);
|
|
644
508
|
try {
|
|
645
|
-
await
|
|
509
|
+
await spawn.spawnCommand(this, 'npm', ['install', '-g', plugin.name, '--omit=dev', '--verbose']);
|
|
646
510
|
this.log.info(`Plugin ${plg}${plugin.name}${nf} reinstalled.`);
|
|
647
511
|
plugin.error = false;
|
|
648
512
|
}
|
|
@@ -661,7 +525,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
661
525
|
await plugin.nodeContext.set('description', plugin.description);
|
|
662
526
|
await plugin.nodeContext.set('author', plugin.author);
|
|
663
527
|
}
|
|
664
|
-
// Log system info and create .matterbridge directory
|
|
665
528
|
await this.logNodeAndSystemInfo();
|
|
666
529
|
this.log.notice(`Matterbridge version ${this.matterbridgeVersion} ` +
|
|
667
530
|
`${hasParameter('bridge') || (!hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'bridge') ? 'mode bridge ' : ''}` +
|
|
@@ -669,7 +532,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
669
532
|
`${hasParameter('controller') ? 'mode controller ' : ''}` +
|
|
670
533
|
`${this.restartMode !== '' ? 'restart mode ' + this.restartMode + ' ' : ''}` +
|
|
671
534
|
`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
535
|
const minNodeVersion = 18;
|
|
674
536
|
const nodeVersion = process.versions.node;
|
|
675
537
|
const versionMajor = parseInt(nodeVersion.split('.')[0]);
|
|
@@ -677,17 +539,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
677
539
|
this.log.error(`Node version ${versionMajor} is not supported. Please upgrade to ${minNodeVersion} or above.`);
|
|
678
540
|
throw new Error(`Node version ${versionMajor} is not supported. Please upgrade to ${minNodeVersion} or above.`);
|
|
679
541
|
}
|
|
680
|
-
// Parse command line
|
|
681
542
|
await this.parseCommandLine();
|
|
682
|
-
// Emit the initialize_completed event
|
|
683
543
|
this.emit('initialize_completed');
|
|
684
544
|
this.initialized = true;
|
|
685
545
|
}
|
|
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
546
|
async parseCommandLine() {
|
|
692
547
|
if (hasParameter('help')) {
|
|
693
548
|
this.log.info(`\nUsage: matterbridge [options]\n
|
|
@@ -809,7 +664,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
809
664
|
this.shutdown = true;
|
|
810
665
|
return;
|
|
811
666
|
}
|
|
812
|
-
// Start the matter storage and create the matterbridge context
|
|
813
667
|
try {
|
|
814
668
|
await this.startMatterStorage();
|
|
815
669
|
}
|
|
@@ -817,14 +671,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
817
671
|
this.log.fatal(`Fatal error creating matter storage: ${error instanceof Error ? error.message : error}`);
|
|
818
672
|
throw new Error(`Fatal error creating matter storage: ${error instanceof Error ? error.message : error}`);
|
|
819
673
|
}
|
|
820
|
-
// Clear the matterbridge context if the reset parameter is set
|
|
821
674
|
if (hasParameter('reset') && getParameter('reset') === undefined) {
|
|
822
675
|
this.initialized = true;
|
|
823
676
|
await this.shutdownProcessAndReset();
|
|
824
677
|
this.shutdown = true;
|
|
825
678
|
return;
|
|
826
679
|
}
|
|
827
|
-
// Clear matterbridge plugin context if the reset parameter is set
|
|
828
680
|
if (hasParameter('reset') && getParameter('reset') !== undefined) {
|
|
829
681
|
this.log.debug(`Reset plugin ${getParameter('reset')}`);
|
|
830
682
|
const plugin = this.plugins.get(getParameter('reset'));
|
|
@@ -849,37 +701,30 @@ export class Matterbridge extends EventEmitter {
|
|
|
849
701
|
this.shutdown = true;
|
|
850
702
|
return;
|
|
851
703
|
}
|
|
852
|
-
// Initialize frontend
|
|
853
704
|
if (getIntParameter('frontend') !== 0 || getIntParameter('frontend') === undefined)
|
|
854
705
|
await this.frontend.start(getIntParameter('frontend'));
|
|
855
|
-
// Check in 30 seconds the latest and dev versions of matterbridge and the plugins
|
|
856
706
|
this.checkUpdateTimeout = setTimeout(async () => {
|
|
857
707
|
const { checkUpdates } = await import('./update.js');
|
|
858
708
|
checkUpdates(this);
|
|
859
709
|
}, 30 * 1000).unref();
|
|
860
|
-
// Check each 12 hours the latest and dev versions of matterbridge and the plugins
|
|
861
710
|
this.checkUpdateInterval = setInterval(async () => {
|
|
862
711
|
const { checkUpdates } = await import('./update.js');
|
|
863
712
|
checkUpdates(this);
|
|
864
713
|
}, 12 * 60 * 60 * 1000).unref();
|
|
865
|
-
// Start the matterbridge in mode test
|
|
866
714
|
if (hasParameter('test')) {
|
|
867
715
|
this.bridgeMode = 'bridge';
|
|
868
716
|
MatterbridgeEndpoint.bridgeMode = 'bridge';
|
|
869
717
|
return;
|
|
870
718
|
}
|
|
871
|
-
// Start the matterbridge in mode controller
|
|
872
719
|
if (hasParameter('controller')) {
|
|
873
720
|
this.bridgeMode = 'controller';
|
|
874
721
|
await this.startController();
|
|
875
722
|
return;
|
|
876
723
|
}
|
|
877
|
-
// Check if the bridge mode is set and start matterbridge in bridge mode if not set
|
|
878
724
|
if (!hasParameter('bridge') && !hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === '') {
|
|
879
725
|
this.log.info('Setting default matterbridge start mode to bridge');
|
|
880
726
|
await this.nodeContext?.set('bridgeMode', 'bridge');
|
|
881
727
|
}
|
|
882
|
-
// Start matterbridge in bridge mode
|
|
883
728
|
if (hasParameter('bridge') || (!hasParameter('childbridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'bridge')) {
|
|
884
729
|
this.bridgeMode = 'bridge';
|
|
885
730
|
MatterbridgeEndpoint.bridgeMode = 'bridge';
|
|
@@ -887,7 +732,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
887
732
|
await this.startBridge();
|
|
888
733
|
return;
|
|
889
734
|
}
|
|
890
|
-
// Start matterbridge in childbridge mode
|
|
891
735
|
if (hasParameter('childbridge') || (!hasParameter('bridge') && (await this.nodeContext?.get('bridgeMode', '')) === 'childbridge')) {
|
|
892
736
|
this.bridgeMode = 'childbridge';
|
|
893
737
|
MatterbridgeEndpoint.bridgeMode = 'childbridge';
|
|
@@ -896,20 +740,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
896
740
|
return;
|
|
897
741
|
}
|
|
898
742
|
}
|
|
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
743
|
async startPlugins() {
|
|
908
|
-
// Check, load and start the plugins
|
|
909
744
|
for (const plugin of this.plugins) {
|
|
910
745
|
plugin.configJson = await this.plugins.loadConfig(plugin);
|
|
911
746
|
plugin.schemaJson = await this.plugins.loadSchema(plugin);
|
|
912
|
-
// Check if the plugin is available
|
|
913
747
|
if (!(await this.plugins.resolve(plugin.path))) {
|
|
914
748
|
this.log.error(`Plugin ${plg}${plugin.name}${er} not found or not validated. Disabling it.`);
|
|
915
749
|
plugin.enabled = false;
|
|
@@ -929,14 +763,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
929
763
|
plugin.addedDevices = undefined;
|
|
930
764
|
plugin.qrPairingCode = undefined;
|
|
931
765
|
plugin.manualPairingCode = undefined;
|
|
932
|
-
this.plugins.load(plugin, true, 'Matterbridge is starting');
|
|
766
|
+
this.plugins.load(plugin, true, 'Matterbridge is starting');
|
|
933
767
|
}
|
|
934
768
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
935
769
|
}
|
|
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
770
|
registerProcessHandlers() {
|
|
941
771
|
this.log.debug(`Registering uncaughtException and unhandledRejection handlers...`);
|
|
942
772
|
process.removeAllListeners('uncaughtException');
|
|
@@ -963,9 +793,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
963
793
|
};
|
|
964
794
|
process.on('SIGTERM', this.sigtermHandler);
|
|
965
795
|
}
|
|
966
|
-
/**
|
|
967
|
-
* Deregisters the process uncaughtException, unhandledRejection, SIGINT and SIGTERM signal handlers.
|
|
968
|
-
*/
|
|
969
796
|
deregisterProcessHandlers() {
|
|
970
797
|
this.log.debug(`Deregistering uncaughtException and unhandledRejection handlers...`);
|
|
971
798
|
if (this.exceptionHandler)
|
|
@@ -982,17 +809,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
982
809
|
process.off('SIGTERM', this.sigtermHandler);
|
|
983
810
|
this.sigtermHandler = undefined;
|
|
984
811
|
}
|
|
985
|
-
/**
|
|
986
|
-
* Logs the node and system information.
|
|
987
|
-
*/
|
|
988
812
|
async logNodeAndSystemInfo() {
|
|
989
|
-
// IP address information
|
|
990
813
|
const networkInterfaces = os.networkInterfaces();
|
|
991
814
|
this.systemInformation.interfaceName = '';
|
|
992
815
|
this.systemInformation.ipv4Address = '';
|
|
993
816
|
this.systemInformation.ipv6Address = '';
|
|
994
817
|
for (const [interfaceName, interfaceDetails] of Object.entries(networkInterfaces)) {
|
|
995
|
-
// this.log.debug(`Checking interface: '${interfaceName}' for '${this.mdnsInterface}'`);
|
|
996
818
|
if (this.mdnsInterface && interfaceName !== this.mdnsInterface)
|
|
997
819
|
continue;
|
|
998
820
|
if (!interfaceDetails) {
|
|
@@ -1018,22 +840,19 @@ export class Matterbridge extends EventEmitter {
|
|
|
1018
840
|
break;
|
|
1019
841
|
}
|
|
1020
842
|
}
|
|
1021
|
-
// Node information
|
|
1022
843
|
this.systemInformation.nodeVersion = process.versions.node;
|
|
1023
844
|
const versionMajor = parseInt(this.systemInformation.nodeVersion.split('.')[0]);
|
|
1024
845
|
const versionMinor = parseInt(this.systemInformation.nodeVersion.split('.')[1]);
|
|
1025
846
|
const versionPatch = parseInt(this.systemInformation.nodeVersion.split('.')[2]);
|
|
1026
|
-
// Host system information
|
|
1027
847
|
this.systemInformation.hostname = os.hostname();
|
|
1028
848
|
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
|
|
849
|
+
this.systemInformation.osType = os.type();
|
|
850
|
+
this.systemInformation.osRelease = os.release();
|
|
851
|
+
this.systemInformation.osPlatform = os.platform();
|
|
852
|
+
this.systemInformation.osArch = os.arch();
|
|
853
|
+
this.systemInformation.totalMemory = (os.totalmem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
854
|
+
this.systemInformation.freeMemory = (os.freemem() / 1024 / 1024 / 1024).toFixed(2) + ' GB';
|
|
855
|
+
this.systemInformation.systemUptime = (os.uptime() / 60 / 60).toFixed(2) + ' hours';
|
|
1037
856
|
this.log.debug('Host System Information:');
|
|
1038
857
|
this.log.debug(`- Hostname: ${this.systemInformation.hostname}`);
|
|
1039
858
|
this.log.debug(`- User: ${this.systemInformation.user}`);
|
|
@@ -1049,17 +868,14 @@ export class Matterbridge extends EventEmitter {
|
|
|
1049
868
|
this.log.debug(`- Total Memory: ${this.systemInformation.totalMemory}`);
|
|
1050
869
|
this.log.debug(`- Free Memory: ${this.systemInformation.freeMemory}`);
|
|
1051
870
|
this.log.debug(`- System Uptime: ${this.systemInformation.systemUptime}`);
|
|
1052
|
-
// Log directories
|
|
1053
871
|
this.log.debug(`Root Directory: ${this.rootDirectory}`);
|
|
1054
872
|
this.log.debug(`Home Directory: ${this.homeDirectory}`);
|
|
1055
873
|
this.log.debug(`Matterbridge Directory: ${this.matterbridgeDirectory}`);
|
|
1056
874
|
this.log.debug(`Matterbridge Plugin Directory: ${this.matterbridgePluginDirectory}`);
|
|
1057
875
|
this.log.debug(`Matterbridge Matter Certificate Directory: ${this.matterbridgeCertDirectory}`);
|
|
1058
|
-
// Global node_modules directory
|
|
1059
876
|
if (this.nodeContext)
|
|
1060
877
|
this.globalModulesDirectory = this.matterbridgeInformation.globalModulesDirectory = await this.nodeContext.get('globalModulesDirectory', '');
|
|
1061
878
|
if (this.globalModulesDirectory === '') {
|
|
1062
|
-
// First run of Matterbridge so the node storage is empty
|
|
1063
879
|
try {
|
|
1064
880
|
this.execRunningCount++;
|
|
1065
881
|
this.matterbridgeInformation.globalModulesDirectory = this.globalModulesDirectory = await getGlobalNodeModules();
|
|
@@ -1073,84 +889,53 @@ export class Matterbridge extends EventEmitter {
|
|
|
1073
889
|
}
|
|
1074
890
|
else
|
|
1075
891
|
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
892
|
const packageJson = JSON.parse(await fs.readFile(path.join(this.rootDirectory, 'package.json'), 'utf-8'));
|
|
1091
893
|
this.matterbridgeVersion = this.matterbridgeLatestVersion = this.matterbridgeDevVersion = packageJson.version;
|
|
1092
894
|
this.matterbridgeInformation.matterbridgeVersion = this.matterbridgeInformation.matterbridgeLatestVersion = this.matterbridgeInformation.matterbridgeDevVersion = packageJson.version;
|
|
1093
895
|
this.log.debug(`Matterbridge Version: ${this.matterbridgeVersion}`);
|
|
1094
|
-
// Matterbridge latest version (will be set in the checkUpdate function)
|
|
1095
896
|
if (this.nodeContext)
|
|
1096
897
|
this.matterbridgeLatestVersion = this.matterbridgeInformation.matterbridgeLatestVersion = await this.nodeContext.get('matterbridgeLatestVersion', this.matterbridgeVersion);
|
|
1097
898
|
this.log.debug(`Matterbridge Latest Version: ${this.matterbridgeLatestVersion}`);
|
|
1098
|
-
// Matterbridge dev version (will be set in the checkUpdate function)
|
|
1099
899
|
if (this.nodeContext)
|
|
1100
900
|
this.matterbridgeDevVersion = this.matterbridgeInformation.matterbridgeDevVersion = await this.nodeContext.get('matterbridgeDevVersion', this.matterbridgeVersion);
|
|
1101
901
|
this.log.debug(`Matterbridge Dev Version: ${this.matterbridgeDevVersion}`);
|
|
1102
|
-
// Current working directory
|
|
1103
902
|
const currentDir = process.cwd();
|
|
1104
903
|
this.log.debug(`Current Working Directory: ${currentDir}`);
|
|
1105
|
-
// Command line arguments (excluding 'node' and the script name)
|
|
1106
904
|
const cmdArgs = process.argv.slice(2).join(' ');
|
|
1107
905
|
this.log.debug(`Command Line Arguments: ${cmdArgs}`);
|
|
1108
906
|
}
|
|
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
907
|
createMatterLogger() {
|
|
1115
|
-
const matterLogger = new AnsiLogger({ logName: 'Matter', logTimestampFormat: 4
|
|
908
|
+
const matterLogger = new AnsiLogger({ logName: 'Matter', logTimestampFormat: 4, logLevel: "debug" });
|
|
1116
909
|
return (level, formattedLog) => {
|
|
1117
910
|
const logger = formattedLog.slice(44, 44 + 20).trim();
|
|
1118
911
|
const message = formattedLog.slice(65);
|
|
1119
912
|
matterLogger.logName = logger;
|
|
1120
913
|
switch (level) {
|
|
1121
914
|
case MatterLogLevel.DEBUG:
|
|
1122
|
-
matterLogger.log("debug"
|
|
915
|
+
matterLogger.log("debug", message);
|
|
1123
916
|
break;
|
|
1124
917
|
case MatterLogLevel.INFO:
|
|
1125
|
-
matterLogger.log("info"
|
|
918
|
+
matterLogger.log("info", message);
|
|
1126
919
|
break;
|
|
1127
920
|
case MatterLogLevel.NOTICE:
|
|
1128
|
-
matterLogger.log("notice"
|
|
921
|
+
matterLogger.log("notice", message);
|
|
1129
922
|
break;
|
|
1130
923
|
case MatterLogLevel.WARN:
|
|
1131
|
-
matterLogger.log("warn"
|
|
924
|
+
matterLogger.log("warn", message);
|
|
1132
925
|
break;
|
|
1133
926
|
case MatterLogLevel.ERROR:
|
|
1134
|
-
matterLogger.log("error"
|
|
927
|
+
matterLogger.log("error", message);
|
|
1135
928
|
break;
|
|
1136
929
|
case MatterLogLevel.FATAL:
|
|
1137
|
-
matterLogger.log("fatal"
|
|
930
|
+
matterLogger.log("fatal", message);
|
|
1138
931
|
break;
|
|
1139
932
|
default:
|
|
1140
|
-
matterLogger.log("debug"
|
|
933
|
+
matterLogger.log("debug", message);
|
|
1141
934
|
break;
|
|
1142
935
|
}
|
|
1143
936
|
};
|
|
1144
937
|
}
|
|
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
938
|
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
939
|
let fileSize = 0;
|
|
1155
940
|
if (unlink) {
|
|
1156
941
|
try {
|
|
@@ -1199,25 +984,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
1199
984
|
}
|
|
1200
985
|
};
|
|
1201
986
|
}
|
|
1202
|
-
/**
|
|
1203
|
-
* Restarts the process by exiting the current instance and loading a new instance.
|
|
1204
|
-
*/
|
|
1205
987
|
async restartProcess() {
|
|
1206
988
|
await this.cleanup('restarting...', true);
|
|
1207
989
|
}
|
|
1208
|
-
/**
|
|
1209
|
-
* Shut down the process by exiting the current process.
|
|
1210
|
-
*/
|
|
1211
990
|
async shutdownProcess() {
|
|
1212
991
|
await this.cleanup('shutting down...', false);
|
|
1213
992
|
}
|
|
1214
|
-
/**
|
|
1215
|
-
* Update matterbridge and and shut down the process.
|
|
1216
|
-
*/
|
|
1217
993
|
async updateProcess() {
|
|
1218
994
|
this.log.info('Updating matterbridge...');
|
|
1219
995
|
try {
|
|
1220
|
-
await
|
|
996
|
+
await spawn.spawnCommand(this, 'npm', ['install', '-g', 'matterbridge', '--omit=dev', '--verbose']);
|
|
1221
997
|
this.log.info('Matterbridge has been updated. Full restart required.');
|
|
1222
998
|
}
|
|
1223
999
|
catch (error) {
|
|
@@ -1226,73 +1002,52 @@ export class Matterbridge extends EventEmitter {
|
|
|
1226
1002
|
this.frontend.wssSendRestartRequired();
|
|
1227
1003
|
await this.cleanup('updating...', false);
|
|
1228
1004
|
}
|
|
1229
|
-
/**
|
|
1230
|
-
* Unregister all devices and shut down the process.
|
|
1231
|
-
*/
|
|
1232
1005
|
async unregisterAndShutdownProcess() {
|
|
1233
1006
|
this.log.info('Unregistering all devices and shutting down...');
|
|
1234
1007
|
for (const plugin of this.plugins) {
|
|
1235
1008
|
await this.removeAllBridgedEndpoints(plugin.name, 250);
|
|
1236
1009
|
}
|
|
1237
1010
|
this.log.debug('Waiting for the MessageExchange to finish...');
|
|
1238
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1011
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1239
1012
|
this.log.debug('Cleaning up and shutting down...');
|
|
1240
1013
|
await this.cleanup('unregistered all devices and shutting down...', false);
|
|
1241
1014
|
}
|
|
1242
|
-
/**
|
|
1243
|
-
* Reset commissioning and shut down the process.
|
|
1244
|
-
*/
|
|
1245
1015
|
async shutdownProcessAndReset() {
|
|
1246
1016
|
await this.cleanup('shutting down with reset...', false);
|
|
1247
1017
|
}
|
|
1248
|
-
/**
|
|
1249
|
-
* Factory reset and shut down the process.
|
|
1250
|
-
*/
|
|
1251
1018
|
async shutdownProcessAndFactoryReset() {
|
|
1252
1019
|
await this.cleanup('shutting down with factory reset...', false);
|
|
1253
1020
|
}
|
|
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
1021
|
async cleanup(message, restart = false) {
|
|
1261
1022
|
if (this.initialized && !this.hasCleanupStarted) {
|
|
1262
1023
|
this.emit('cleanup_started');
|
|
1263
1024
|
this.hasCleanupStarted = true;
|
|
1264
1025
|
this.log.info(message);
|
|
1265
|
-
// Clear the start matter interval
|
|
1266
1026
|
if (this.startMatterInterval) {
|
|
1267
1027
|
clearInterval(this.startMatterInterval);
|
|
1268
1028
|
this.startMatterInterval = undefined;
|
|
1269
1029
|
this.log.debug('Start matter interval cleared');
|
|
1270
1030
|
}
|
|
1271
|
-
// Clear the check update timeout
|
|
1272
1031
|
if (this.checkUpdateTimeout) {
|
|
1273
1032
|
clearInterval(this.checkUpdateTimeout);
|
|
1274
1033
|
this.checkUpdateTimeout = undefined;
|
|
1275
1034
|
this.log.debug('Check update timeout cleared');
|
|
1276
1035
|
}
|
|
1277
|
-
// Clear the check update interval
|
|
1278
1036
|
if (this.checkUpdateInterval) {
|
|
1279
1037
|
clearInterval(this.checkUpdateInterval);
|
|
1280
1038
|
this.checkUpdateInterval = undefined;
|
|
1281
1039
|
this.log.debug('Check update interval cleared');
|
|
1282
1040
|
}
|
|
1283
|
-
// Clear the configure timeout
|
|
1284
1041
|
if (this.configureTimeout) {
|
|
1285
1042
|
clearTimeout(this.configureTimeout);
|
|
1286
1043
|
this.configureTimeout = undefined;
|
|
1287
1044
|
this.log.debug('Matterbridge configure timeout cleared');
|
|
1288
1045
|
}
|
|
1289
|
-
// Clear the reachability timeout
|
|
1290
1046
|
if (this.reachabilityTimeout) {
|
|
1291
1047
|
clearTimeout(this.reachabilityTimeout);
|
|
1292
1048
|
this.reachabilityTimeout = undefined;
|
|
1293
1049
|
this.log.debug('Matterbridge reachability timeout cleared');
|
|
1294
1050
|
}
|
|
1295
|
-
// Calling the shutdown method of each plugin and clear the plugins reachability timeout
|
|
1296
1051
|
for (const plugin of this.plugins) {
|
|
1297
1052
|
if (!plugin.enabled || plugin.error)
|
|
1298
1053
|
continue;
|
|
@@ -1303,10 +1058,9 @@ export class Matterbridge extends EventEmitter {
|
|
|
1303
1058
|
this.log.debug(`Plugin ${plg}${plugin.name}${db} reachability timeout cleared`);
|
|
1304
1059
|
}
|
|
1305
1060
|
}
|
|
1306
|
-
// Stop matter server nodes
|
|
1307
1061
|
this.log.notice(`Stopping matter server nodes in ${this.bridgeMode} mode...`);
|
|
1308
1062
|
this.log.debug('Waiting for the MessageExchange to finish...');
|
|
1309
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1063
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
1310
1064
|
if (this.bridgeMode === 'bridge') {
|
|
1311
1065
|
if (this.serverNode) {
|
|
1312
1066
|
await this.stopServerNode(this.serverNode);
|
|
@@ -1322,7 +1076,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1322
1076
|
}
|
|
1323
1077
|
}
|
|
1324
1078
|
this.log.notice('Stopped matter server nodes');
|
|
1325
|
-
// Matter commisioning reset
|
|
1326
1079
|
if (message === 'shutting down with reset...') {
|
|
1327
1080
|
this.log.info('Resetting Matterbridge commissioning information...');
|
|
1328
1081
|
await this.matterStorageManager?.createContext('events')?.clearAll();
|
|
@@ -1332,36 +1085,18 @@ export class Matterbridge extends EventEmitter {
|
|
|
1332
1085
|
await this.matterbridgeContext?.clearAll();
|
|
1333
1086
|
this.log.info('Matter storage reset done! Remove the bridge from the controller.');
|
|
1334
1087
|
}
|
|
1335
|
-
// Stop matter storage
|
|
1336
1088
|
await this.stopMatterStorage();
|
|
1337
|
-
// Stop the frontend
|
|
1338
1089
|
await this.frontend.stop();
|
|
1339
|
-
// Remove the matterfilelogger
|
|
1340
1090
|
try {
|
|
1341
1091
|
Logger.removeLogger('matterfilelogger');
|
|
1342
1092
|
}
|
|
1343
1093
|
catch (error) {
|
|
1344
1094
|
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
1095
|
}
|
|
1346
|
-
// Close the matterbridge node storage and context
|
|
1347
1096
|
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
1097
|
this.log.debug(`Closing node storage context for ${plg}Matterbridge${db}...`);
|
|
1362
1098
|
await this.nodeContext.close();
|
|
1363
1099
|
this.nodeContext = undefined;
|
|
1364
|
-
// Clear nodeContext for each plugin (they just need 1000ms to write the data to disk)
|
|
1365
1100
|
for (const plugin of this.plugins) {
|
|
1366
1101
|
if (plugin.nodeContext) {
|
|
1367
1102
|
this.log.debug(`Closing node storage context for plugin ${plg}${plugin.name}${db}...`);
|
|
@@ -1378,10 +1113,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
1378
1113
|
}
|
|
1379
1114
|
this.plugins.clear();
|
|
1380
1115
|
this.devices.clear();
|
|
1381
|
-
// Factory reset
|
|
1382
1116
|
if (message === 'shutting down with factory reset...') {
|
|
1383
1117
|
try {
|
|
1384
|
-
// Delete matter storage directory with its subdirectories and backup
|
|
1385
1118
|
const dir = path.join(this.matterbridgeDirectory, this.matterStorageName);
|
|
1386
1119
|
this.log.info(`Removing matter storage directory: ${dir}`);
|
|
1387
1120
|
await fs.rm(dir, { recursive: true });
|
|
@@ -1395,7 +1128,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1395
1128
|
}
|
|
1396
1129
|
}
|
|
1397
1130
|
try {
|
|
1398
|
-
// Delete matterbridge storage directory with its subdirectories and backup
|
|
1399
1131
|
const dir = path.join(this.matterbridgeDirectory, this.nodeStorageName);
|
|
1400
1132
|
this.log.info(`Removing matterbridge storage directory: ${dir}`);
|
|
1401
1133
|
await fs.rm(dir, { recursive: true });
|
|
@@ -1410,13 +1142,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
1410
1142
|
}
|
|
1411
1143
|
this.log.info('Factory reset done! Remove all paired fabrics from the controllers.');
|
|
1412
1144
|
}
|
|
1413
|
-
// Deregisters the process handlers
|
|
1414
1145
|
this.deregisterProcessHandlers();
|
|
1415
1146
|
if (restart) {
|
|
1416
1147
|
if (message === 'updating...') {
|
|
1417
1148
|
this.log.info('Cleanup completed. Updating...');
|
|
1418
1149
|
Matterbridge.instance = undefined;
|
|
1419
|
-
this.emit('update');
|
|
1150
|
+
this.emit('update');
|
|
1420
1151
|
}
|
|
1421
1152
|
else if (message === 'restarting...') {
|
|
1422
1153
|
this.log.info('Cleanup completed. Restarting...');
|
|
@@ -1437,14 +1168,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1437
1168
|
this.log.debug('Cleanup already started...');
|
|
1438
1169
|
}
|
|
1439
1170
|
}
|
|
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
1171
|
async createAccessoryPlugin(plugin, device, start = false) {
|
|
1449
1172
|
if (!plugin.locked && device.deviceName && device.vendorId && device.productId && device.vendorName && device.productName) {
|
|
1450
1173
|
plugin.locked = true;
|
|
@@ -1458,13 +1181,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1458
1181
|
await this.startServerNode(plugin.serverNode);
|
|
1459
1182
|
}
|
|
1460
1183
|
}
|
|
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
1184
|
async createDynamicPlugin(plugin, start = false) {
|
|
1469
1185
|
if (!plugin.locked) {
|
|
1470
1186
|
plugin.locked = true;
|
|
@@ -1477,13 +1193,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1477
1193
|
await this.startServerNode(plugin.serverNode);
|
|
1478
1194
|
}
|
|
1479
1195
|
}
|
|
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
1196
|
async startBridge() {
|
|
1486
|
-
// Plugins are configured by a timer when matter server is started and plugin.configured is set to true
|
|
1487
1197
|
if (!this.matterStorageManager)
|
|
1488
1198
|
throw new Error('No storage manager initialized');
|
|
1489
1199
|
if (!this.matterbridgeContext)
|
|
@@ -1522,9 +1232,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1522
1232
|
clearInterval(this.startMatterInterval);
|
|
1523
1233
|
this.startMatterInterval = undefined;
|
|
1524
1234
|
this.log.debug('Cleared startMatterInterval interval for Matterbridge');
|
|
1525
|
-
// Start the Matter server node
|
|
1526
1235
|
this.startServerNode(this.serverNode);
|
|
1527
|
-
// Configure the plugins
|
|
1528
1236
|
this.configureTimeout = setTimeout(async () => {
|
|
1529
1237
|
for (const plugin of this.plugins) {
|
|
1530
1238
|
if (!plugin.enabled || !plugin.loaded || !plugin.started || plugin.error)
|
|
@@ -1542,7 +1250,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1542
1250
|
}
|
|
1543
1251
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
1544
1252
|
}, 30 * 1000);
|
|
1545
|
-
// Setting reachability to true
|
|
1546
1253
|
this.reachabilityTimeout = setTimeout(() => {
|
|
1547
1254
|
this.log.info(`Setting reachability to true for ${plg}Matterbridge${db}`);
|
|
1548
1255
|
if (this.aggregatorNode)
|
|
@@ -1551,11 +1258,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1551
1258
|
}, 60 * 1000);
|
|
1552
1259
|
}, 1000);
|
|
1553
1260
|
}
|
|
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
1261
|
async startChildbridge() {
|
|
1560
1262
|
if (!this.matterStorageManager)
|
|
1561
1263
|
throw new Error('No storage manager initialized');
|
|
@@ -1593,7 +1295,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1593
1295
|
clearInterval(this.startMatterInterval);
|
|
1594
1296
|
this.startMatterInterval = undefined;
|
|
1595
1297
|
this.log.debug('Cleared startMatterInterval interval in childbridge mode');
|
|
1596
|
-
// Configure the plugins
|
|
1597
1298
|
this.configureTimeout = setTimeout(async () => {
|
|
1598
1299
|
for (const plugin of this.plugins) {
|
|
1599
1300
|
if (!plugin.enabled || !plugin.loaded || !plugin.started || plugin.error)
|
|
@@ -1630,9 +1331,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1630
1331
|
this.log.error(`Node storage context not found for plugin ${plg}${plugin.name}${er}`);
|
|
1631
1332
|
continue;
|
|
1632
1333
|
}
|
|
1633
|
-
// Start the Matter server node
|
|
1634
1334
|
this.startServerNode(plugin.serverNode);
|
|
1635
|
-
// Setting reachability to true
|
|
1636
1335
|
plugin.reachabilityTimeout = setTimeout(() => {
|
|
1637
1336
|
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
1337
|
if (plugin.type === 'DynamicPlatform' && plugin.aggregatorNode)
|
|
@@ -1642,226 +1341,9 @@ export class Matterbridge extends EventEmitter {
|
|
|
1642
1341
|
}
|
|
1643
1342
|
}, 1000);
|
|
1644
1343
|
}
|
|
1645
|
-
/**
|
|
1646
|
-
* Starts the Matterbridge controller.
|
|
1647
|
-
* @private
|
|
1648
|
-
* @returns {Promise<void>} A promise that resolves when the Matterbridge is started.
|
|
1649
|
-
*/
|
|
1650
1344
|
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
1345
|
}
|
|
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
1346
|
async startMatterStorage() {
|
|
1864
|
-
// Setup Matter storage
|
|
1865
1347
|
this.log.info(`Starting matter node storage...`);
|
|
1866
1348
|
this.matterStorageService = this.environment.get(StorageService);
|
|
1867
1349
|
this.log.info(`Matter node storage service created: ${this.matterStorageService.location}`);
|
|
@@ -1870,25 +1352,18 @@ export class Matterbridge extends EventEmitter {
|
|
|
1870
1352
|
this.matterbridgeContext = await this.createServerNodeContext('Matterbridge', 'Matterbridge', bridge.code, this.aggregatorVendorId, this.aggregatorVendorName, this.aggregatorProductId, this.aggregatorProductName);
|
|
1871
1353
|
this.matterbridgeInformation.matterbridgeSerialNumber = await this.matterbridgeContext.get('serialNumber', '');
|
|
1872
1354
|
this.log.info('Matter node storage started');
|
|
1873
|
-
// Backup matter storage since it is created/opened correctly
|
|
1874
1355
|
await this.backupMatterStorage(path.join(this.matterbridgeDirectory, this.matterStorageName), path.join(this.matterbridgeDirectory, this.matterStorageName + '.backup'));
|
|
1875
1356
|
}
|
|
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
1357
|
async backupMatterStorage(storageName, backupName) {
|
|
1884
1358
|
this.log.info('Creating matter node storage backup...');
|
|
1885
|
-
|
|
1886
|
-
|
|
1359
|
+
try {
|
|
1360
|
+
await copyDirectory(storageName, backupName);
|
|
1361
|
+
this.log.info('Created matter node storage backup');
|
|
1362
|
+
}
|
|
1363
|
+
catch (error) {
|
|
1364
|
+
this.log.error(`Error creating matter node storage backup from ${storageName} to ${backupName}:`, error);
|
|
1365
|
+
}
|
|
1887
1366
|
}
|
|
1888
|
-
/**
|
|
1889
|
-
* Stops the matter storage.
|
|
1890
|
-
* @returns {Promise<void>} A promise that resolves when the storage is stopped.
|
|
1891
|
-
*/
|
|
1892
1367
|
async stopMatterStorage() {
|
|
1893
1368
|
this.log.info('Closing matter node storage...');
|
|
1894
1369
|
await this.matterStorageManager?.close();
|
|
@@ -1897,19 +1372,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1897
1372
|
this.matterbridgeContext = undefined;
|
|
1898
1373
|
this.log.info('Matter node storage closed');
|
|
1899
1374
|
}
|
|
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
1375
|
async createServerNodeContext(pluginName, deviceName, deviceType, vendorId, vendorName, productId, productName, serialNumber) {
|
|
1914
1376
|
const { randomBytes } = await import('node:crypto');
|
|
1915
1377
|
if (!this.matterStorageService)
|
|
@@ -1943,15 +1405,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
1943
1405
|
this.log.debug(`- hardwareVersion: ${await storageContext.get('hardwareVersion')} hardwareVersionString: ${await storageContext.get('hardwareVersionString')}`);
|
|
1944
1406
|
return storageContext;
|
|
1945
1407
|
}
|
|
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
1408
|
async createServerNode(storageContext, port = 5540, passcode = 20242025, discriminator = 3850) {
|
|
1956
1409
|
const storeId = await storageContext.get('storeId');
|
|
1957
1410
|
this.log.notice(`Creating server node for ${storeId} on port ${port} with passcode ${passcode} and discriminator ${discriminator}...`);
|
|
@@ -1961,37 +1414,24 @@ export class Matterbridge extends EventEmitter {
|
|
|
1961
1414
|
this.log.debug(`- uniqueId: ${await storageContext.get('uniqueId')}`);
|
|
1962
1415
|
this.log.debug(`- softwareVersion: ${await storageContext.get('softwareVersion')} softwareVersionString: ${await storageContext.get('softwareVersionString')}`);
|
|
1963
1416
|
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
1417
|
const serverNode = await ServerNode.create({
|
|
1968
|
-
// Required: Give the Node a unique ID which is used to store the state of this node
|
|
1969
1418
|
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
1419
|
network: {
|
|
1973
1420
|
listeningAddressIpv4: this.ipv4address,
|
|
1974
1421
|
listeningAddressIpv6: this.ipv6address,
|
|
1975
1422
|
port,
|
|
1976
1423
|
},
|
|
1977
|
-
// Provide the certificate for the device
|
|
1978
1424
|
operationalCredentials: {
|
|
1979
1425
|
certification: this.certification,
|
|
1980
1426
|
},
|
|
1981
|
-
// Provide Commissioning relevant settings
|
|
1982
|
-
// Optional for development/testing purposes
|
|
1983
1427
|
commissioning: {
|
|
1984
1428
|
passcode,
|
|
1985
1429
|
discriminator,
|
|
1986
1430
|
},
|
|
1987
|
-
// Provide Node announcement settings
|
|
1988
|
-
// Optional: If Ommitted some development defaults are used
|
|
1989
1431
|
productDescription: {
|
|
1990
1432
|
name: await storageContext.get('deviceName'),
|
|
1991
1433
|
deviceType: DeviceTypeId(await storageContext.get('deviceType')),
|
|
1992
1434
|
},
|
|
1993
|
-
// Provide defaults for the BasicInformation cluster on the Root endpoint
|
|
1994
|
-
// Optional: If Omitted some development defaults are used
|
|
1995
1435
|
basicInformation: {
|
|
1996
1436
|
vendorId: VendorId(await storageContext.get('vendorId')),
|
|
1997
1437
|
vendorName: await storageContext.get('vendorName'),
|
|
@@ -2009,13 +1449,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
2009
1449
|
},
|
|
2010
1450
|
});
|
|
2011
1451
|
const sanitizeFabrics = (fabrics, resetSessions = false) => {
|
|
2012
|
-
// New type of fabric information: Record<FabricIndex, ExposedFabricInformation>
|
|
2013
1452
|
const sanitizedFabrics = this.sanitizeFabricInformations(Array.from(Object.values(fabrics)));
|
|
2014
1453
|
this.log.info(`Fabrics: ${debugStringify(sanitizedFabrics)}`);
|
|
2015
1454
|
if (this.bridgeMode === 'bridge') {
|
|
2016
1455
|
this.matterbridgeFabricInformations = sanitizedFabrics;
|
|
2017
1456
|
if (resetSessions)
|
|
2018
|
-
this.matterbridgeSessionInformations = undefined;
|
|
1457
|
+
this.matterbridgeSessionInformations = undefined;
|
|
2019
1458
|
this.matterbridgePaired = true;
|
|
2020
1459
|
}
|
|
2021
1460
|
if (this.bridgeMode === 'childbridge') {
|
|
@@ -2023,19 +1462,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
2023
1462
|
if (plugin) {
|
|
2024
1463
|
plugin.fabricInformations = sanitizedFabrics;
|
|
2025
1464
|
if (resetSessions)
|
|
2026
|
-
plugin.sessionInformations = undefined;
|
|
1465
|
+
plugin.sessionInformations = undefined;
|
|
2027
1466
|
plugin.paired = true;
|
|
2028
1467
|
}
|
|
2029
1468
|
}
|
|
2030
1469
|
};
|
|
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. */
|
|
1470
|
+
serverNode.lifecycle.commissioned.on(() => {
|
|
1471
|
+
this.log.notice(`Server node for ${storeId} was initially commissioned successfully!`);
|
|
1472
|
+
clearTimeout(this.endAdvertiseTimeout);
|
|
1473
|
+
});
|
|
2037
1474
|
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
1475
|
serverNode.lifecycle.online.on(async () => {
|
|
2040
1476
|
this.log.notice(`Server node for ${storeId} is online`);
|
|
2041
1477
|
if (!serverNode.lifecycle.isCommissioned) {
|
|
@@ -2074,27 +1510,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
2074
1510
|
}
|
|
2075
1511
|
}
|
|
2076
1512
|
}
|
|
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();
|
|
1513
|
+
this.startEndAdvertiseTimer(serverNode);
|
|
2098
1514
|
}
|
|
2099
1515
|
else {
|
|
2100
1516
|
this.log.notice(`Server node for ${storeId} is already commissioned. Waiting for controllers to connect ...`);
|
|
@@ -2103,8 +1519,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
2103
1519
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
2104
1520
|
this.frontend.wssSendRefreshRequired('settings');
|
|
2105
1521
|
this.frontend.wssSendSnackbarMessage(`${storeId} is online`, 5, 'success');
|
|
1522
|
+
this.emit('online', storeId);
|
|
2106
1523
|
});
|
|
2107
|
-
/** This event is triggered when the device went offline. it is not longer discoverable or connectable in the network. */
|
|
2108
1524
|
serverNode.lifecycle.offline.on(() => {
|
|
2109
1525
|
this.log.notice(`Server node for ${storeId} is offline`);
|
|
2110
1526
|
if (this.bridgeMode === 'bridge') {
|
|
@@ -2127,11 +1543,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
2127
1543
|
this.frontend.wssSendRefreshRequired('plugins');
|
|
2128
1544
|
this.frontend.wssSendRefreshRequired('settings');
|
|
2129
1545
|
this.frontend.wssSendSnackbarMessage(`${storeId} is offline`, 5, 'warning');
|
|
1546
|
+
this.emit('offline', storeId);
|
|
2130
1547
|
});
|
|
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
1548
|
serverNode.events.commissioning.fabricsChanged.on((fabricIndex, fabricAction) => {
|
|
2136
1549
|
let action = '';
|
|
2137
1550
|
switch (fabricAction) {
|
|
@@ -2165,24 +1578,16 @@ export class Matterbridge extends EventEmitter {
|
|
|
2165
1578
|
}
|
|
2166
1579
|
}
|
|
2167
1580
|
};
|
|
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
1581
|
serverNode.events.sessions.opened.on((session) => {
|
|
2173
1582
|
this.log.notice(`Session opened on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2174
1583
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
2175
1584
|
this.frontend.wssSendRefreshRequired('sessions');
|
|
2176
1585
|
});
|
|
2177
|
-
/**
|
|
2178
|
-
* This event is triggered when an operative session is closed by a Controller or because the Device goes offline.
|
|
2179
|
-
*/
|
|
2180
1586
|
serverNode.events.sessions.closed.on((session) => {
|
|
2181
1587
|
this.log.notice(`Session closed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2182
1588
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
2183
1589
|
this.frontend.wssSendRefreshRequired('sessions');
|
|
2184
1590
|
});
|
|
2185
|
-
/** This event is triggered when a subscription gets added or removed on an operative session. */
|
|
2186
1591
|
serverNode.events.sessions.subscriptionsChanged.on((session) => {
|
|
2187
1592
|
this.log.notice(`Session subscriptions changed on server node for ${storeId}: ${debugStringify(session)}`);
|
|
2188
1593
|
sanitizeSessions(Object.values(serverNode.state.sessions.sessions));
|
|
@@ -2191,42 +1596,52 @@ export class Matterbridge extends EventEmitter {
|
|
|
2191
1596
|
this.log.info(`Created server node for ${storeId}`);
|
|
2192
1597
|
return serverNode;
|
|
2193
1598
|
}
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
1599
|
+
startEndAdvertiseTimer(matterServerNode) {
|
|
1600
|
+
if (this.endAdvertiseTimeout) {
|
|
1601
|
+
this.log.debug(`***Clear ${matterServerNode.id} server node end advertise timer`);
|
|
1602
|
+
clearTimeout(this.endAdvertiseTimeout);
|
|
1603
|
+
}
|
|
1604
|
+
this.log.debug(`***Starting ${matterServerNode.id} server node end advertise timer`);
|
|
1605
|
+
this.endAdvertiseTimeout = setTimeout(() => {
|
|
1606
|
+
if (matterServerNode.lifecycle.isCommissioned)
|
|
1607
|
+
return;
|
|
1608
|
+
if (this.bridgeMode === 'bridge') {
|
|
1609
|
+
this.matterbridgeQrPairingCode = undefined;
|
|
1610
|
+
this.matterbridgeManualPairingCode = undefined;
|
|
1611
|
+
}
|
|
1612
|
+
if (this.bridgeMode === 'childbridge') {
|
|
1613
|
+
const plugin = this.plugins.get(matterServerNode.id);
|
|
1614
|
+
if (plugin) {
|
|
1615
|
+
plugin.qrPairingCode = undefined;
|
|
1616
|
+
plugin.manualPairingCode = undefined;
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
this.frontend.wssSendRefreshRequired('plugins');
|
|
1620
|
+
this.frontend.wssSendRefreshRequired('settings');
|
|
1621
|
+
this.frontend.wssSendRefreshRequired('fabrics');
|
|
1622
|
+
this.frontend.wssSendRefreshRequired('sessions');
|
|
1623
|
+
this.frontend.wssSendSnackbarMessage(`Advertising on server node for ${matterServerNode.id} stopped. Restart to commission.`, 0);
|
|
1624
|
+
this.log.notice(`Advertising on server node for ${matterServerNode.id} stopped. Restart to commission.`);
|
|
1625
|
+
}, 15 * 60 * 1000).unref();
|
|
1626
|
+
}
|
|
2200
1627
|
async startServerNode(matterServerNode) {
|
|
2201
1628
|
if (!matterServerNode)
|
|
2202
1629
|
return;
|
|
2203
1630
|
this.log.notice(`Starting ${matterServerNode.id} server node`);
|
|
2204
1631
|
await matterServerNode.start();
|
|
2205
1632
|
}
|
|
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) {
|
|
1633
|
+
async stopServerNode(matterServerNode, timeout = 30000) {
|
|
2213
1634
|
if (!matterServerNode)
|
|
2214
1635
|
return;
|
|
2215
1636
|
this.log.notice(`Closing ${matterServerNode.id} server node`);
|
|
2216
1637
|
try {
|
|
2217
|
-
await withTimeout(matterServerNode.close(),
|
|
1638
|
+
await withTimeout(matterServerNode.close(), timeout);
|
|
2218
1639
|
this.log.info(`Closed ${matterServerNode.id} server node`);
|
|
2219
1640
|
}
|
|
2220
1641
|
catch (error) {
|
|
2221
1642
|
this.log.error(`Failed to close ${matterServerNode.id} server node: ${error instanceof Error ? error.message : error}`);
|
|
2222
1643
|
}
|
|
2223
1644
|
}
|
|
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
1645
|
async advertiseServerNode(matterServerNode) {
|
|
2231
1646
|
if (matterServerNode) {
|
|
2232
1647
|
await matterServerNode.env.get(DeviceCommissioner)?.allowBasicCommissioning();
|
|
@@ -2235,46 +1650,25 @@ export class Matterbridge extends EventEmitter {
|
|
|
2235
1650
|
return { qrPairingCode, manualPairingCode };
|
|
2236
1651
|
}
|
|
2237
1652
|
}
|
|
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
1653
|
async stopAdvertiseServerNode(matterServerNode) {
|
|
2245
1654
|
if (matterServerNode && matterServerNode.lifecycle.isOnline) {
|
|
2246
1655
|
await matterServerNode.env.get(DeviceCommissioner)?.endCommissioning();
|
|
2247
1656
|
this.log.notice(`Stopped advertising for ${matterServerNode.id}`);
|
|
2248
1657
|
}
|
|
2249
1658
|
}
|
|
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
1659
|
async createAggregatorNode(storageContext) {
|
|
2257
1660
|
this.log.notice(`Creating ${await storageContext.get('storeId')} aggregator...`);
|
|
2258
1661
|
const aggregatorNode = new Endpoint(AggregatorEndpoint, { id: `${await storageContext.get('storeId')}` });
|
|
2259
1662
|
this.log.info(`Created ${await storageContext.get('storeId')} aggregator`);
|
|
2260
1663
|
return aggregatorNode;
|
|
2261
1664
|
}
|
|
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
1665
|
async addBridgedEndpoint(pluginName, device) {
|
|
2270
|
-
// Check if the plugin is registered
|
|
2271
1666
|
const plugin = this.plugins.get(pluginName);
|
|
2272
1667
|
if (!plugin) {
|
|
2273
1668
|
this.log.error(`Error adding bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.id}${er}) plugin ${plg}${pluginName}${er} not found`);
|
|
2274
1669
|
return;
|
|
2275
1670
|
}
|
|
2276
1671
|
if (this.bridgeMode === 'bridge') {
|
|
2277
|
-
// Register and add the device to the matterbridge aggregator node
|
|
2278
1672
|
this.log.debug(`Adding bridged endpoint ${plg}${pluginName}${db}:${dev}${device.deviceName}${db} to Matterbridge aggregator node`);
|
|
2279
1673
|
if (!this.aggregatorNode) {
|
|
2280
1674
|
this.log.error('Aggregator node not found for Matterbridge');
|
|
@@ -2291,7 +1685,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2291
1685
|
}
|
|
2292
1686
|
}
|
|
2293
1687
|
else if (this.bridgeMode === 'childbridge') {
|
|
2294
|
-
// Register and add the device to the plugin server node
|
|
2295
1688
|
if (plugin.type === 'AccessoryPlatform') {
|
|
2296
1689
|
try {
|
|
2297
1690
|
this.log.debug(`Creating endpoint ${dev}${device.deviceName}${db} for AccessoryPlatform plugin ${plg}${plugin.name}${db} server node`);
|
|
@@ -2308,12 +1701,10 @@ export class Matterbridge extends EventEmitter {
|
|
|
2308
1701
|
return;
|
|
2309
1702
|
}
|
|
2310
1703
|
}
|
|
2311
|
-
// Register and add the device to the plugin aggregator node
|
|
2312
1704
|
if (plugin.type === 'DynamicPlatform') {
|
|
2313
1705
|
try {
|
|
2314
1706
|
this.log.debug(`Adding bridged endpoint ${dev}${device.deviceName}${db} for DynamicPlatform plugin ${plg}${plugin.name}${db} aggregator node`);
|
|
2315
1707
|
await this.createDynamicPlugin(plugin);
|
|
2316
|
-
// Fast plugins can add another device before the server node is created
|
|
2317
1708
|
await waiter(`createDynamicPlugin(${plugin.name})`, () => plugin.serverNode?.hasParts === true);
|
|
2318
1709
|
if (!plugin.aggregatorNode) {
|
|
2319
1710
|
this.log.error(`Aggregator node not found for plugin ${plg}${plugin.name}${er}`);
|
|
@@ -2333,28 +1724,17 @@ export class Matterbridge extends EventEmitter {
|
|
|
2333
1724
|
plugin.registeredDevices++;
|
|
2334
1725
|
if (plugin.addedDevices !== undefined)
|
|
2335
1726
|
plugin.addedDevices++;
|
|
2336
|
-
// Add the device to the DeviceManager
|
|
2337
1727
|
this.devices.set(device);
|
|
2338
|
-
// Subscribe to the reachable$Changed event
|
|
2339
1728
|
await this.subscribeAttributeChanged(plugin, device);
|
|
2340
1729
|
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
1730
|
}
|
|
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
1731
|
async removeBridgedEndpoint(pluginName, device) {
|
|
2350
1732
|
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
1733
|
const plugin = this.plugins.get(pluginName);
|
|
2353
1734
|
if (!plugin) {
|
|
2354
1735
|
this.log.error(`Error removing bridged endpoint ${dev}${device.deviceName}${er} (${zb}${device.name}${er}) for plugin ${plg}${pluginName}${er}: plugin not found`);
|
|
2355
1736
|
return;
|
|
2356
1737
|
}
|
|
2357
|
-
// Register and add the device to the matterbridge aggregator node
|
|
2358
1738
|
if (this.bridgeMode === 'bridge') {
|
|
2359
1739
|
if (!this.aggregatorNode) {
|
|
2360
1740
|
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 +1749,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2369
1749
|
}
|
|
2370
1750
|
else if (this.bridgeMode === 'childbridge') {
|
|
2371
1751
|
if (plugin.type === 'AccessoryPlatform') {
|
|
2372
|
-
// Nothing to do here since the server node has no aggregator node but only the device itself
|
|
2373
1752
|
}
|
|
2374
1753
|
else if (plugin.type === 'DynamicPlatform') {
|
|
2375
1754
|
if (!plugin.aggregatorNode) {
|
|
@@ -2384,21 +1763,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
2384
1763
|
if (plugin.addedDevices !== undefined)
|
|
2385
1764
|
plugin.addedDevices--;
|
|
2386
1765
|
}
|
|
2387
|
-
// Remove the device from the DeviceManager
|
|
2388
1766
|
this.devices.remove(device);
|
|
2389
1767
|
}
|
|
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
1768
|
async removeAllBridgedEndpoints(pluginName, delay = 0) {
|
|
2403
1769
|
this.log.debug(`Removing all bridged endpoints for plugin ${plg}${pluginName}${db}${delay > 0 ? ` with delay ${delay} ms` : ''}`);
|
|
2404
1770
|
for (const device of this.devices.array().filter((device) => device.plugin === pluginName)) {
|
|
@@ -2409,15 +1775,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2409
1775
|
if (delay > 0)
|
|
2410
1776
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
2411
1777
|
}
|
|
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
1778
|
async subscribeAttributeChanged(plugin, device) {
|
|
2422
1779
|
this.log.info(`Subscribing attributes for endpoint ${dev}${device.deviceName}${nf} (${dev}${device.id}${nf}) plugin ${plg}${plugin.name}${nf}`);
|
|
2423
1780
|
if (this.bridgeMode === 'childbridge' && plugin.type === 'AccessoryPlatform' && plugin.serverNode) {
|
|
@@ -2433,12 +1790,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2433
1790
|
});
|
|
2434
1791
|
}
|
|
2435
1792
|
}
|
|
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
1793
|
sanitizeFabricInformations(fabricInfo) {
|
|
2443
1794
|
return fabricInfo.map((info) => {
|
|
2444
1795
|
return {
|
|
@@ -2452,12 +1803,6 @@ export class Matterbridge extends EventEmitter {
|
|
|
2452
1803
|
};
|
|
2453
1804
|
});
|
|
2454
1805
|
}
|
|
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
1806
|
sanitizeSessionInformation(sessionInfo) {
|
|
2462
1807
|
return sessionInfo
|
|
2463
1808
|
.filter((session) => session.isPeerActive)
|
|
@@ -2485,20 +1830,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
2485
1830
|
};
|
|
2486
1831
|
});
|
|
2487
1832
|
}
|
|
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
1833
|
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
1834
|
}
|
|
2503
1835
|
getVendorIdName = (vendorId) => {
|
|
2504
1836
|
if (!vendorId)
|
|
@@ -2541,112 +1873,4 @@ export class Matterbridge extends EventEmitter {
|
|
|
2541
1873
|
}
|
|
2542
1874
|
return vendorName;
|
|
2543
1875
|
};
|
|
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
1876
|
}
|
|
2652
|
-
//# sourceMappingURL=matterbridge.js.map
|