matterbridge 3.3.3 → 3.3.4-dev-20251020-4d2dd49
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 +21 -0
- package/dist/broadcastServer.js +1 -86
- package/dist/broadcastServerTypes.js +0 -24
- package/dist/cli.js +110 -444
- package/dist/cliEmitter.js +0 -37
- package/dist/cliHistory.js +15 -95
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +0 -24
- package/dist/deviceManager.js +1 -124
- package/dist/devices/airConditioner.js +0 -57
- package/dist/devices/batteryStorage.js +1 -48
- package/dist/devices/cooktop.js +0 -55
- package/dist/devices/dishwasher.js +0 -57
- package/dist/devices/evse.js +10 -74
- package/dist/devices/export.js +0 -5
- package/dist/devices/extractorHood.js +0 -42
- package/dist/devices/heatPump.js +2 -50
- package/dist/devices/laundryDryer.js +3 -62
- package/dist/devices/laundryWasher.js +4 -70
- package/dist/devices/microwaveOven.js +5 -88
- package/dist/devices/oven.js +0 -85
- package/dist/devices/refrigerator.js +0 -102
- package/dist/devices/roboticVacuumCleaner.js +9 -100
- package/dist/devices/solarPower.js +0 -38
- package/dist/devices/speaker.js +0 -84
- package/dist/devices/temperatureControl.js +3 -25
- package/dist/devices/waterHeater.js +2 -82
- package/dist/dgram/coap.js +13 -126
- package/dist/dgram/dgram.js +2 -114
- package/dist/dgram/mb_coap.js +3 -41
- package/dist/dgram/mb_mdns.js +15 -80
- package/dist/dgram/mdns.js +137 -299
- package/dist/dgram/multicast.js +1 -62
- package/dist/dgram/unicast.js +0 -54
- package/dist/frontend.js +34 -413
- package/dist/frontendTypes.js +0 -45
- package/dist/helpers.js +0 -53
- package/dist/index.js +0 -25
- 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 -3
- package/dist/matter/types.js +0 -3
- package/dist/matterbridge.js +51 -873
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -71
- package/dist/matterbridgeDeviceTypes.js +17 -630
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +58 -1412
- package/dist/matterbridgeEndpointHelpers.js +10 -368
- package/dist/matterbridgePlatform.js +1 -341
- package/dist/matterbridgeTypes.js +0 -26
- package/dist/pluginManager.js +3 -325
- package/dist/shelly.js +7 -168
- package/dist/storage/export.js +0 -1
- package/dist/update.js +0 -69
- package/dist/utils/colorUtils.js +2 -97
- package/dist/utils/commandLine.js +6 -55
- package/dist/utils/copyDirectory.js +1 -38
- package/dist/utils/createDirectory.js +0 -33
- package/dist/utils/createZip.js +2 -47
- package/dist/utils/deepCopy.js +0 -39
- package/dist/utils/deepEqual.js +1 -72
- package/dist/utils/error.js +0 -41
- package/dist/utils/export.js +0 -1
- package/dist/utils/hex.js +0 -124
- package/dist/utils/inspector.js +200 -0
- package/dist/utils/isvalid.js +0 -101
- package/dist/utils/jestHelpers.js +3 -153
- package/dist/utils/network.js +5 -108
- package/dist/utils/spawn.js +0 -71
- package/dist/utils/tracker.js +229 -0
- package/dist/utils/wait.js +8 -60
- package/frontend/build/assets/index.js +4 -4
- package/frontend/build/assets/vendor_mdi.js +1 -1
- package/frontend/package.json +1 -1
- package/npm-shrinkwrap.json +44 -44
- package/package.json +2 -3
- package/dist/broadcastServer.d.ts +0 -105
- package/dist/broadcastServer.d.ts.map +0 -1
- package/dist/broadcastServer.js.map +0 -1
- package/dist/broadcastServerTypes.d.ts +0 -719
- package/dist/broadcastServerTypes.d.ts.map +0 -1
- package/dist/broadcastServerTypes.js.map +0 -1
- package/dist/cli.d.ts +0 -26
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cliEmitter.d.ts +0 -50
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.js.map +0 -1
- package/dist/cliHistory.d.ts +0 -74
- package/dist/cliHistory.d.ts.map +0 -1
- package/dist/cliHistory.js.map +0 -1
- package/dist/clusters/export.d.ts +0 -2
- package/dist/clusters/export.d.ts.map +0 -1
- package/dist/clusters/export.js.map +0 -1
- package/dist/defaultConfigSchema.d.ts +0 -28
- package/dist/defaultConfigSchema.d.ts.map +0 -1
- package/dist/defaultConfigSchema.js.map +0 -1
- package/dist/deviceManager.d.ts +0 -117
- package/dist/deviceManager.d.ts.map +0 -1
- package/dist/deviceManager.js.map +0 -1
- package/dist/devices/airConditioner.d.ts +0 -98
- package/dist/devices/airConditioner.d.ts.map +0 -1
- package/dist/devices/airConditioner.js.map +0 -1
- package/dist/devices/batteryStorage.d.ts +0 -48
- package/dist/devices/batteryStorage.d.ts.map +0 -1
- package/dist/devices/batteryStorage.js.map +0 -1
- package/dist/devices/cooktop.d.ts +0 -60
- package/dist/devices/cooktop.d.ts.map +0 -1
- package/dist/devices/cooktop.js.map +0 -1
- package/dist/devices/dishwasher.d.ts +0 -71
- package/dist/devices/dishwasher.d.ts.map +0 -1
- package/dist/devices/dishwasher.js.map +0 -1
- package/dist/devices/evse.d.ts +0 -75
- package/dist/devices/evse.d.ts.map +0 -1
- package/dist/devices/evse.js.map +0 -1
- package/dist/devices/export.d.ts +0 -17
- package/dist/devices/export.d.ts.map +0 -1
- package/dist/devices/export.js.map +0 -1
- package/dist/devices/extractorHood.d.ts +0 -46
- package/dist/devices/extractorHood.d.ts.map +0 -1
- package/dist/devices/extractorHood.js.map +0 -1
- package/dist/devices/heatPump.d.ts +0 -47
- package/dist/devices/heatPump.d.ts.map +0 -1
- package/dist/devices/heatPump.js.map +0 -1
- package/dist/devices/laundryDryer.d.ts +0 -67
- package/dist/devices/laundryDryer.d.ts.map +0 -1
- package/dist/devices/laundryDryer.js.map +0 -1
- package/dist/devices/laundryWasher.d.ts +0 -81
- package/dist/devices/laundryWasher.d.ts.map +0 -1
- package/dist/devices/laundryWasher.js.map +0 -1
- package/dist/devices/microwaveOven.d.ts +0 -168
- package/dist/devices/microwaveOven.d.ts.map +0 -1
- package/dist/devices/microwaveOven.js.map +0 -1
- package/dist/devices/oven.d.ts +0 -105
- package/dist/devices/oven.d.ts.map +0 -1
- package/dist/devices/oven.js.map +0 -1
- package/dist/devices/refrigerator.d.ts +0 -118
- package/dist/devices/refrigerator.d.ts.map +0 -1
- package/dist/devices/refrigerator.js.map +0 -1
- package/dist/devices/roboticVacuumCleaner.d.ts +0 -112
- package/dist/devices/roboticVacuumCleaner.d.ts.map +0 -1
- package/dist/devices/roboticVacuumCleaner.js.map +0 -1
- package/dist/devices/solarPower.d.ts +0 -40
- package/dist/devices/solarPower.d.ts.map +0 -1
- package/dist/devices/solarPower.js.map +0 -1
- package/dist/devices/speaker.d.ts +0 -87
- package/dist/devices/speaker.d.ts.map +0 -1
- package/dist/devices/speaker.js.map +0 -1
- package/dist/devices/temperatureControl.d.ts +0 -166
- package/dist/devices/temperatureControl.d.ts.map +0 -1
- package/dist/devices/temperatureControl.js.map +0 -1
- package/dist/devices/waterHeater.d.ts +0 -111
- package/dist/devices/waterHeater.d.ts.map +0 -1
- package/dist/devices/waterHeater.js.map +0 -1
- package/dist/dgram/coap.d.ts +0 -205
- package/dist/dgram/coap.d.ts.map +0 -1
- package/dist/dgram/coap.js.map +0 -1
- package/dist/dgram/dgram.d.ts +0 -141
- package/dist/dgram/dgram.d.ts.map +0 -1
- package/dist/dgram/dgram.js.map +0 -1
- package/dist/dgram/mb_coap.d.ts +0 -24
- package/dist/dgram/mb_coap.d.ts.map +0 -1
- package/dist/dgram/mb_coap.js.map +0 -1
- package/dist/dgram/mb_mdns.d.ts +0 -24
- package/dist/dgram/mb_mdns.d.ts.map +0 -1
- package/dist/dgram/mb_mdns.js.map +0 -1
- package/dist/dgram/mdns.d.ts +0 -290
- package/dist/dgram/mdns.d.ts.map +0 -1
- package/dist/dgram/mdns.js.map +0 -1
- package/dist/dgram/multicast.d.ts +0 -67
- package/dist/dgram/multicast.d.ts.map +0 -1
- package/dist/dgram/multicast.js.map +0 -1
- package/dist/dgram/unicast.d.ts +0 -56
- package/dist/dgram/unicast.d.ts.map +0 -1
- package/dist/dgram/unicast.js.map +0 -1
- package/dist/frontend.d.ts +0 -235
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/frontendTypes.d.ts +0 -529
- package/dist/frontendTypes.d.ts.map +0 -1
- package/dist/frontendTypes.js.map +0 -1
- package/dist/helpers.d.ts +0 -48
- package/dist/helpers.d.ts.map +0 -1
- package/dist/helpers.js.map +0 -1
- package/dist/index.d.ts +0 -33
- package/dist/index.d.ts.map +0 -1
- package/dist/index.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 -469
- package/dist/matterbridge.d.ts.map +0 -1
- package/dist/matterbridge.js.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.d.ts +0 -42
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +0 -1
- package/dist/matterbridgeAccessoryPlatform.js.map +0 -1
- package/dist/matterbridgeBehaviors.d.ts +0 -2399
- package/dist/matterbridgeBehaviors.d.ts.map +0 -1
- package/dist/matterbridgeBehaviors.js.map +0 -1
- package/dist/matterbridgeDeviceTypes.d.ts +0 -761
- package/dist/matterbridgeDeviceTypes.d.ts.map +0 -1
- package/dist/matterbridgeDeviceTypes.js.map +0 -1
- package/dist/matterbridgeDynamicPlatform.d.ts +0 -42
- package/dist/matterbridgeDynamicPlatform.d.ts.map +0 -1
- package/dist/matterbridgeDynamicPlatform.js.map +0 -1
- package/dist/matterbridgeEndpoint.d.ts +0 -1545
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -560
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -402
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -209
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -353
- package/dist/pluginManager.d.ts.map +0 -1
- package/dist/pluginManager.js.map +0 -1
- package/dist/shelly.d.ts +0 -174
- 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 -75
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js.map +0 -1
- package/dist/utils/colorUtils.d.ts +0 -99
- package/dist/utils/colorUtils.d.ts.map +0 -1
- package/dist/utils/colorUtils.js.map +0 -1
- package/dist/utils/commandLine.d.ts +0 -59
- package/dist/utils/commandLine.d.ts.map +0 -1
- package/dist/utils/commandLine.js.map +0 -1
- package/dist/utils/copyDirectory.d.ts +0 -33
- package/dist/utils/copyDirectory.d.ts.map +0 -1
- package/dist/utils/copyDirectory.js.map +0 -1
- package/dist/utils/createDirectory.d.ts +0 -34
- package/dist/utils/createDirectory.d.ts.map +0 -1
- package/dist/utils/createDirectory.js.map +0 -1
- package/dist/utils/createZip.d.ts +0 -39
- package/dist/utils/createZip.d.ts.map +0 -1
- package/dist/utils/createZip.js.map +0 -1
- package/dist/utils/deepCopy.d.ts +0 -32
- package/dist/utils/deepCopy.d.ts.map +0 -1
- package/dist/utils/deepCopy.js.map +0 -1
- package/dist/utils/deepEqual.d.ts +0 -54
- package/dist/utils/deepEqual.d.ts.map +0 -1
- package/dist/utils/deepEqual.js.map +0 -1
- package/dist/utils/error.d.ts +0 -44
- package/dist/utils/error.d.ts.map +0 -1
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/export.d.ts +0 -13
- package/dist/utils/export.d.ts.map +0 -1
- package/dist/utils/export.js.map +0 -1
- package/dist/utils/hex.d.ts +0 -89
- package/dist/utils/hex.d.ts.map +0 -1
- package/dist/utils/hex.js.map +0 -1
- package/dist/utils/isvalid.d.ts +0 -103
- package/dist/utils/isvalid.d.ts.map +0 -1
- package/dist/utils/isvalid.js.map +0 -1
- package/dist/utils/jestHelpers.d.ts +0 -137
- package/dist/utils/jestHelpers.d.ts.map +0 -1
- package/dist/utils/jestHelpers.js.map +0 -1
- package/dist/utils/network.d.ts +0 -115
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -35
- package/dist/utils/spawn.d.ts.map +0 -1
- package/dist/utils/spawn.js.map +0 -1
- package/dist/utils/wait.d.ts +0 -54
- package/dist/utils/wait.d.ts.map +0 -1
- package/dist/utils/wait.js.map +0 -1
|
@@ -1,68 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description This file contains the Jest helpers.
|
|
3
|
-
* @file src/helpers.test.ts
|
|
4
|
-
* @author Luca Liguori
|
|
5
|
-
* @created 2025-09-03
|
|
6
|
-
* @version 1.0.5
|
|
7
|
-
* @license Apache-2.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 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
1
|
import { rmSync } from 'node:fs';
|
|
24
2
|
import { inspect } from 'node:util';
|
|
25
3
|
import path from 'node:path';
|
|
26
|
-
// Imports from Matterbridge
|
|
27
4
|
import { jest } from '@jest/globals';
|
|
28
5
|
import { DeviceTypeId, Endpoint, Environment, ServerNode, ServerNodeStore, VendorId, LogFormat as MatterLogFormat, LogLevel as MatterLogLevel, Lifecycle } from '@matter/main';
|
|
29
6
|
import { AggregatorEndpoint, RootEndpoint } from '@matter/main/endpoints';
|
|
30
7
|
import { MdnsService } from '@matter/main/protocol';
|
|
31
8
|
import { AnsiLogger } from 'node-ansi-logger';
|
|
32
|
-
// Imports from a plugin
|
|
33
|
-
/*
|
|
34
|
-
import { jest } from '@jest/globals';
|
|
35
|
-
import { DeviceTypeId, Endpoint, Environment, MdnsService, ServerNode, ServerNodeStore, VendorId, LogFormat as MatterLogFormat, LogLevel as MatterLogLevel, Lifecycle } from 'matterbridge/matter';
|
|
36
|
-
import { RootEndpoint, AggregatorEndpoint } from 'matterbridge/matter/endpoints';
|
|
37
|
-
import { AnsiLogger } from 'matterbridge/logger';
|
|
38
|
-
*/
|
|
39
9
|
export let loggerLogSpy;
|
|
40
10
|
export let consoleLogSpy;
|
|
41
11
|
export let consoleDebugSpy;
|
|
42
12
|
export let consoleInfoSpy;
|
|
43
13
|
export let consoleWarnSpy;
|
|
44
14
|
export let consoleErrorSpy;
|
|
45
|
-
/**
|
|
46
|
-
* Setup the Jest environment:
|
|
47
|
-
* - it will remove any existing home directory
|
|
48
|
-
* - setup the spies for logging
|
|
49
|
-
*
|
|
50
|
-
* @param {string} name The name of the test suite.
|
|
51
|
-
* @param {boolean} debug If true, the logging is not mocked.
|
|
52
|
-
*
|
|
53
|
-
* ```typescript
|
|
54
|
-
* import { consoleDebugSpy, consoleErrorSpy, consoleInfoSpy, consoleLogSpy, consoleWarnSpy, loggerLogSpy, setDebug, setupTest } from './jestHelpers.js';
|
|
55
|
-
*
|
|
56
|
-
* // Setup the test environment
|
|
57
|
-
* setupTest(NAME, false);
|
|
58
|
-
*
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
15
|
export function setupTest(name, debug = false) {
|
|
62
16
|
expect(name).toBeDefined();
|
|
63
17
|
expect(typeof name).toBe('string');
|
|
64
|
-
expect(name.length).toBeGreaterThanOrEqual(4);
|
|
65
|
-
// Cleanup any existing home directory
|
|
18
|
+
expect(name.length).toBeGreaterThanOrEqual(4);
|
|
66
19
|
rmSync(path.join('jest', name), { recursive: true, force: true });
|
|
67
20
|
if (debug) {
|
|
68
21
|
loggerLogSpy = jest.spyOn(AnsiLogger.prototype, 'log');
|
|
@@ -81,11 +34,6 @@ export function setupTest(name, debug = false) {
|
|
|
81
34
|
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
|
|
82
35
|
}
|
|
83
36
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Set or unset the debug mode.
|
|
86
|
-
*
|
|
87
|
-
* @param {boolean} debug If true, the logging is not mocked.
|
|
88
|
-
*/
|
|
89
37
|
export function setDebug(debug) {
|
|
90
38
|
if (debug) {
|
|
91
39
|
loggerLogSpy.mockRestore();
|
|
@@ -110,21 +58,11 @@ export function setDebug(debug) {
|
|
|
110
58
|
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
|
|
111
59
|
}
|
|
112
60
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Create a matter Environment for testing:
|
|
115
|
-
* - it will remove any existing home directory
|
|
116
|
-
* - setup the matter environment with homeDir, debug logging and ANSI format
|
|
117
|
-
*
|
|
118
|
-
* @param {string} homeDir Home directory for the environment.
|
|
119
|
-
* @returns {Environment} The default matter environment.
|
|
120
|
-
*/
|
|
121
61
|
export function createTestEnvironment(homeDir) {
|
|
122
62
|
expect(homeDir).toBeDefined();
|
|
123
63
|
expect(typeof homeDir).toBe('string');
|
|
124
|
-
expect(homeDir.length).toBeGreaterThanOrEqual(4);
|
|
125
|
-
// Cleanup any existing home directory
|
|
64
|
+
expect(homeDir.length).toBeGreaterThanOrEqual(4);
|
|
126
65
|
rmSync(homeDir, { recursive: true, force: true });
|
|
127
|
-
// Setup the matter environment
|
|
128
66
|
const environment = Environment.default;
|
|
129
67
|
environment.vars.set('log.level', MatterLogLevel.DEBUG);
|
|
130
68
|
environment.vars.set('log.format', MatterLogFormat.ANSI);
|
|
@@ -133,18 +71,6 @@ export function createTestEnvironment(homeDir) {
|
|
|
133
71
|
environment.vars.set('runtime.exitcode', false);
|
|
134
72
|
return environment;
|
|
135
73
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Advance the Node.js event loop deterministically to allow chained asynchronous work (Promises scheduled in
|
|
138
|
-
* microtasks and follow‑up macrotasks) to complete inside tests without adding arbitrary long timeouts.
|
|
139
|
-
*
|
|
140
|
-
* NOTE: This does not guarantee OS level network IO completion—only JavaScript task queue progression inside the
|
|
141
|
-
* current process.
|
|
142
|
-
*
|
|
143
|
-
* @param {number} ticks Number of macrotask (setImmediate) turns to yield (default 3).
|
|
144
|
-
* @param {number} microTurns Number of microtask drains (Promise.resolve chains) after macrotask yielding (default 10).
|
|
145
|
-
* @param {number} pause Final timer delay in ms; set 0 to disable (default 100ms).
|
|
146
|
-
* @returns {Promise<void>} Resolves after the requested event loop advancement has completed.
|
|
147
|
-
*/
|
|
148
74
|
export async function flushAsync(ticks = 3, microTurns = 10, pause = 100) {
|
|
149
75
|
for (let i = 0; i < ticks; i++)
|
|
150
76
|
await new Promise((resolve) => setImmediate(resolve));
|
|
@@ -153,19 +79,6 @@ export async function flushAsync(ticks = 3, microTurns = 10, pause = 100) {
|
|
|
153
79
|
if (pause)
|
|
154
80
|
await new Promise((resolve) => setTimeout(resolve, pause));
|
|
155
81
|
}
|
|
156
|
-
/**
|
|
157
|
-
* Flush (await) the lazy endpoint number persistence mechanism used by matter.js.
|
|
158
|
-
*
|
|
159
|
-
* Background:
|
|
160
|
-
* assignNumber() batches persistence (store.saveNumber + updating __nextNumber__) via an internal promise (#numbersPersisted).
|
|
161
|
-
* Calling endpointStores.close() waits for the current batch only. If new endpoints were added in the same macrotask
|
|
162
|
-
* cycle additional micro/macro turns might be needed to ensure the batch started. We defensively yield macrotasks
|
|
163
|
-
* (setImmediate) and then await close() multiple rounds.
|
|
164
|
-
*
|
|
165
|
-
* @param {ServerNode} targetServer The server whose endpoint numbering persistence should be flushed.
|
|
166
|
-
* @param {number} rounds Number of macrotask + close cycles to run (2 is usually sufficient; 1 often works).
|
|
167
|
-
* @returns {Promise<void>} Resolves when pending number persistence batches have completed.
|
|
168
|
-
*/
|
|
169
82
|
export async function flushAllEndpointNumberPersistence(targetServer, rounds = 2) {
|
|
170
83
|
const nodeStore = targetServer.env.get(ServerNodeStore);
|
|
171
84
|
for (let i = 0; i < rounds; i++) {
|
|
@@ -173,12 +86,6 @@ export async function flushAllEndpointNumberPersistence(targetServer, rounds = 2
|
|
|
173
86
|
await nodeStore.endpointStores.close();
|
|
174
87
|
}
|
|
175
88
|
}
|
|
176
|
-
/**
|
|
177
|
-
* Collect all endpoints in the server endpoint tree (root -> descendants).
|
|
178
|
-
*
|
|
179
|
-
* @param {Endpoint} root Root endpoint (typically the ServerNode root endpoint cast as Endpoint).
|
|
180
|
-
* @returns {Endpoint[]} Flat array including the root and every descendant once.
|
|
181
|
-
*/
|
|
182
89
|
function collectAllEndpoints(root) {
|
|
183
90
|
const list = [];
|
|
184
91
|
const walk = (ep) => {
|
|
@@ -192,26 +99,14 @@ function collectAllEndpoints(root) {
|
|
|
192
99
|
walk(root);
|
|
193
100
|
return list;
|
|
194
101
|
}
|
|
195
|
-
/**
|
|
196
|
-
* Assert that every endpoint attached to the server has an assigned and (batch-)persisted endpoint number.
|
|
197
|
-
*
|
|
198
|
-
* This waits for any outstanding number persistence batch (endpointStores.close()), then traverses the endpoint
|
|
199
|
-
* graph and asserts:
|
|
200
|
-
* - Root endpoint: number is 0 (allowing undefined to coerce to 0 via nullish coalescing check).
|
|
201
|
-
* - All other endpoints: number > 0.
|
|
202
|
-
*
|
|
203
|
-
* @param {ServerNode} targetServer The server whose endpoint numbers are verified.
|
|
204
|
-
* @returns {Promise<void>} Resolves when assertions complete.
|
|
205
|
-
*/
|
|
206
102
|
export async function assertAllEndpointNumbersPersisted(targetServer) {
|
|
207
103
|
const nodeStore = targetServer.env.get(ServerNodeStore);
|
|
208
|
-
// Ensure any pending persistence finished (flush any in-flight batch promise)
|
|
209
104
|
await nodeStore.endpointStores.close();
|
|
210
105
|
const all = collectAllEndpoints(targetServer);
|
|
211
106
|
for (const ep of all) {
|
|
212
107
|
const store = nodeStore.storeForEndpoint(ep);
|
|
213
108
|
if (ep.maybeNumber === 0) {
|
|
214
|
-
expect(store.number ?? 0).toBe(0);
|
|
109
|
+
expect(store.number ?? 0).toBe(0);
|
|
215
110
|
}
|
|
216
111
|
else {
|
|
217
112
|
expect(store.number).toBeGreaterThan(0);
|
|
@@ -219,15 +114,7 @@ export async function assertAllEndpointNumbersPersisted(targetServer) {
|
|
|
219
114
|
}
|
|
220
115
|
return all.length;
|
|
221
116
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Start a matter server node for testing.
|
|
224
|
-
*
|
|
225
|
-
* @param {string} name Name of the server (used for logging and product description).
|
|
226
|
-
* @param {number} port TCP port to listen on.
|
|
227
|
-
* @returns {Promise<[ServerNode<ServerNode.RootEndpoint>, Endpoint<AggregatorEndpoint>]>} Resolves to an array containing the created ServerNode and its AggregatorNode.
|
|
228
|
-
*/
|
|
229
117
|
export async function startServerNode(name, port) {
|
|
230
|
-
// Create the server node
|
|
231
118
|
const server = await ServerNode.create({
|
|
232
119
|
id: name + 'ServerNode',
|
|
233
120
|
productDescription: {
|
|
@@ -236,7 +123,6 @@ export async function startServerNode(name, port) {
|
|
|
236
123
|
vendorId: VendorId(0xfff1),
|
|
237
124
|
productId: 0x8000,
|
|
238
125
|
},
|
|
239
|
-
// Provide defaults for the BasicInformation cluster on the Root endpoint
|
|
240
126
|
basicInformation: {
|
|
241
127
|
vendorId: VendorId(0xfff1),
|
|
242
128
|
vendorName: 'Matterbridge',
|
|
@@ -253,26 +139,21 @@ export async function startServerNode(name, port) {
|
|
|
253
139
|
});
|
|
254
140
|
expect(server).toBeDefined();
|
|
255
141
|
expect(server.lifecycle.isReady).toBeTruthy();
|
|
256
|
-
// Create the aggregator node
|
|
257
142
|
const aggregator = new Endpoint(AggregatorEndpoint, {
|
|
258
143
|
id: name + 'AggregatorNode',
|
|
259
144
|
});
|
|
260
145
|
expect(aggregator).toBeDefined();
|
|
261
|
-
// Add the aggregator to the server
|
|
262
146
|
await server.add(aggregator);
|
|
263
147
|
expect(server.parts.has(aggregator.id)).toBeTruthy();
|
|
264
148
|
expect(server.parts.has(aggregator)).toBeTruthy();
|
|
265
149
|
expect(aggregator.lifecycle.isReady).toBeTruthy();
|
|
266
|
-
// Run the server
|
|
267
150
|
expect(server.lifecycle.isOnline).toBeFalsy();
|
|
268
|
-
// Wait for the server to be online
|
|
269
151
|
await new Promise((resolve) => {
|
|
270
152
|
server.lifecycle.online.on(async () => {
|
|
271
153
|
resolve();
|
|
272
154
|
});
|
|
273
155
|
server.start();
|
|
274
156
|
});
|
|
275
|
-
// Check if the server is online
|
|
276
157
|
expect(server.lifecycle.isReady).toBeTruthy();
|
|
277
158
|
expect(server.lifecycle.isOnline).toBeTruthy();
|
|
278
159
|
expect(server.lifecycle.isCommissioned).toBeFalsy();
|
|
@@ -284,41 +165,21 @@ export async function startServerNode(name, port) {
|
|
|
284
165
|
expect(aggregator.lifecycle.isPartsReady).toBeTruthy();
|
|
285
166
|
expect(aggregator.lifecycle.hasId).toBeTruthy();
|
|
286
167
|
expect(aggregator.lifecycle.hasNumber).toBeTruthy();
|
|
287
|
-
// Ensure the queue is empty and pause 100ms
|
|
288
168
|
await flushAsync();
|
|
289
169
|
return [server, aggregator];
|
|
290
170
|
}
|
|
291
|
-
/**
|
|
292
|
-
* Stop a matter server node.
|
|
293
|
-
*
|
|
294
|
-
* @param {ServerNode<ServerNode.RootEndpoint>} server The server to stop.
|
|
295
|
-
* @returns {Promise<void>} Resolves when the server has stopped.
|
|
296
|
-
*/
|
|
297
171
|
export async function stopServerNode(server) {
|
|
298
|
-
// Flush any pending endpoint number persistence
|
|
299
172
|
await flushAllEndpointNumberPersistence(server);
|
|
300
|
-
// Ensure all endpoint numbers are persisted
|
|
301
173
|
await assertAllEndpointNumbersPersisted(server);
|
|
302
|
-
// Stop the server
|
|
303
174
|
expect(server).toBeDefined();
|
|
304
175
|
expect(server.lifecycle.isReady).toBeTruthy();
|
|
305
176
|
expect(server.lifecycle.isOnline).toBeTruthy();
|
|
306
177
|
await server.close();
|
|
307
178
|
expect(server.lifecycle.isReady).toBeTruthy();
|
|
308
179
|
expect(server.lifecycle.isOnline).toBeFalsy();
|
|
309
|
-
// stop the mDNS service
|
|
310
180
|
await server.env.get(MdnsService)[Symbol.asyncDispose]();
|
|
311
|
-
// Ensure the queue is empty and pause 100ms
|
|
312
181
|
await flushAsync();
|
|
313
182
|
}
|
|
314
|
-
/**
|
|
315
|
-
* Add a device (endpoint) to a matter server node or an aggregator.
|
|
316
|
-
*
|
|
317
|
-
* @param {ServerNode<ServerNode.RootEndpoint> | Endpoint<AggregatorEndpoint>} owner The server or aggregator to add the device to.
|
|
318
|
-
* @param {Endpoint} device The device to add.
|
|
319
|
-
* @param {number} pause The pause time in milliseconds after addition (default 10ms).
|
|
320
|
-
* @returns {Promise<void>} Resolves when the device has been added and is ready.
|
|
321
|
-
*/
|
|
322
183
|
export async function addDevice(owner, device, pause = 10) {
|
|
323
184
|
expect(owner).toBeDefined();
|
|
324
185
|
expect(device).toBeDefined();
|
|
@@ -331,7 +192,6 @@ export async function addDevice(owner, device, pause = 10) {
|
|
|
331
192
|
catch (error) {
|
|
332
193
|
const errorMessage = error instanceof Error ? error.message : error;
|
|
333
194
|
const errorInspect = inspect(error, { depth: 10 });
|
|
334
|
-
// eslint-disable-next-line no-console
|
|
335
195
|
console.error(`Error adding device ${device.maybeId}.${device.maybeNumber}: ${errorMessage}\nstack: ${errorInspect}`);
|
|
336
196
|
return false;
|
|
337
197
|
}
|
|
@@ -345,14 +205,6 @@ export async function addDevice(owner, device, pause = 10) {
|
|
|
345
205
|
await flushAsync(1, 1, pause);
|
|
346
206
|
return true;
|
|
347
207
|
}
|
|
348
|
-
/**
|
|
349
|
-
* Delete a device (endpoint) from a matter server node or an aggregator.
|
|
350
|
-
*
|
|
351
|
-
* @param {ServerNode<ServerNode.RootEndpoint> | Endpoint<AggregatorEndpoint>} owner The server or aggregator to remove the device from.
|
|
352
|
-
* @param {Endpoint} device The device to remove.
|
|
353
|
-
* @param {number} pause The pause time in milliseconds after deletion (default 10ms).
|
|
354
|
-
* @returns {Promise<void>} Resolves when the device has been removed and is no longer ready.
|
|
355
|
-
*/
|
|
356
208
|
export async function deleteDevice(owner, device, pause = 10) {
|
|
357
209
|
expect(owner).toBeDefined();
|
|
358
210
|
expect(device).toBeDefined();
|
|
@@ -365,7 +217,6 @@ export async function deleteDevice(owner, device, pause = 10) {
|
|
|
365
217
|
catch (error) {
|
|
366
218
|
const errorMessage = error instanceof Error ? error.message : error;
|
|
367
219
|
const errorInspect = inspect(error, { depth: 10 });
|
|
368
|
-
// eslint-disable-next-line no-console
|
|
369
220
|
console.error(`Error deleting device ${device.maybeId}.${device.maybeNumber}: ${errorMessage}\nstack: ${errorInspect}`);
|
|
370
221
|
return false;
|
|
371
222
|
}
|
|
@@ -379,4 +230,3 @@ export async function deleteDevice(owner, device, pause = 10) {
|
|
|
379
230
|
await flushAsync(1, 1, pause);
|
|
380
231
|
return true;
|
|
381
232
|
}
|
|
382
|
-
//# sourceMappingURL=jestHelpers.js.map
|
package/dist/utils/network.js
CHANGED
|
@@ -1,34 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description This file contains the network functions.
|
|
3
|
-
* @file network.ts
|
|
4
|
-
* @author Luca Liguori
|
|
5
|
-
* @created 2024-02-17
|
|
6
|
-
* @version 1.0.1
|
|
7
|
-
* @license Apache-2.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2024, 2025, 2026 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
|
-
// AnsiLogger module
|
|
26
2
|
import { AnsiLogger, BLUE, CYAN, nf } from 'node-ansi-logger';
|
|
27
|
-
/**
|
|
28
|
-
* Retrieves the first non-internal network interface details.
|
|
29
|
-
*
|
|
30
|
-
* @returns {os.NetworkInterfaceInfo | undefined} The details of the selected network interface, or undefined if not found.
|
|
31
|
-
*/
|
|
32
3
|
export function getInterfaceDetails() {
|
|
33
4
|
const result = { interfaceName: '', ipv4Address: undefined, ipv6Address: undefined, macAddress: undefined };
|
|
34
5
|
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
@@ -50,11 +21,6 @@ export function getInterfaceDetails() {
|
|
|
50
21
|
if (result.interfaceName)
|
|
51
22
|
return result;
|
|
52
23
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Retrieves the first non-internal network interface name.
|
|
55
|
-
*
|
|
56
|
-
* @returns {string | undefined} The name of the selected network interface, or undefined if not found.
|
|
57
|
-
*/
|
|
58
24
|
export function getInterfaceName() {
|
|
59
25
|
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
60
26
|
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
@@ -65,11 +31,6 @@ export function getInterfaceName() {
|
|
|
65
31
|
}
|
|
66
32
|
}
|
|
67
33
|
}
|
|
68
|
-
/**
|
|
69
|
-
* Retrieves the IPv4 address of the first non-internal network interface.
|
|
70
|
-
*
|
|
71
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
72
|
-
*/
|
|
73
34
|
export function getIpv4InterfaceAddress() {
|
|
74
35
|
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
75
36
|
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
@@ -80,11 +41,6 @@ export function getIpv4InterfaceAddress() {
|
|
|
80
41
|
}
|
|
81
42
|
}
|
|
82
43
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Retrieves the IPv6 address of the first non-internal network interface.
|
|
85
|
-
*
|
|
86
|
-
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
87
|
-
*/
|
|
88
44
|
export function getIpv6InterfaceAddress() {
|
|
89
45
|
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
90
46
|
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
@@ -95,11 +51,6 @@ export function getIpv6InterfaceAddress() {
|
|
|
95
51
|
}
|
|
96
52
|
}
|
|
97
53
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Retrieves the mac address of the first non-internal network interface.
|
|
100
|
-
*
|
|
101
|
-
* @returns {string | undefined} The mac address, or undefined if not found.
|
|
102
|
-
*/
|
|
103
54
|
export function getMacAddress() {
|
|
104
55
|
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
105
56
|
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
@@ -110,14 +61,9 @@ export function getMacAddress() {
|
|
|
110
61
|
}
|
|
111
62
|
}
|
|
112
63
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Logs the available network interfaces and their details.
|
|
115
|
-
*
|
|
116
|
-
* @returns {void}
|
|
117
|
-
*/
|
|
118
64
|
export function logInterfaces() {
|
|
119
|
-
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4
|
|
120
|
-
log.logLevel = "info"
|
|
65
|
+
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4, logLevel: "info" });
|
|
66
|
+
log.logLevel = "info";
|
|
121
67
|
log.logName = 'LogInterfaces';
|
|
122
68
|
log.info('Available Network Interfaces:');
|
|
123
69
|
const availableAddresses = Object.entries(os.networkInterfaces());
|
|
@@ -131,36 +77,16 @@ export function logInterfaces() {
|
|
|
131
77
|
}
|
|
132
78
|
}
|
|
133
79
|
}
|
|
134
|
-
/**
|
|
135
|
-
* Resolves the given hostname to an IP address.
|
|
136
|
-
*
|
|
137
|
-
* @param {string} hostname - The hostname to resolve.
|
|
138
|
-
* @param {0 | 4 | 6} [family] - The address family to use (0 for any, 4 for IPv4, 6 for IPv6). Default is 4.
|
|
139
|
-
* @returns {Promise<string | null>} - A promise that resolves to the IP address or null if not found.
|
|
140
|
-
*
|
|
141
|
-
* @remarks
|
|
142
|
-
* This function uses DNS lookup to resolve the hostname, which can take some time to complete.
|
|
143
|
-
*/
|
|
144
80
|
export async function resolveHostname(hostname, family = 4) {
|
|
145
81
|
const dns = await import('node:dns');
|
|
146
82
|
try {
|
|
147
|
-
const addresses = await dns.promises.lookup(hostname.toLowerCase()
|
|
83
|
+
const addresses = await dns.promises.lookup(hostname.toLowerCase(), { family });
|
|
148
84
|
return addresses.address;
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
150
85
|
}
|
|
151
86
|
catch (error) {
|
|
152
87
|
return null;
|
|
153
88
|
}
|
|
154
89
|
}
|
|
155
|
-
/**
|
|
156
|
-
* Retrieves the version of an npm package from the npm registry.
|
|
157
|
-
*
|
|
158
|
-
* @param {string} packageName - The name of the npm package.
|
|
159
|
-
* @param {string} [tag] - The tag of the package version to retrieve (default is 'latest').
|
|
160
|
-
* @param {number} [timeout] - The timeout duration in milliseconds (default is 10000ms).
|
|
161
|
-
* @returns {Promise<string>} A promise that resolves to the version string of the package.
|
|
162
|
-
* @throws {Error} If the request fails or the tag is not found.
|
|
163
|
-
*/
|
|
164
90
|
export async function getNpmPackageVersion(packageName, tag = 'latest', timeout = 10000) {
|
|
165
91
|
const https = await import('node:https');
|
|
166
92
|
return new Promise((resolve, reject) => {
|
|
@@ -174,7 +100,7 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
174
100
|
let data = '';
|
|
175
101
|
if (res.statusCode !== 200) {
|
|
176
102
|
clearTimeout(timeoutId);
|
|
177
|
-
res.resume();
|
|
103
|
+
res.resume();
|
|
178
104
|
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
179
105
|
return;
|
|
180
106
|
}
|
|
@@ -185,7 +111,6 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
185
111
|
clearTimeout(timeoutId);
|
|
186
112
|
try {
|
|
187
113
|
const jsonData = JSON.parse(data);
|
|
188
|
-
// console.log(`Package ${packageName} tag ${tag}`, jsonData);
|
|
189
114
|
const version = jsonData['dist-tags']?.[tag];
|
|
190
115
|
if (version) {
|
|
191
116
|
resolve(version);
|
|
@@ -205,15 +130,6 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
205
130
|
});
|
|
206
131
|
});
|
|
207
132
|
}
|
|
208
|
-
/**
|
|
209
|
-
* Retrieves a file from the public directory of the Matterbridge GitHub repository.
|
|
210
|
-
*
|
|
211
|
-
* @param {string} branch - The branch from which to fetch the file.
|
|
212
|
-
* @param {string} file - The file path to fetch.
|
|
213
|
-
* @param {number} [timeout] - The timeout duration in milliseconds (default is 10000ms).
|
|
214
|
-
* @returns {Promise<Record<string, boolean | string | number>>} A promise that resolves to the parsed JSON object from the file.
|
|
215
|
-
* @throws {Error} If the request fails or the JSON parsing fails.
|
|
216
|
-
*/
|
|
217
133
|
export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
218
134
|
const https = await import('node:https');
|
|
219
135
|
return new Promise((resolve, reject) => {
|
|
@@ -227,7 +143,7 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
|
227
143
|
let data = '';
|
|
228
144
|
if (res.statusCode !== 200) {
|
|
229
145
|
clearTimeout(timeoutId);
|
|
230
|
-
res.resume();
|
|
146
|
+
res.resume();
|
|
231
147
|
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
232
148
|
return;
|
|
233
149
|
}
|
|
@@ -245,18 +161,12 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
|
245
161
|
}
|
|
246
162
|
});
|
|
247
163
|
});
|
|
248
|
-
// istanbul ignore next
|
|
249
164
|
req.on('error', (error) => {
|
|
250
165
|
clearTimeout(timeoutId);
|
|
251
166
|
reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
|
|
252
167
|
});
|
|
253
168
|
});
|
|
254
169
|
}
|
|
255
|
-
/**
|
|
256
|
-
* Retrieves the path to the global Node.js modules directory.
|
|
257
|
-
*
|
|
258
|
-
* @returns {Promise<string>} A promise that resolves to the path of the global Node.js modules directory.
|
|
259
|
-
*/
|
|
260
170
|
export async function getGlobalNodeModules() {
|
|
261
171
|
const { exec } = await import('node:child_process');
|
|
262
172
|
return new Promise((resolve, reject) => {
|
|
@@ -270,12 +180,6 @@ export async function getGlobalNodeModules() {
|
|
|
270
180
|
});
|
|
271
181
|
});
|
|
272
182
|
}
|
|
273
|
-
/**
|
|
274
|
-
* Function to format bytes to KB, MB, or GB
|
|
275
|
-
*
|
|
276
|
-
* @param {number} bytes - The number of bytes to format
|
|
277
|
-
* @returns {string} The formatted memory usage string
|
|
278
|
-
*/
|
|
279
183
|
export function formatMemoryUsage(bytes) {
|
|
280
184
|
if (bytes >= 1024 ** 3) {
|
|
281
185
|
return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
|
|
@@ -287,12 +191,6 @@ export function formatMemoryUsage(bytes) {
|
|
|
287
191
|
return `${(bytes / 1024).toFixed(2)} KB`;
|
|
288
192
|
}
|
|
289
193
|
}
|
|
290
|
-
/**
|
|
291
|
-
* Function to format system uptime with only the most significant unit
|
|
292
|
-
*
|
|
293
|
-
* @param {number} seconds - The number of seconds to format
|
|
294
|
-
* @returns {string} The formatted uptime string
|
|
295
|
-
*/
|
|
296
194
|
export function formatOsUpTime(seconds) {
|
|
297
195
|
if (seconds >= 86400) {
|
|
298
196
|
const days = Math.floor(seconds / 86400);
|
|
@@ -308,4 +206,3 @@ export function formatOsUpTime(seconds) {
|
|
|
308
206
|
}
|
|
309
207
|
return `${seconds} second${seconds !== 1 ? 's' : ''}`;
|
|
310
208
|
}
|
|
311
|
-
//# sourceMappingURL=network.js.map
|
package/dist/utils/spawn.js
CHANGED
|
@@ -1,52 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description This file contains the spawn functions.
|
|
3
|
-
* @file spawn.ts
|
|
4
|
-
* @author Luca Liguori
|
|
5
|
-
* @created 2025-02-16
|
|
6
|
-
* @version 1.1.0
|
|
7
|
-
* @license Apache-2.0
|
|
8
|
-
*
|
|
9
|
-
* Copyright 2025, 2026, 2027 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
1
|
import { hasParameter } from './commandLine.js';
|
|
24
|
-
/**
|
|
25
|
-
* Spawns a child process with the given command and arguments.
|
|
26
|
-
*
|
|
27
|
-
* @param {Matterbridge} matterbridge - The Matterbridge instance to use for logging and sending messages.
|
|
28
|
-
* @param {string} command - The command to execute.
|
|
29
|
-
* @param {string[]} args - The arguments to pass to the command (default: []).
|
|
30
|
-
* @param {'install' | 'uninstall'} packageCommand - The package command being executed (e.g., 'install', 'uninstall').
|
|
31
|
-
* @param {string} [packageName] - The name of the package being installed (optional).
|
|
32
|
-
* @returns {Promise<boolean>} A promise that resolves when the child process exits successfully, or rejects if there is an error.
|
|
33
|
-
*/
|
|
34
2
|
export async function spawnCommand(matterbridge, command, args, packageCommand, packageName) {
|
|
35
3
|
const { spawn } = await import('node:child_process');
|
|
36
|
-
/*
|
|
37
|
-
* npm > npm.cmd on windows
|
|
38
|
-
* cmd.exe ['dir'] on windows
|
|
39
|
-
*/
|
|
40
4
|
const cmdLine = command + ' ' + args.join(' ');
|
|
41
5
|
if (process.platform === 'win32' && command === 'npm') {
|
|
42
|
-
// Must be spawn('cmd.exe', ['/c', 'npm -g install <package>']);
|
|
43
6
|
const argstring = 'npm ' + args.join(' ');
|
|
44
7
|
args.splice(0, args.length, '/c', argstring);
|
|
45
8
|
command = 'cmd.exe';
|
|
46
9
|
}
|
|
47
|
-
// Decide when using sudo on linux and macOS
|
|
48
|
-
// When you need sudo: Spawn stderr: npm error Error: EACCES: permission denied
|
|
49
|
-
// When you don't need sudo: Failed to start child process "npm install -g matterbridge-eve-door": spawn sudo ENOENT
|
|
50
10
|
if (hasParameter('sudo') || (process.platform !== 'win32' && command === 'npm' && !hasParameter('docker') && !hasParameter('nosudo'))) {
|
|
51
11
|
args.unshift(command);
|
|
52
12
|
command = 'sudo';
|
|
@@ -66,7 +26,6 @@ export async function spawnCommand(matterbridge, command, args, packageCommand,
|
|
|
66
26
|
reject(err);
|
|
67
27
|
});
|
|
68
28
|
childProcess.on('close', (code, signal) => {
|
|
69
|
-
// matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', `child process closed with code ${code} and signal ${signal}`);
|
|
70
29
|
if (code === 0) {
|
|
71
30
|
matterbridge.log.debug(`Child process "${cmdLine}" closed with code ${code} and signal ${signal}`);
|
|
72
31
|
matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn-exit-success', 'Child process closed');
|
|
@@ -79,7 +38,6 @@ export async function spawnCommand(matterbridge, command, args, packageCommand,
|
|
|
79
38
|
}
|
|
80
39
|
});
|
|
81
40
|
childProcess.on('exit', (code, signal) => {
|
|
82
|
-
// matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', `child process exited with code ${code} and signal ${signal}`);
|
|
83
41
|
if (code === 0) {
|
|
84
42
|
matterbridge.log.debug(`Child process "${cmdLine}" exited with code ${code} and signal ${signal}`);
|
|
85
43
|
matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn-exit-success', 'Child process exited');
|
|
@@ -104,20 +62,6 @@ export async function spawnCommand(matterbridge, command, args, packageCommand,
|
|
|
104
62
|
matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', line);
|
|
105
63
|
}
|
|
106
64
|
});
|
|
107
|
-
/*
|
|
108
|
-
childProcess.stdout.on('close', () => {
|
|
109
|
-
matterbridge.log.debug(`Spawn output (stdout): closed`);
|
|
110
|
-
resolve(true);
|
|
111
|
-
});
|
|
112
|
-
childProcess.stdout.on('end', () => {
|
|
113
|
-
matterbridge.log.debug(`Spawn output (stdout): ended`);
|
|
114
|
-
resolve(true);
|
|
115
|
-
});
|
|
116
|
-
childProcess.stdout.on('error', () => {
|
|
117
|
-
matterbridge.log.debug(`Spawn output (stdout): error`);
|
|
118
|
-
resolve(true);
|
|
119
|
-
});
|
|
120
|
-
*/
|
|
121
65
|
}
|
|
122
66
|
if (childProcess.stderr) {
|
|
123
67
|
childProcess.stderr.on('data', (data) => {
|
|
@@ -128,21 +72,6 @@ export async function spawnCommand(matterbridge, command, args, packageCommand,
|
|
|
128
72
|
matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', line);
|
|
129
73
|
}
|
|
130
74
|
});
|
|
131
|
-
/*
|
|
132
|
-
childProcess.stderr.on('close', () => {
|
|
133
|
-
matterbridge.log.debug(`Spawn verbose (stderr): closed`);
|
|
134
|
-
resolve(true);
|
|
135
|
-
});
|
|
136
|
-
childProcess.stderr.on('end', () => {
|
|
137
|
-
matterbridge.log.debug(`Spawn verbose (stderr): ended`);
|
|
138
|
-
resolve(true);
|
|
139
|
-
});
|
|
140
|
-
childProcess.stderr.on('error', () => {
|
|
141
|
-
matterbridge.log.debug(`Spawn verbose (stderr): error`);
|
|
142
|
-
resolve(true);
|
|
143
|
-
});
|
|
144
|
-
*/
|
|
145
75
|
}
|
|
146
76
|
});
|
|
147
77
|
}
|
|
148
|
-
//# sourceMappingURL=spawn.js.map
|