matterbridge 3.3.7-dev-20251109-a306ab9 → 3.3.7
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/dist/broadcastServer.d.ts +115 -0
- package/dist/broadcastServer.d.ts.map +1 -0
- package/dist/broadcastServer.js +93 -1
- package/dist/broadcastServer.js.map +1 -0
- package/dist/broadcastServerTypes.d.ts +806 -0
- package/dist/broadcastServerTypes.d.ts.map +1 -0
- package/dist/broadcastServerTypes.js +24 -0
- package/dist/broadcastServerTypes.js.map +1 -0
- package/dist/cli.d.ts +30 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +97 -1
- package/dist/cli.js.map +1 -0
- package/dist/cliEmitter.d.ts +50 -0
- package/dist/cliEmitter.d.ts.map +1 -0
- package/dist/cliEmitter.js +37 -0
- package/dist/cliEmitter.js.map +1 -0
- package/dist/cliHistory.d.ts +48 -0
- package/dist/cliHistory.d.ts.map +1 -0
- package/dist/cliHistory.js +38 -0
- package/dist/cliHistory.js.map +1 -0
- package/dist/clusters/export.d.ts +2 -0
- package/dist/clusters/export.d.ts.map +1 -0
- package/dist/clusters/export.js +2 -0
- package/dist/clusters/export.js.map +1 -0
- package/dist/defaultConfigSchema.d.ts +28 -0
- package/dist/defaultConfigSchema.d.ts.map +1 -0
- package/dist/defaultConfigSchema.js +24 -0
- package/dist/defaultConfigSchema.js.map +1 -0
- package/dist/deviceManager.d.ts +128 -0
- package/dist/deviceManager.d.ts.map +1 -0
- package/dist/deviceManager.js +105 -1
- package/dist/deviceManager.js.map +1 -0
- package/dist/devices/airConditioner.d.ts +98 -0
- package/dist/devices/airConditioner.d.ts.map +1 -0
- package/dist/devices/airConditioner.js +57 -0
- package/dist/devices/airConditioner.js.map +1 -0
- package/dist/devices/batteryStorage.d.ts +48 -0
- package/dist/devices/batteryStorage.d.ts.map +1 -0
- package/dist/devices/batteryStorage.js +48 -1
- package/dist/devices/batteryStorage.js.map +1 -0
- package/dist/devices/cooktop.d.ts +60 -0
- package/dist/devices/cooktop.d.ts.map +1 -0
- package/dist/devices/cooktop.js +55 -0
- package/dist/devices/cooktop.js.map +1 -0
- package/dist/devices/dishwasher.d.ts +71 -0
- package/dist/devices/dishwasher.d.ts.map +1 -0
- package/dist/devices/dishwasher.js +57 -0
- package/dist/devices/dishwasher.js.map +1 -0
- package/dist/devices/evse.d.ts +76 -0
- package/dist/devices/evse.d.ts.map +1 -0
- package/dist/devices/evse.js +74 -10
- package/dist/devices/evse.js.map +1 -0
- package/dist/devices/export.d.ts +17 -0
- package/dist/devices/export.d.ts.map +1 -0
- package/dist/devices/export.js +5 -0
- package/dist/devices/export.js.map +1 -0
- package/dist/devices/extractorHood.d.ts +46 -0
- package/dist/devices/extractorHood.d.ts.map +1 -0
- package/dist/devices/extractorHood.js +42 -0
- package/dist/devices/extractorHood.js.map +1 -0
- package/dist/devices/heatPump.d.ts +47 -0
- package/dist/devices/heatPump.d.ts.map +1 -0
- package/dist/devices/heatPump.js +50 -2
- package/dist/devices/heatPump.js.map +1 -0
- package/dist/devices/laundryDryer.d.ts +67 -0
- package/dist/devices/laundryDryer.d.ts.map +1 -0
- package/dist/devices/laundryDryer.js +62 -3
- package/dist/devices/laundryDryer.js.map +1 -0
- package/dist/devices/laundryWasher.d.ts +81 -0
- package/dist/devices/laundryWasher.d.ts.map +1 -0
- package/dist/devices/laundryWasher.js +70 -4
- package/dist/devices/laundryWasher.js.map +1 -0
- package/dist/devices/microwaveOven.d.ts +168 -0
- package/dist/devices/microwaveOven.d.ts.map +1 -0
- package/dist/devices/microwaveOven.js +88 -5
- package/dist/devices/microwaveOven.js.map +1 -0
- package/dist/devices/oven.d.ts +105 -0
- package/dist/devices/oven.d.ts.map +1 -0
- package/dist/devices/oven.js +85 -0
- package/dist/devices/oven.js.map +1 -0
- package/dist/devices/refrigerator.d.ts +118 -0
- package/dist/devices/refrigerator.d.ts.map +1 -0
- package/dist/devices/refrigerator.js +102 -0
- package/dist/devices/refrigerator.js.map +1 -0
- package/dist/devices/roboticVacuumCleaner.d.ts +112 -0
- package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
- package/dist/devices/roboticVacuumCleaner.js +100 -9
- package/dist/devices/roboticVacuumCleaner.js.map +1 -0
- package/dist/devices/solarPower.d.ts +40 -0
- package/dist/devices/solarPower.d.ts.map +1 -0
- package/dist/devices/solarPower.js +38 -0
- package/dist/devices/solarPower.js.map +1 -0
- package/dist/devices/speaker.d.ts +87 -0
- package/dist/devices/speaker.d.ts.map +1 -0
- package/dist/devices/speaker.js +84 -0
- package/dist/devices/speaker.js.map +1 -0
- package/dist/devices/temperatureControl.d.ts +166 -0
- package/dist/devices/temperatureControl.d.ts.map +1 -0
- package/dist/devices/temperatureControl.js +24 -3
- package/dist/devices/temperatureControl.js.map +1 -0
- package/dist/devices/waterHeater.d.ts +111 -0
- package/dist/devices/waterHeater.d.ts.map +1 -0
- package/dist/devices/waterHeater.js +82 -2
- package/dist/devices/waterHeater.js.map +1 -0
- package/dist/dgram/coap.d.ts +205 -0
- package/dist/dgram/coap.d.ts.map +1 -0
- package/dist/dgram/coap.js +126 -13
- package/dist/dgram/coap.js.map +1 -0
- package/dist/dgram/dgram.d.ts +141 -0
- package/dist/dgram/dgram.d.ts.map +1 -0
- package/dist/dgram/dgram.js +114 -2
- package/dist/dgram/dgram.js.map +1 -0
- package/dist/dgram/mb_coap.d.ts +24 -0
- package/dist/dgram/mb_coap.d.ts.map +1 -0
- package/dist/dgram/mb_coap.js +41 -3
- package/dist/dgram/mb_coap.js.map +1 -0
- package/dist/dgram/mb_mdns.d.ts +24 -0
- package/dist/dgram/mb_mdns.d.ts.map +1 -0
- package/dist/dgram/mb_mdns.js +80 -15
- package/dist/dgram/mb_mdns.js.map +1 -0
- package/dist/dgram/mdns.d.ts +290 -0
- package/dist/dgram/mdns.d.ts.map +1 -0
- package/dist/dgram/mdns.js +299 -137
- package/dist/dgram/mdns.js.map +1 -0
- package/dist/dgram/multicast.d.ts +67 -0
- package/dist/dgram/multicast.d.ts.map +1 -0
- package/dist/dgram/multicast.js +62 -1
- package/dist/dgram/multicast.js.map +1 -0
- package/dist/dgram/unicast.d.ts +56 -0
- package/dist/dgram/unicast.d.ts.map +1 -0
- package/dist/dgram/unicast.js +54 -0
- package/dist/dgram/unicast.js.map +1 -0
- package/dist/frontend.d.ts +238 -0
- package/dist/frontend.d.ts.map +1 -0
- package/dist/frontend.js +451 -35
- package/dist/frontend.js.map +1 -0
- package/dist/frontendTypes.d.ts +529 -0
- package/dist/frontendTypes.d.ts.map +1 -0
- package/dist/frontendTypes.js +45 -0
- package/dist/frontendTypes.js.map +1 -0
- package/dist/helpers.d.ts +48 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +53 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/export.d.ts +2 -0
- package/dist/logger/export.d.ts.map +1 -0
- package/dist/logger/export.js +1 -0
- package/dist/logger/export.js.map +1 -0
- package/dist/matter/behaviors.d.ts +2 -0
- package/dist/matter/behaviors.d.ts.map +1 -0
- package/dist/matter/behaviors.js +2 -0
- package/dist/matter/behaviors.js.map +1 -0
- package/dist/matter/clusters.d.ts +2 -0
- package/dist/matter/clusters.d.ts.map +1 -0
- package/dist/matter/clusters.js +2 -0
- package/dist/matter/clusters.js.map +1 -0
- package/dist/matter/devices.d.ts +2 -0
- package/dist/matter/devices.d.ts.map +1 -0
- package/dist/matter/devices.js +2 -0
- package/dist/matter/devices.js.map +1 -0
- package/dist/matter/endpoints.d.ts +2 -0
- package/dist/matter/endpoints.d.ts.map +1 -0
- package/dist/matter/endpoints.js +2 -0
- package/dist/matter/endpoints.js.map +1 -0
- package/dist/matter/export.d.ts +5 -0
- package/dist/matter/export.d.ts.map +1 -0
- package/dist/matter/export.js +3 -0
- package/dist/matter/export.js.map +1 -0
- package/dist/matter/types.d.ts +3 -0
- package/dist/matter/types.d.ts.map +1 -0
- package/dist/matter/types.js +3 -0
- package/dist/matter/types.js.map +1 -0
- package/dist/matterbridge.d.ts +478 -0
- package/dist/matterbridge.d.ts.map +1 -0
- package/dist/matterbridge.js +828 -46
- package/dist/matterbridge.js.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts +42 -0
- package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
- package/dist/matterbridgeAccessoryPlatform.js +37 -0
- package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
- package/dist/matterbridgeBehaviors.d.ts +2404 -0
- package/dist/matterbridgeBehaviors.d.ts.map +1 -0
- package/dist/matterbridgeBehaviors.js +68 -5
- package/dist/matterbridgeBehaviors.js.map +1 -0
- package/dist/matterbridgeDeviceTypes.d.ts +770 -0
- package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
- package/dist/matterbridgeDeviceTypes.js +638 -17
- package/dist/matterbridgeDeviceTypes.js.map +1 -0
- package/dist/matterbridgeDynamicPlatform.d.ts +42 -0
- package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
- package/dist/matterbridgeDynamicPlatform.js +37 -0
- package/dist/matterbridgeDynamicPlatform.js.map +1 -0
- package/dist/matterbridgeEndpoint.d.ts +1556 -0
- package/dist/matterbridgeEndpoint.d.ts.map +1 -0
- package/dist/matterbridgeEndpoint.js +1408 -52
- package/dist/matterbridgeEndpoint.js.map +1 -0
- package/dist/matterbridgeEndpointHelpers.d.ts +758 -0
- package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
- package/dist/matterbridgeEndpointHelpers.js +464 -19
- package/dist/matterbridgeEndpointHelpers.js.map +1 -0
- package/dist/matterbridgePlatform.d.ts +402 -0
- package/dist/matterbridgePlatform.d.ts.map +1 -0
- package/dist/matterbridgePlatform.js +341 -1
- package/dist/matterbridgePlatform.js.map +1 -0
- package/dist/matterbridgeTypes.d.ts +239 -0
- package/dist/matterbridgeTypes.d.ts.map +1 -0
- package/dist/matterbridgeTypes.js +26 -0
- package/dist/matterbridgeTypes.js.map +1 -0
- package/dist/pluginManager.d.ts +371 -0
- package/dist/pluginManager.d.ts.map +1 -0
- package/dist/pluginManager.js +339 -4
- package/dist/pluginManager.js.map +1 -0
- package/dist/shelly.d.ts +174 -0
- package/dist/shelly.d.ts.map +1 -0
- package/dist/shelly.js +168 -7
- package/dist/shelly.js.map +1 -0
- package/dist/storage/export.d.ts +2 -0
- package/dist/storage/export.d.ts.map +1 -0
- package/dist/storage/export.js +1 -0
- package/dist/storage/export.js.map +1 -0
- package/dist/update.d.ts +75 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +69 -0
- package/dist/update.js.map +1 -0
- package/dist/utils/colorUtils.d.ts +101 -0
- package/dist/utils/colorUtils.d.ts.map +1 -0
- package/dist/utils/colorUtils.js +97 -2
- package/dist/utils/colorUtils.js.map +1 -0
- package/dist/utils/commandLine.d.ts +66 -0
- package/dist/utils/commandLine.d.ts.map +1 -0
- package/dist/utils/commandLine.js +60 -0
- package/dist/utils/commandLine.js.map +1 -0
- package/dist/utils/copyDirectory.d.ts +33 -0
- package/dist/utils/copyDirectory.d.ts.map +1 -0
- package/dist/utils/copyDirectory.js +38 -1
- package/dist/utils/copyDirectory.js.map +1 -0
- package/dist/utils/createDirectory.d.ts +34 -0
- package/dist/utils/createDirectory.d.ts.map +1 -0
- package/dist/utils/createDirectory.js +33 -0
- package/dist/utils/createDirectory.js.map +1 -0
- package/dist/utils/createZip.d.ts +39 -0
- package/dist/utils/createZip.d.ts.map +1 -0
- package/dist/utils/createZip.js +47 -2
- package/dist/utils/createZip.js.map +1 -0
- package/dist/utils/deepCopy.d.ts +32 -0
- package/dist/utils/deepCopy.d.ts.map +1 -0
- package/dist/utils/deepCopy.js +39 -0
- package/dist/utils/deepCopy.js.map +1 -0
- package/dist/utils/deepEqual.d.ts +54 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/deepEqual.js +72 -1
- package/dist/utils/deepEqual.js.map +1 -0
- package/dist/utils/error.d.ts +44 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +41 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/export.d.ts +13 -0
- package/dist/utils/export.d.ts.map +1 -0
- package/dist/utils/export.js +1 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/format.d.ts +53 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +49 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/hex.d.ts +89 -0
- package/dist/utils/hex.d.ts.map +1 -0
- package/dist/utils/hex.js +124 -0
- package/dist/utils/hex.js.map +1 -0
- package/dist/utils/inspector.d.ts +87 -0
- package/dist/utils/inspector.d.ts.map +1 -0
- package/dist/utils/inspector.js +69 -1
- package/dist/utils/inspector.js.map +1 -0
- package/dist/utils/isvalid.d.ts +103 -0
- package/dist/utils/isvalid.d.ts.map +1 -0
- package/dist/utils/isvalid.js +101 -0
- package/dist/utils/isvalid.js.map +1 -0
- package/dist/utils/jestHelpers.d.ts +139 -0
- package/dist/utils/jestHelpers.d.ts.map +1 -0
- package/dist/utils/jestHelpers.js +153 -3
- package/dist/utils/jestHelpers.js.map +1 -0
- package/dist/utils/network.d.ts +101 -0
- package/dist/utils/network.d.ts.map +1 -0
- package/dist/utils/network.js +96 -5
- package/dist/utils/network.js.map +1 -0
- package/dist/utils/spawn.d.ts +35 -0
- package/dist/utils/spawn.d.ts.map +1 -0
- package/dist/utils/spawn.js +71 -0
- package/dist/utils/spawn.js.map +1 -0
- package/dist/utils/tracker.d.ts +108 -0
- package/dist/utils/tracker.d.ts.map +1 -0
- package/dist/utils/tracker.js +64 -1
- package/dist/utils/tracker.js.map +1 -0
- package/dist/utils/wait.d.ts +54 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +60 -8
- package/dist/utils/wait.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
/**
|
|
24
|
+
* Retrieves the first non-internal network interface details.
|
|
25
|
+
*
|
|
26
|
+
* @returns {os.NetworkInterfaceInfo | undefined} The details of the selected network interface, or undefined if not found.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getInterfaceDetails(): {
|
|
29
|
+
interfaceName: string;
|
|
30
|
+
ipv4Address: string | undefined;
|
|
31
|
+
ipv6Address: string | undefined;
|
|
32
|
+
macAddress: string | undefined;
|
|
33
|
+
} | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves the first non-internal network interface name.
|
|
36
|
+
*
|
|
37
|
+
* @returns {string | undefined} The name of the selected network interface, or undefined if not found.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getInterfaceName(): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves the IPv4 address of the first non-internal network interface.
|
|
42
|
+
*
|
|
43
|
+
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getIpv4InterfaceAddress(): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Retrieves the IPv6 address of the first non-internal network interface.
|
|
48
|
+
*
|
|
49
|
+
* @returns {string | undefined} The IPv4 address of the selected network interface, or undefined if not found.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getIpv6InterfaceAddress(): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the mac address of the first non-internal network interface.
|
|
54
|
+
*
|
|
55
|
+
* @returns {string | undefined} The mac address, or undefined if not found.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getMacAddress(): string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Logs the available network interfaces and their details.
|
|
60
|
+
*
|
|
61
|
+
* @returns {void}
|
|
62
|
+
*/
|
|
63
|
+
export declare function logInterfaces(): void;
|
|
64
|
+
/**
|
|
65
|
+
* Resolves the given hostname to an IP address.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} hostname - The hostname to resolve.
|
|
68
|
+
* @param {0 | 4 | 6} [family] - The address family to use (0 for any, 4 for IPv4, 6 for IPv6). Default is 4.
|
|
69
|
+
* @returns {Promise<string | null>} - A promise that resolves to the IP address or null if not found.
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* This function uses DNS lookup to resolve the hostname, which can take some time to complete.
|
|
73
|
+
*/
|
|
74
|
+
export declare function resolveHostname(hostname: string, family?: 0 | 4 | 6): Promise<string | null>;
|
|
75
|
+
/**
|
|
76
|
+
* Retrieves the version of an npm package from the npm registry.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} packageName - The name of the npm package.
|
|
79
|
+
* @param {string} [tag] - The tag of the package version to retrieve (default is 'latest').
|
|
80
|
+
* @param {number} [timeout] - The timeout duration in milliseconds (default is 10000ms).
|
|
81
|
+
* @returns {Promise<string>} A promise that resolves to the version string of the package.
|
|
82
|
+
* @throws {Error} If the request fails or the tag is not found.
|
|
83
|
+
*/
|
|
84
|
+
export declare function getNpmPackageVersion(packageName: string, tag?: string, timeout?: number): Promise<string>;
|
|
85
|
+
/**
|
|
86
|
+
* Retrieves a file from the public directory of the Matterbridge GitHub repository.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} branch - The branch from which to fetch the file.
|
|
89
|
+
* @param {string} file - The file path to fetch.
|
|
90
|
+
* @param {number} [timeout] - The timeout duration in milliseconds (default is 10000ms).
|
|
91
|
+
* @returns {Promise<Record<string, boolean | string | number>>} A promise that resolves to the parsed JSON object from the file.
|
|
92
|
+
* @throws {Error} If the request fails or the JSON parsing fails.
|
|
93
|
+
*/
|
|
94
|
+
export declare function getGitHubUpdate(branch: 'main' | 'dev', file: string, timeout?: number): Promise<Record<string, boolean | string | number>>;
|
|
95
|
+
/**
|
|
96
|
+
* Retrieves the path to the global Node.js modules directory.
|
|
97
|
+
*
|
|
98
|
+
* @returns {Promise<string>} A promise that resolves to the path of the global Node.js modules directory.
|
|
99
|
+
*/
|
|
100
|
+
export declare function getGlobalNodeModules(): Promise<string>;
|
|
101
|
+
//# sourceMappingURL=network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAUH;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAAG,SAAS,CAa7K;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,GAAG,SAAS,CAOrD;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,SAAS,CAO5D;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,SAAS,CAO5D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,GAAG,SAAS,CAOlD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAmBpC;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAE,CAAC,GAAG,CAAC,GAAG,CAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CASrG;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,GAAE,MAAiB,EAAE,OAAO,GAAE,MAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CA8ChI;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,MAAc,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC,CAyCvJ;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAW5D"}
|
package/dist/utils/network.js
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
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
|
|
1
24
|
import os from 'node:os';
|
|
25
|
+
// AnsiLogger module
|
|
2
26
|
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
|
+
*/
|
|
3
32
|
export function getInterfaceDetails() {
|
|
4
33
|
const result = { interfaceName: '', ipv4Address: undefined, ipv6Address: undefined, macAddress: undefined };
|
|
5
34
|
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
@@ -21,6 +50,11 @@ export function getInterfaceDetails() {
|
|
|
21
50
|
if (result.interfaceName)
|
|
22
51
|
return result;
|
|
23
52
|
}
|
|
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
|
+
*/
|
|
24
58
|
export function getInterfaceName() {
|
|
25
59
|
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
26
60
|
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
@@ -31,6 +65,11 @@ export function getInterfaceName() {
|
|
|
31
65
|
}
|
|
32
66
|
}
|
|
33
67
|
}
|
|
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
|
+
*/
|
|
34
73
|
export function getIpv4InterfaceAddress() {
|
|
35
74
|
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
36
75
|
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
@@ -41,6 +80,11 @@ export function getIpv4InterfaceAddress() {
|
|
|
41
80
|
}
|
|
42
81
|
}
|
|
43
82
|
}
|
|
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
|
+
*/
|
|
44
88
|
export function getIpv6InterfaceAddress() {
|
|
45
89
|
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
46
90
|
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
@@ -51,6 +95,11 @@ export function getIpv6InterfaceAddress() {
|
|
|
51
95
|
}
|
|
52
96
|
}
|
|
53
97
|
}
|
|
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
|
+
*/
|
|
54
103
|
export function getMacAddress() {
|
|
55
104
|
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
56
105
|
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
@@ -61,9 +110,14 @@ export function getMacAddress() {
|
|
|
61
110
|
}
|
|
62
111
|
}
|
|
63
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Logs the available network interfaces and their details.
|
|
115
|
+
*
|
|
116
|
+
* @returns {void}
|
|
117
|
+
*/
|
|
64
118
|
export function logInterfaces() {
|
|
65
|
-
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4
|
|
66
|
-
log.logLevel = "info"
|
|
119
|
+
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4 /* TimestampFormat.TIME_MILLIS */, logLevel: "info" /* LogLevel.INFO */ });
|
|
120
|
+
log.logLevel = "info" /* LogLevel.INFO */;
|
|
67
121
|
log.logName = 'LogInterfaces';
|
|
68
122
|
log.info('Available Network Interfaces:');
|
|
69
123
|
const availableAddresses = Object.entries(os.networkInterfaces());
|
|
@@ -77,16 +131,36 @@ export function logInterfaces() {
|
|
|
77
131
|
}
|
|
78
132
|
}
|
|
79
133
|
}
|
|
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
|
+
*/
|
|
80
144
|
export async function resolveHostname(hostname, family = 4) {
|
|
81
145
|
const dns = await import('node:dns');
|
|
82
146
|
try {
|
|
83
|
-
const addresses = await dns.promises.lookup(hostname.toLowerCase()
|
|
147
|
+
const addresses = await dns.promises.lookup(hostname.toLowerCase() /* + '.local'*/, { family });
|
|
84
148
|
return addresses.address;
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
85
150
|
}
|
|
86
151
|
catch (error) {
|
|
87
152
|
return null;
|
|
88
153
|
}
|
|
89
154
|
}
|
|
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
|
+
*/
|
|
90
164
|
export async function getNpmPackageVersion(packageName, tag = 'latest', timeout = 10000) {
|
|
91
165
|
const https = await import('node:https');
|
|
92
166
|
return new Promise((resolve, reject) => {
|
|
@@ -100,7 +174,7 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
100
174
|
let data = '';
|
|
101
175
|
if (res.statusCode !== 200) {
|
|
102
176
|
clearTimeout(timeoutId);
|
|
103
|
-
res.resume();
|
|
177
|
+
res.resume(); // Discard response data to close the socket properly
|
|
104
178
|
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
105
179
|
return;
|
|
106
180
|
}
|
|
@@ -111,6 +185,7 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
111
185
|
clearTimeout(timeoutId);
|
|
112
186
|
try {
|
|
113
187
|
const jsonData = JSON.parse(data);
|
|
188
|
+
// console.log(`Package ${packageName} tag ${tag}`, jsonData);
|
|
114
189
|
const version = jsonData['dist-tags']?.[tag];
|
|
115
190
|
if (version) {
|
|
116
191
|
resolve(version);
|
|
@@ -130,6 +205,15 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
130
205
|
});
|
|
131
206
|
});
|
|
132
207
|
}
|
|
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
|
+
*/
|
|
133
217
|
export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
134
218
|
const https = await import('node:https');
|
|
135
219
|
return new Promise((resolve, reject) => {
|
|
@@ -143,7 +227,7 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
|
143
227
|
let data = '';
|
|
144
228
|
if (res.statusCode !== 200) {
|
|
145
229
|
clearTimeout(timeoutId);
|
|
146
|
-
res.resume();
|
|
230
|
+
res.resume(); // Discard response data to close the socket properly
|
|
147
231
|
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
148
232
|
return;
|
|
149
233
|
}
|
|
@@ -161,12 +245,18 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
|
161
245
|
}
|
|
162
246
|
});
|
|
163
247
|
});
|
|
248
|
+
// istanbul ignore next
|
|
164
249
|
req.on('error', (error) => {
|
|
165
250
|
clearTimeout(timeoutId);
|
|
166
251
|
reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
|
|
167
252
|
});
|
|
168
253
|
});
|
|
169
254
|
}
|
|
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
|
+
*/
|
|
170
260
|
export async function getGlobalNodeModules() {
|
|
171
261
|
const { exec } = await import('node:child_process');
|
|
172
262
|
return new Promise((resolve, reject) => {
|
|
@@ -180,3 +270,4 @@ export async function getGlobalNodeModules() {
|
|
|
180
270
|
});
|
|
181
271
|
});
|
|
182
272
|
}
|
|
273
|
+
//# sourceMappingURL=network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.js","sourceRoot":"","sources":["../../src/utils/network.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,kBAAkB;AAClB,OAAO,EAAE,MAAM,SAAS,CAAC;AAIzB,oBAAoB;AACpB,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAY,EAAE,EAAmB,MAAM,kBAAkB,CAAC;AAEzF;;;;GAIG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,MAAM,GAAgI,EAAE,aAAa,EAAE,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,S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,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,IAAI,CAAC,aAAa,EAAE,CAAC,KAA2B,EAAE,MAAc,EAAE,EAAE;YAClE,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;YACzB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
import type { Matterbridge } from '../matterbridge.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
|
+
export declare function spawnCommand(matterbridge: Matterbridge, command: string, args: string[], packageCommand: 'install' | 'uninstall', packageName: string): Promise<boolean>;
|
|
35
|
+
//# sourceMappingURL=spawn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../../src/utils/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,cAAc,EAAE,SAAS,GAAG,WAAW,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAqH9K"}
|
package/dist/utils/spawn.js
CHANGED
|
@@ -1,12 +1,52 @@
|
|
|
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
|
+
*/
|
|
1
23
|
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
|
+
*/
|
|
2
34
|
export async function spawnCommand(matterbridge, command, args, packageCommand, packageName) {
|
|
3
35
|
const { spawn } = await import('node:child_process');
|
|
36
|
+
/*
|
|
37
|
+
* npm > npm.cmd on windows
|
|
38
|
+
* cmd.exe ['dir'] on windows
|
|
39
|
+
*/
|
|
4
40
|
const cmdLine = command + ' ' + args.join(' ');
|
|
5
41
|
if (process.platform === 'win32' && command === 'npm') {
|
|
42
|
+
// Must be spawn('cmd.exe', ['/c', 'npm -g install <package>']);
|
|
6
43
|
const argstring = 'npm ' + args.join(' ');
|
|
7
44
|
args.splice(0, args.length, '/c', argstring);
|
|
8
45
|
command = 'cmd.exe';
|
|
9
46
|
}
|
|
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
|
|
10
50
|
if (hasParameter('sudo') || (process.platform !== 'win32' && command === 'npm' && !hasParameter('docker') && !hasParameter('nosudo'))) {
|
|
11
51
|
args.unshift(command);
|
|
12
52
|
command = 'sudo';
|
|
@@ -26,6 +66,7 @@ export async function spawnCommand(matterbridge, command, args, packageCommand,
|
|
|
26
66
|
reject(err);
|
|
27
67
|
});
|
|
28
68
|
childProcess.on('close', (code, signal) => {
|
|
69
|
+
// matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', `child process closed with code ${code} and signal ${signal}`);
|
|
29
70
|
if (code === 0) {
|
|
30
71
|
matterbridge.log.debug(`Child process "${cmdLine}" closed with code ${code} and signal ${signal}`);
|
|
31
72
|
matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn-exit-success', 'Child process closed');
|
|
@@ -38,6 +79,7 @@ export async function spawnCommand(matterbridge, command, args, packageCommand,
|
|
|
38
79
|
}
|
|
39
80
|
});
|
|
40
81
|
childProcess.on('exit', (code, signal) => {
|
|
82
|
+
// matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', `child process exited with code ${code} and signal ${signal}`);
|
|
41
83
|
if (code === 0) {
|
|
42
84
|
matterbridge.log.debug(`Child process "${cmdLine}" exited with code ${code} and signal ${signal}`);
|
|
43
85
|
matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn-exit-success', 'Child process exited');
|
|
@@ -62,6 +104,20 @@ export async function spawnCommand(matterbridge, command, args, packageCommand,
|
|
|
62
104
|
matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', line);
|
|
63
105
|
}
|
|
64
106
|
});
|
|
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
|
+
*/
|
|
65
121
|
}
|
|
66
122
|
if (childProcess.stderr) {
|
|
67
123
|
childProcess.stderr.on('data', (data) => {
|
|
@@ -72,6 +128,21 @@ export async function spawnCommand(matterbridge, command, args, packageCommand,
|
|
|
72
128
|
matterbridge.frontend.wssSendLogMessage('spawn', matterbridge.log.now(), 'Matterbridge:spawn', line);
|
|
73
129
|
}
|
|
74
130
|
});
|
|
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
|
+
*/
|
|
75
145
|
}
|
|
76
146
|
});
|
|
77
147
|
}
|
|
148
|
+
//# sourceMappingURL=spawn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.js","sourceRoot":"","sources":["../../src/utils/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,YAA0B,EAAE,OAAe,EAAE,IAAc,EAAE,cAAuC,EAAE,WAAmB;IAC1J,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;IAErD;;;OAGG;IACH,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Liguori
|
|
6
|
+
* @created 2025-10-10
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
* @license Apache-2.0
|
|
9
|
+
*
|
|
10
|
+
* Copyright 2025, 2026, 2027 Luca Liguori.
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
import EventEmitter from 'node:events';
|
|
25
|
+
export type TrackerSnapshot = {
|
|
26
|
+
timestamp: number;
|
|
27
|
+
freeMemory: number;
|
|
28
|
+
peakFreeMemory: number;
|
|
29
|
+
totalMemory: number;
|
|
30
|
+
peakTotalMemory: number;
|
|
31
|
+
osCpu: number;
|
|
32
|
+
peakOsCpu: number;
|
|
33
|
+
processCpu: number;
|
|
34
|
+
peakProcessCpu: number;
|
|
35
|
+
rss: number;
|
|
36
|
+
peakRss: number;
|
|
37
|
+
heapUsed: number;
|
|
38
|
+
peakHeapUsed: number;
|
|
39
|
+
heapTotal: number;
|
|
40
|
+
peakHeapTotal: number;
|
|
41
|
+
external: number;
|
|
42
|
+
peakExternal: number;
|
|
43
|
+
arrayBuffers: number;
|
|
44
|
+
peakArrayBuffers: number;
|
|
45
|
+
};
|
|
46
|
+
interface TrackerEvents {
|
|
47
|
+
/** Start tracking */
|
|
48
|
+
start: [];
|
|
49
|
+
/** Stop tracking */
|
|
50
|
+
stop: [];
|
|
51
|
+
/** Uptime event */
|
|
52
|
+
uptime: [os: number, process: number];
|
|
53
|
+
/** CPU event */
|
|
54
|
+
cpu: [os: number, process: number];
|
|
55
|
+
/** Memory event */
|
|
56
|
+
memory: [free: number, total: number, rss: number, heapUsed: number, heapTotal: number, external: number, arrayBuffers: number];
|
|
57
|
+
/** Snapshot event */
|
|
58
|
+
snapshot: [snapshot: TrackerSnapshot];
|
|
59
|
+
/** Reset peaks */
|
|
60
|
+
reset_peaks: [];
|
|
61
|
+
/** Reset peaks done event */
|
|
62
|
+
reset_peaks_done: [];
|
|
63
|
+
/** Run garbage collection */
|
|
64
|
+
gc: [];
|
|
65
|
+
/** Garbage collection done event */
|
|
66
|
+
gc_done: [type: 'major' | 'minor', execution: 'sync' | 'async'];
|
|
67
|
+
}
|
|
68
|
+
export declare class Tracker extends EventEmitter<TrackerEvents> {
|
|
69
|
+
private readonly name;
|
|
70
|
+
private readonly debug;
|
|
71
|
+
private readonly verbose;
|
|
72
|
+
private trackerInterval?;
|
|
73
|
+
static historyIndex: number;
|
|
74
|
+
static readonly historySize = 2880;
|
|
75
|
+
static readonly history: TrackerSnapshot[];
|
|
76
|
+
private prevCpus;
|
|
77
|
+
private prevCpuUsage;
|
|
78
|
+
private log;
|
|
79
|
+
constructor(name?: string, debug?: boolean, verbose?: boolean);
|
|
80
|
+
/**
|
|
81
|
+
* Start tracking cpu and memory usage with a given interval in ms
|
|
82
|
+
*
|
|
83
|
+
* @param {number} sampleIntervalMs Sample interval in milliseconds. Default is 10000 (10 seconds).
|
|
84
|
+
*/
|
|
85
|
+
start(sampleIntervalMs?: number): void;
|
|
86
|
+
/**
|
|
87
|
+
* Reset peak values to the currently stored values
|
|
88
|
+
*/
|
|
89
|
+
resetPeaks(): void;
|
|
90
|
+
/**
|
|
91
|
+
* Manually trigger garbage collection to free memory (if exposed with --expose-gc)
|
|
92
|
+
*
|
|
93
|
+
* @param {'major' | 'minor'} type - The type of garbage collection to perform ('major' or 'minor'). Default is 'major'.
|
|
94
|
+
* @param {'sync' | 'async'} execution - The execution mode of garbage collection ('sync' or 'async'). Default is 'async'.
|
|
95
|
+
*
|
|
96
|
+
* @remarks
|
|
97
|
+
* - major collection refers to old-generation mark-sweep/mark-compact cycles.
|
|
98
|
+
* - minor collection refers to young-generation collections (scavenges).
|
|
99
|
+
* - sync execution blocks the main thread until GC is complete, which can cause pauses.
|
|
100
|
+
*/
|
|
101
|
+
runGarbageCollector(type?: 'major' | 'minor', execution?: 'sync' | 'async'): void;
|
|
102
|
+
/**
|
|
103
|
+
* Stop tracking, clear interval, log history
|
|
104
|
+
*/
|
|
105
|
+
stop(): void;
|
|
106
|
+
}
|
|
107
|
+
export {};
|
|
108
|
+
//# sourceMappingURL=tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../src/utils/tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAOH,OAAO,YAAY,MAAM,aAAa,CAAC;AAOvC,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAGF,UAAU,aAAa;IACrB,qBA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