matterbridge 3.2.6 → 3.2.7-dev-20250908-3bb699e
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 +20 -0
- package/dist/cli.js +2 -91
- package/dist/cliEmitter.js +0 -30
- package/dist/clusters/export.js +0 -2
- package/dist/defaultConfigSchema.js +3 -24
- package/dist/deviceManager.js +1 -94
- 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 -80
- 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 +24 -450
- package/dist/globalMatterbridge.js +0 -47
- package/dist/helpers.js +0 -53
- package/dist/index.js +1 -30
- package/dist/jest-utils/jestHelpers.js +2 -124
- 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 +49 -780
- package/dist/matterbridgeAccessoryPlatform.js +0 -36
- package/dist/matterbridgeBehaviors.js +5 -65
- package/dist/matterbridgeDeviceTypes.js +17 -630
- package/dist/matterbridgeDynamicPlatform.js +0 -36
- package/dist/matterbridgeEndpoint.js +54 -1301
- package/dist/matterbridgeEndpointHelpers.js +12 -345
- package/dist/matterbridgePlatform.js +1 -305
- package/dist/matterbridgeTypes.js +0 -25
- package/dist/pluginManager.js +5 -251
- 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 +0 -54
- 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/isvalid.js +0 -101
- package/dist/utils/network.js +6 -92
- package/dist/utils/spawn.js +0 -40
- package/dist/utils/wait.js +8 -60
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -2
- 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 -34
- package/dist/cliEmitter.d.ts.map +0 -1
- package/dist/cliEmitter.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 -112
- 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 -83
- 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 -313
- package/dist/frontend.d.ts.map +0 -1
- package/dist/frontend.js.map +0 -1
- package/dist/globalMatterbridge.d.ts +0 -59
- package/dist/globalMatterbridge.d.ts.map +0 -1
- package/dist/globalMatterbridge.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/jest-utils/jestHelpers.d.ts +0 -103
- package/dist/jest-utils/jestHelpers.d.ts.map +0 -1
- package/dist/jest-utils/jestHelpers.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 -457
- 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 -1351
- 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 -1438
- package/dist/matterbridgeEndpoint.d.ts.map +0 -1
- package/dist/matterbridgeEndpoint.js.map +0 -1
- package/dist/matterbridgeEndpointHelpers.d.ts +0 -407
- package/dist/matterbridgeEndpointHelpers.d.ts.map +0 -1
- package/dist/matterbridgeEndpointHelpers.js.map +0 -1
- package/dist/matterbridgePlatform.d.ts +0 -379
- package/dist/matterbridgePlatform.d.ts.map +0 -1
- package/dist/matterbridgePlatform.js.map +0 -1
- package/dist/matterbridgeTypes.d.ts +0 -198
- package/dist/matterbridgeTypes.d.ts.map +0 -1
- package/dist/matterbridgeTypes.js.map +0 -1
- package/dist/pluginManager.d.ts +0 -270
- 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/network.d.ts +0 -84
- package/dist/utils/network.d.ts.map +0 -1
- package/dist/utils/network.js.map +0 -1
- package/dist/utils/spawn.d.ts +0 -33
- 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
package/dist/frontend.js
CHANGED
|
@@ -1,126 +1,30 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file contains the class Frontend.
|
|
3
|
-
*
|
|
4
|
-
* @file frontend.ts
|
|
5
|
-
* @author Luca Liguori
|
|
6
|
-
* @created 2025-01-13
|
|
7
|
-
* @version 1.2.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
|
-
// Node modules
|
|
25
1
|
import { createServer } from 'node:http';
|
|
26
2
|
import https from 'node:https';
|
|
27
3
|
import os from 'node:os';
|
|
28
4
|
import path from 'node:path';
|
|
29
5
|
import { existsSync, promises as fs } from 'node:fs';
|
|
30
6
|
import EventEmitter from 'node:events';
|
|
31
|
-
// Third-party modules
|
|
32
7
|
import express from 'express';
|
|
33
8
|
import WebSocket, { WebSocketServer } from 'ws';
|
|
34
9
|
import multer from 'multer';
|
|
35
|
-
// AnsiLogger module
|
|
36
10
|
import { AnsiLogger, stringify, debugStringify, CYAN, db, er, nf, rs, UNDERLINE, UNDERLINEOFF, YELLOW, nt } from 'node-ansi-logger';
|
|
37
|
-
// @matter
|
|
38
11
|
import { Logger, LogLevel as MatterLogLevel, Lifecycle } from '@matter/main';
|
|
39
12
|
import { BridgedDeviceBasicInformation, PowerSource } from '@matter/main/clusters';
|
|
40
|
-
// Matterbridge
|
|
41
13
|
import { createZip, isValidArray, isValidNumber, isValidObject, isValidString, isValidBoolean, withTimeout, hasParameter } from './utils/export.js';
|
|
42
14
|
import { plg } from './matterbridgeTypes.js';
|
|
43
15
|
import { capitalizeFirstLetter, getAttribute } from './matterbridgeEndpointHelpers.js';
|
|
44
16
|
import { cliEmitter, lastCpuUsage } from './cliEmitter.js';
|
|
45
|
-
/**
|
|
46
|
-
* Websocket message ID for logging.
|
|
47
|
-
*
|
|
48
|
-
* @constant {number}
|
|
49
|
-
*/
|
|
50
17
|
export const WS_ID_LOG = 0;
|
|
51
|
-
/**
|
|
52
|
-
* Websocket message ID indicating a refresh is needed.
|
|
53
|
-
*
|
|
54
|
-
* @constant {number}
|
|
55
|
-
*/
|
|
56
18
|
export const WS_ID_REFRESH_NEEDED = 1;
|
|
57
|
-
/**
|
|
58
|
-
* Websocket message ID indicating a restart is needed.
|
|
59
|
-
*
|
|
60
|
-
* @constant {number}
|
|
61
|
-
*/
|
|
62
19
|
export const WS_ID_RESTART_NEEDED = 2;
|
|
63
|
-
/**
|
|
64
|
-
* Websocket message ID indicating a cpu update.
|
|
65
|
-
*
|
|
66
|
-
* @constant {number}
|
|
67
|
-
*/
|
|
68
20
|
export const WS_ID_CPU_UPDATE = 3;
|
|
69
|
-
/**
|
|
70
|
-
* Websocket message ID indicating a memory update.
|
|
71
|
-
*
|
|
72
|
-
* @constant {number}
|
|
73
|
-
*/
|
|
74
21
|
export const WS_ID_MEMORY_UPDATE = 4;
|
|
75
|
-
/**
|
|
76
|
-
* Websocket message ID indicating an uptime update.
|
|
77
|
-
*
|
|
78
|
-
* @constant {number}
|
|
79
|
-
*/
|
|
80
22
|
export const WS_ID_UPTIME_UPDATE = 5;
|
|
81
|
-
/**
|
|
82
|
-
* Websocket message ID indicating a snackbar message.
|
|
83
|
-
*
|
|
84
|
-
* @constant {number}
|
|
85
|
-
*/
|
|
86
23
|
export const WS_ID_SNACKBAR = 6;
|
|
87
|
-
/**
|
|
88
|
-
* Websocket message ID indicating matterbridge has un update available.
|
|
89
|
-
*
|
|
90
|
-
* @constant {number}
|
|
91
|
-
*/
|
|
92
24
|
export const WS_ID_UPDATE_NEEDED = 7;
|
|
93
|
-
/**
|
|
94
|
-
* Websocket message ID indicating a state update.
|
|
95
|
-
*
|
|
96
|
-
* @constant {number}
|
|
97
|
-
*/
|
|
98
25
|
export const WS_ID_STATEUPDATE = 8;
|
|
99
|
-
/**
|
|
100
|
-
* Websocket message ID indicating to close a permanent snackbar message.
|
|
101
|
-
*
|
|
102
|
-
* @constant {number}
|
|
103
|
-
*/
|
|
104
26
|
export const WS_ID_CLOSE_SNACKBAR = 9;
|
|
105
|
-
/**
|
|
106
|
-
* Websocket message ID indicating a shelly system update.
|
|
107
|
-
* check:
|
|
108
|
-
* curl -k http://127.0.0.1:8101/api/updates/sys/check
|
|
109
|
-
* perform:
|
|
110
|
-
* curl -k http://127.0.0.1:8101/api/updates/sys/perform
|
|
111
|
-
*
|
|
112
|
-
* @constant {number}
|
|
113
|
-
*/
|
|
114
27
|
export const WS_ID_SHELLY_SYS_UPDATE = 100;
|
|
115
|
-
/**
|
|
116
|
-
* Websocket message ID indicating a shelly main update.
|
|
117
|
-
* check:
|
|
118
|
-
* curl -k http://127.0.0.1:8101/api/updates/main/check
|
|
119
|
-
* perform:
|
|
120
|
-
* curl -k http://127.0.0.1:8101/api/updates/main/perform
|
|
121
|
-
*
|
|
122
|
-
* @constant {number}
|
|
123
|
-
*/
|
|
124
28
|
export const WS_ID_SHELLY_MAIN_UPDATE = 101;
|
|
125
29
|
export class Frontend extends EventEmitter {
|
|
126
30
|
matterbridge;
|
|
@@ -133,7 +37,7 @@ export class Frontend extends EventEmitter {
|
|
|
133
37
|
constructor(matterbridge) {
|
|
134
38
|
super();
|
|
135
39
|
this.matterbridge = matterbridge;
|
|
136
|
-
this.log = new AnsiLogger({ logName: 'Frontend', logTimestampFormat: 4
|
|
40
|
+
this.log = new AnsiLogger({ logName: 'Frontend', logTimestampFormat: 4, logLevel: hasParameter('debug') ? "debug" : "info" });
|
|
137
41
|
}
|
|
138
42
|
set logLevel(logLevel) {
|
|
139
43
|
this.log.logLevel = logLevel;
|
|
@@ -141,39 +45,10 @@ export class Frontend extends EventEmitter {
|
|
|
141
45
|
async start(port = 8283) {
|
|
142
46
|
this.port = port;
|
|
143
47
|
this.log.debug(`Initializing the frontend ${hasParameter('ssl') ? 'https' : 'http'} server on port ${YELLOW}${this.port}${db}`);
|
|
144
|
-
|
|
145
|
-
const uploadDir = path.join(this.matterbridge.matterbridgeDirectory, 'uploads'); // Is created by matterbridge initialize
|
|
48
|
+
const uploadDir = path.join(this.matterbridge.matterbridgeDirectory, 'uploads');
|
|
146
49
|
const upload = multer({ dest: uploadDir });
|
|
147
|
-
// Create the express app that serves the frontend
|
|
148
50
|
this.expressApp = express();
|
|
149
|
-
// Inject logging/debug wrapper for route/middleware registration
|
|
150
|
-
/*
|
|
151
|
-
const methods = ['get', 'post', 'put', 'delete', 'use'];
|
|
152
|
-
for (const method of methods) {
|
|
153
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
|
-
const original = (this.expressApp as any)[method].bind(this.expressApp);
|
|
155
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
156
|
-
(this.expressApp as any)[method] = (path: any, ...rest: any) => {
|
|
157
|
-
try {
|
|
158
|
-
console.log(`[DEBUG] Registering ${method.toUpperCase()} route:`, path);
|
|
159
|
-
return original(path, ...rest);
|
|
160
|
-
} catch (err) {
|
|
161
|
-
console.error(`[ERROR] Failed to register route: ${path}`);
|
|
162
|
-
throw err;
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
*/
|
|
167
|
-
// Log all requests to the server for debugging
|
|
168
|
-
/*
|
|
169
|
-
this.expressApp.use((req, res, next) => {
|
|
170
|
-
this.log.debug(`***Received request on expressApp: ${req.method} ${req.url}`);
|
|
171
|
-
next();
|
|
172
|
-
});
|
|
173
|
-
*/
|
|
174
|
-
// Serve static files from '/static' endpoint
|
|
175
51
|
this.expressApp.use(express.static(path.join(this.matterbridge.rootDirectory, 'frontend/build')));
|
|
176
|
-
// Read the package.json file to get the frontend version
|
|
177
52
|
try {
|
|
178
53
|
this.log.debug(`Reading frontend package.json...`);
|
|
179
54
|
const frontendJson = await fs.readFile(path.join(this.matterbridge.rootDirectory, 'frontend/package.json'), 'utf8');
|
|
@@ -181,11 +56,9 @@ export class Frontend extends EventEmitter {
|
|
|
181
56
|
this.log.debug(`Frontend version ${CYAN}${this.matterbridge.matterbridgeInformation.frontendVersion}${db}`);
|
|
182
57
|
}
|
|
183
58
|
catch (error) {
|
|
184
|
-
// istanbul ignore next
|
|
185
59
|
this.log.error(`Failed to read frontend package.json: ${error instanceof Error ? error.message : String(error)}`);
|
|
186
60
|
}
|
|
187
61
|
if (!hasParameter('ssl')) {
|
|
188
|
-
// Create an HTTP server and attach the express app
|
|
189
62
|
try {
|
|
190
63
|
this.log.debug(`Creating HTTP server...`);
|
|
191
64
|
this.httpServer = createServer(this.expressApp);
|
|
@@ -195,7 +68,6 @@ export class Frontend extends EventEmitter {
|
|
|
195
68
|
this.emit('server_error', error);
|
|
196
69
|
return;
|
|
197
70
|
}
|
|
198
|
-
// Listen on the specified port
|
|
199
71
|
if (hasParameter('ingress')) {
|
|
200
72
|
this.httpServer.listen(this.port, '0.0.0.0', () => {
|
|
201
73
|
this.log.info(`The frontend http server is listening on ${UNDERLINE}http://0.0.0.0:${this.port}${UNDERLINEOFF}${rs}`);
|
|
@@ -234,7 +106,6 @@ export class Frontend extends EventEmitter {
|
|
|
234
106
|
let passphrase;
|
|
235
107
|
let httpsServerOptions = {};
|
|
236
108
|
if (existsSync(path.join(this.matterbridge.matterbridgeDirectory, 'certs/cert.p12'))) {
|
|
237
|
-
// Load the p12 certificate and the passphrase
|
|
238
109
|
try {
|
|
239
110
|
pfx = await fs.readFile(path.join(this.matterbridge.matterbridgeDirectory, 'certs/cert.p12'));
|
|
240
111
|
this.log.info(`Loaded p12 certificate file ${path.join(this.matterbridge.matterbridgeDirectory, 'certs/cert.p12')}`);
|
|
@@ -246,7 +117,7 @@ export class Frontend extends EventEmitter {
|
|
|
246
117
|
}
|
|
247
118
|
try {
|
|
248
119
|
passphrase = await fs.readFile(path.join(this.matterbridge.matterbridgeDirectory, 'certs/cert.pass'), 'utf8');
|
|
249
|
-
passphrase = passphrase.trim();
|
|
120
|
+
passphrase = passphrase.trim();
|
|
250
121
|
this.log.info(`Loaded p12 passphrase file ${path.join(this.matterbridge.matterbridgeDirectory, 'certs/cert.pass')}`);
|
|
251
122
|
}
|
|
252
123
|
catch (error) {
|
|
@@ -257,7 +128,6 @@ export class Frontend extends EventEmitter {
|
|
|
257
128
|
httpsServerOptions = { pfx, passphrase };
|
|
258
129
|
}
|
|
259
130
|
else {
|
|
260
|
-
// Load the SSL certificate, the private key and optionally the CA certificate. If the CA certificate is present, it will be used to create a full chain certificate.
|
|
261
131
|
try {
|
|
262
132
|
cert = await fs.readFile(path.join(this.matterbridge.matterbridgeDirectory, 'certs/cert.pem'), 'utf8');
|
|
263
133
|
this.log.info(`Loaded certificate file ${path.join(this.matterbridge.matterbridgeDirectory, 'certs/cert.pem')}`);
|
|
@@ -287,10 +157,9 @@ export class Frontend extends EventEmitter {
|
|
|
287
157
|
httpsServerOptions = { cert: fullChain ?? cert, key, ca };
|
|
288
158
|
}
|
|
289
159
|
if (hasParameter('mtls')) {
|
|
290
|
-
httpsServerOptions.requestCert = true;
|
|
291
|
-
httpsServerOptions.rejectUnauthorized = true;
|
|
160
|
+
httpsServerOptions.requestCert = true;
|
|
161
|
+
httpsServerOptions.rejectUnauthorized = true;
|
|
292
162
|
}
|
|
293
|
-
// Create an HTTPS server with the SSL certificate and private key (ca is optional) and attach the express app
|
|
294
163
|
try {
|
|
295
164
|
this.log.debug(`Creating HTTPS server...`);
|
|
296
165
|
this.httpsServer = https.createServer(httpsServerOptions, this.expressApp);
|
|
@@ -300,7 +169,6 @@ export class Frontend extends EventEmitter {
|
|
|
300
169
|
this.emit('server_error', error);
|
|
301
170
|
return;
|
|
302
171
|
}
|
|
303
|
-
// Listen on the specified port
|
|
304
172
|
if (hasParameter('ingress')) {
|
|
305
173
|
this.httpsServer.listen(this.port, '0.0.0.0', () => {
|
|
306
174
|
this.log.info(`The frontend https server is listening on ${UNDERLINE}https://0.0.0.0:${this.port}${UNDERLINEOFF}${rs}`);
|
|
@@ -330,19 +198,17 @@ export class Frontend extends EventEmitter {
|
|
|
330
198
|
return;
|
|
331
199
|
});
|
|
332
200
|
}
|
|
333
|
-
// Create a WebSocket server and attach it to the http or https server
|
|
334
201
|
const wssPort = this.port;
|
|
335
202
|
const wssHost = hasParameter('ssl') ? `wss://${this.matterbridge.systemInformation.ipv4Address}:${wssPort}` : `ws://${this.matterbridge.systemInformation.ipv4Address}:${wssPort}`;
|
|
336
203
|
this.log.debug(`Creating WebSocketServer on host ${CYAN}${wssHost}${db}...`);
|
|
337
204
|
this.webSocketServer = new WebSocketServer(hasParameter('ssl') ? { server: this.httpsServer } : { server: this.httpServer });
|
|
338
205
|
this.webSocketServer.on('connection', (ws, request) => {
|
|
339
206
|
const clientIp = request.socket.remoteAddress;
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
callbackLogLevel = "debug" /* LogLevel.DEBUG */;
|
|
207
|
+
let callbackLogLevel = "notice";
|
|
208
|
+
if (this.matterbridge.matterbridgeInformation.loggerLevel === "info" || this.matterbridge.matterbridgeInformation.matterLoggerLevel === MatterLogLevel.INFO)
|
|
209
|
+
callbackLogLevel = "info";
|
|
210
|
+
if (this.matterbridge.matterbridgeInformation.loggerLevel === "debug" || this.matterbridge.matterbridgeInformation.matterLoggerLevel === MatterLogLevel.DEBUG)
|
|
211
|
+
callbackLogLevel = "debug";
|
|
346
212
|
AnsiLogger.setGlobalCallback(this.wssSendMessage.bind(this), callbackLogLevel);
|
|
347
213
|
this.log.debug(`WebSocketServer logger global callback set to ${callbackLogLevel}`);
|
|
348
214
|
this.log.info(`WebSocketServer client "${clientIp}" connected to Matterbridge`);
|
|
@@ -364,7 +230,6 @@ export class Frontend extends EventEmitter {
|
|
|
364
230
|
}
|
|
365
231
|
});
|
|
366
232
|
ws.on('error', (error) => {
|
|
367
|
-
// istanbul ignore next
|
|
368
233
|
this.log.error(`WebSocket client error: ${error}`);
|
|
369
234
|
});
|
|
370
235
|
});
|
|
@@ -378,7 +243,6 @@ export class Frontend extends EventEmitter {
|
|
|
378
243
|
this.webSocketServer.on('error', (ws, error) => {
|
|
379
244
|
this.log.error(`WebSocketServer error: ${error}`);
|
|
380
245
|
});
|
|
381
|
-
// Subscribe to cli events
|
|
382
246
|
cliEmitter.removeAllListeners();
|
|
383
247
|
cliEmitter.on('uptime', (systemUptime, processUptime) => {
|
|
384
248
|
this.wssSendUptimeUpdate(systemUptime, processUptime);
|
|
@@ -389,8 +253,6 @@ export class Frontend extends EventEmitter {
|
|
|
389
253
|
cliEmitter.on('cpu', (cpuUsage) => {
|
|
390
254
|
this.wssSendCpuUpdate(cpuUsage);
|
|
391
255
|
});
|
|
392
|
-
// Endpoint to validate login code
|
|
393
|
-
// curl -X POST "http://localhost:8283/api/login" -H "Content-Type: application/json" -d "{\"password\":\"Here\"}"
|
|
394
256
|
this.expressApp.post('/api/login', express.json(), async (req, res) => {
|
|
395
257
|
const { password } = req.body;
|
|
396
258
|
this.log.debug('The frontend sent /api/login', password);
|
|
@@ -409,27 +271,23 @@ export class Frontend extends EventEmitter {
|
|
|
409
271
|
this.log.warn('/api/login error wrong password');
|
|
410
272
|
res.json({ valid: false });
|
|
411
273
|
}
|
|
412
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
413
274
|
}
|
|
414
275
|
catch (error) {
|
|
415
276
|
this.log.error('/api/login error getting password');
|
|
416
277
|
res.json({ valid: false });
|
|
417
278
|
}
|
|
418
279
|
});
|
|
419
|
-
// Endpoint to provide health check for docker
|
|
420
280
|
this.expressApp.get('/health', (req, res) => {
|
|
421
281
|
this.log.debug('Express received /health');
|
|
422
282
|
const healthStatus = {
|
|
423
|
-
status: 'ok',
|
|
424
|
-
uptime: process.uptime(),
|
|
425
|
-
timestamp: new Date().toISOString(),
|
|
283
|
+
status: 'ok',
|
|
284
|
+
uptime: process.uptime(),
|
|
285
|
+
timestamp: new Date().toISOString(),
|
|
426
286
|
};
|
|
427
287
|
res.status(200).json(healthStatus);
|
|
428
288
|
});
|
|
429
|
-
// Endpoint to provide memory usage details
|
|
430
289
|
this.expressApp.get('/memory', async (req, res) => {
|
|
431
290
|
this.log.debug('Express received /memory');
|
|
432
|
-
// Memory usage from process
|
|
433
291
|
const memoryUsageRaw = process.memoryUsage();
|
|
434
292
|
const memoryUsage = {
|
|
435
293
|
rss: this.formatMemoryUsage(memoryUsageRaw.rss),
|
|
@@ -438,13 +296,10 @@ export class Frontend extends EventEmitter {
|
|
|
438
296
|
external: this.formatMemoryUsage(memoryUsageRaw.external),
|
|
439
297
|
arrayBuffers: this.formatMemoryUsage(memoryUsageRaw.arrayBuffers),
|
|
440
298
|
};
|
|
441
|
-
// V8 heap statistics
|
|
442
299
|
const { default: v8 } = await import('node:v8');
|
|
443
300
|
const heapStatsRaw = v8.getHeapStatistics();
|
|
444
301
|
const heapSpacesRaw = v8.getHeapSpaceStatistics();
|
|
445
|
-
// Format heapStats
|
|
446
302
|
const heapStats = Object.fromEntries(Object.entries(heapStatsRaw).map(([key, value]) => [key, this.formatMemoryUsage(value)]));
|
|
447
|
-
// Format heapSpaces
|
|
448
303
|
const heapSpaces = heapSpacesRaw.map((space) => ({
|
|
449
304
|
...space,
|
|
450
305
|
space_size: this.formatMemoryUsage(space.space_size),
|
|
@@ -462,23 +317,19 @@ export class Frontend extends EventEmitter {
|
|
|
462
317
|
};
|
|
463
318
|
res.status(200).json(memoryReport);
|
|
464
319
|
});
|
|
465
|
-
// Endpoint to provide settings
|
|
466
320
|
this.expressApp.get('/api/settings', express.json(), async (req, res) => {
|
|
467
321
|
this.log.debug('The frontend sent /api/settings');
|
|
468
322
|
res.json(await this.getApiSettings());
|
|
469
323
|
});
|
|
470
|
-
// Endpoint to provide plugins
|
|
471
324
|
this.expressApp.get('/api/plugins', async (req, res) => {
|
|
472
325
|
this.log.debug('The frontend sent /api/plugins');
|
|
473
326
|
res.json(this.getPlugins());
|
|
474
327
|
});
|
|
475
|
-
// Endpoint to provide devices
|
|
476
328
|
this.expressApp.get('/api/devices', async (req, res) => {
|
|
477
329
|
this.log.debug('The frontend sent /api/devices');
|
|
478
330
|
const devices = await this.getDevices();
|
|
479
331
|
res.json(devices);
|
|
480
332
|
});
|
|
481
|
-
// Endpoint to view the matterbridge log
|
|
482
333
|
this.expressApp.get('/api/view-mblog', async (req, res) => {
|
|
483
334
|
this.log.debug('The frontend sent /api/view-mblog');
|
|
484
335
|
try {
|
|
@@ -491,7 +342,6 @@ export class Frontend extends EventEmitter {
|
|
|
491
342
|
res.status(500).send('Error reading matterbridge log file. Please enable the matterbridge log on file in the settings.');
|
|
492
343
|
}
|
|
493
344
|
});
|
|
494
|
-
// Endpoint to view the matter.js log
|
|
495
345
|
this.expressApp.get('/api/view-mjlog', async (req, res) => {
|
|
496
346
|
this.log.debug('The frontend sent /api/view-mjlog');
|
|
497
347
|
try {
|
|
@@ -504,7 +354,6 @@ export class Frontend extends EventEmitter {
|
|
|
504
354
|
res.status(500).send('Error reading matter log file. Please enable the matter log on file in the settings.');
|
|
505
355
|
}
|
|
506
356
|
});
|
|
507
|
-
// Endpoint to view the shelly log
|
|
508
357
|
this.expressApp.get('/api/shellyviewsystemlog', async (req, res) => {
|
|
509
358
|
this.log.debug('The frontend sent /api/shellyviewsystemlog');
|
|
510
359
|
try {
|
|
@@ -517,7 +366,6 @@ export class Frontend extends EventEmitter {
|
|
|
517
366
|
res.status(500).send('Error reading shelly log file. Please create the shelly system log before loading it.');
|
|
518
367
|
}
|
|
519
368
|
});
|
|
520
|
-
// Endpoint to download the matterbridge log
|
|
521
369
|
this.expressApp.get('/api/download-mblog', async (req, res) => {
|
|
522
370
|
this.log.debug(`The frontend sent /api/download-mblog ${path.join(this.matterbridge.matterbridgeDirectory, this.matterbridge.matterbridgeLoggerFile)}`);
|
|
523
371
|
try {
|
|
@@ -531,14 +379,12 @@ export class Frontend extends EventEmitter {
|
|
|
531
379
|
}
|
|
532
380
|
res.type('text/plain');
|
|
533
381
|
res.download(path.join(os.tmpdir(), this.matterbridge.matterbridgeLoggerFile), 'matterbridge.log', (error) => {
|
|
534
|
-
/* istanbul ignore if */
|
|
535
382
|
if (error) {
|
|
536
383
|
this.log.error(`Error downloading log file ${this.matterbridge.matterbridgeLoggerFile}: ${error instanceof Error ? error.message : error}`);
|
|
537
384
|
res.status(500).send('Error downloading the matterbridge log file');
|
|
538
385
|
}
|
|
539
386
|
});
|
|
540
387
|
});
|
|
541
|
-
// Endpoint to download the matter log
|
|
542
388
|
this.expressApp.get('/api/download-mjlog', async (req, res) => {
|
|
543
389
|
this.log.debug(`The frontend sent /api/download-mjlog ${path.join(this.matterbridge.matterbridgeDirectory, this.matterbridge.matterbridgeLoggerFile)}`);
|
|
544
390
|
try {
|
|
@@ -552,14 +398,12 @@ export class Frontend extends EventEmitter {
|
|
|
552
398
|
}
|
|
553
399
|
res.type('text/plain');
|
|
554
400
|
res.download(path.join(os.tmpdir(), this.matterbridge.matterLoggerFile), 'matter.log', (error) => {
|
|
555
|
-
/* istanbul ignore if */
|
|
556
401
|
if (error) {
|
|
557
402
|
this.log.error(`Error downloading log file ${this.matterbridge.matterLoggerFile}: ${error instanceof Error ? error.message : error}`);
|
|
558
403
|
res.status(500).send('Error downloading the matter log file');
|
|
559
404
|
}
|
|
560
405
|
});
|
|
561
406
|
});
|
|
562
|
-
// Endpoint to download the shelly log
|
|
563
407
|
this.expressApp.get('/api/shellydownloadsystemlog', async (req, res) => {
|
|
564
408
|
this.log.debug('The frontend sent /api/shellydownloadsystemlog');
|
|
565
409
|
try {
|
|
@@ -573,90 +417,74 @@ export class Frontend extends EventEmitter {
|
|
|
573
417
|
}
|
|
574
418
|
res.type('text/plain');
|
|
575
419
|
res.download(path.join(os.tmpdir(), 'shelly.log'), 'shelly.log', (error) => {
|
|
576
|
-
/* istanbul ignore if */
|
|
577
420
|
if (error) {
|
|
578
421
|
this.log.error(`Error downloading Shelly system log file: ${error instanceof Error ? error.message : error}`);
|
|
579
422
|
res.status(500).send('Error downloading Shelly system log file');
|
|
580
423
|
}
|
|
581
424
|
});
|
|
582
425
|
});
|
|
583
|
-
// Endpoint to download the matterbridge storage directory
|
|
584
426
|
this.expressApp.get('/api/download-mbstorage', async (req, res) => {
|
|
585
427
|
this.log.debug('The frontend sent /api/download-mbstorage');
|
|
586
428
|
await createZip(path.join(os.tmpdir(), `matterbridge.${this.matterbridge.nodeStorageName}.zip`), path.join(this.matterbridge.matterbridgeDirectory, this.matterbridge.nodeStorageName));
|
|
587
429
|
res.download(path.join(os.tmpdir(), `matterbridge.${this.matterbridge.nodeStorageName}.zip`), `matterbridge.${this.matterbridge.nodeStorageName}.zip`, (error) => {
|
|
588
|
-
/* istanbul ignore if */
|
|
589
430
|
if (error) {
|
|
590
431
|
this.log.error(`Error downloading file ${`matterbridge.${this.matterbridge.nodeStorageName}.zip`}: ${error instanceof Error ? error.message : error}`);
|
|
591
432
|
res.status(500).send('Error downloading the matterbridge storage file');
|
|
592
433
|
}
|
|
593
434
|
});
|
|
594
435
|
});
|
|
595
|
-
// Endpoint to download the matter storage file
|
|
596
436
|
this.expressApp.get('/api/download-mjstorage', async (req, res) => {
|
|
597
437
|
this.log.debug('The frontend sent /api/download-mjstorage');
|
|
598
438
|
await createZip(path.join(os.tmpdir(), `matterbridge.${this.matterbridge.matterStorageName}.zip`), path.join(this.matterbridge.matterbridgeDirectory, this.matterbridge.matterStorageName));
|
|
599
439
|
res.download(path.join(os.tmpdir(), `matterbridge.${this.matterbridge.matterStorageName}.zip`), `matterbridge.${this.matterbridge.matterStorageName}.zip`, (error) => {
|
|
600
|
-
/* istanbul ignore if */
|
|
601
440
|
if (error) {
|
|
602
441
|
this.log.error(`Error downloading the matter storage matterbridge.${this.matterbridge.matterStorageName}.zip: ${error instanceof Error ? error.message : error}`);
|
|
603
442
|
res.status(500).send('Error downloading the matter storage zip file');
|
|
604
443
|
}
|
|
605
444
|
});
|
|
606
445
|
});
|
|
607
|
-
// Endpoint to download the matterbridge plugin directory
|
|
608
446
|
this.expressApp.get('/api/download-pluginstorage', async (req, res) => {
|
|
609
447
|
this.log.debug('The frontend sent /api/download-pluginstorage');
|
|
610
448
|
await createZip(path.join(os.tmpdir(), `matterbridge.pluginstorage.zip`), this.matterbridge.matterbridgePluginDirectory);
|
|
611
449
|
res.download(path.join(os.tmpdir(), `matterbridge.pluginstorage.zip`), `matterbridge.pluginstorage.zip`, (error) => {
|
|
612
|
-
/* istanbul ignore if */
|
|
613
450
|
if (error) {
|
|
614
451
|
this.log.error(`Error downloading file matterbridge.pluginstorage.zip: ${error instanceof Error ? error.message : error}`);
|
|
615
452
|
res.status(500).send('Error downloading the matterbridge plugin storage file');
|
|
616
453
|
}
|
|
617
454
|
});
|
|
618
455
|
});
|
|
619
|
-
// Endpoint to download the matterbridge plugin config files
|
|
620
456
|
this.expressApp.get('/api/download-pluginconfig', async (req, res) => {
|
|
621
457
|
this.log.debug('The frontend sent /api/download-pluginconfig');
|
|
622
458
|
await createZip(path.join(os.tmpdir(), `matterbridge.pluginconfig.zip`), path.relative(process.cwd(), path.join(this.matterbridge.matterbridgeDirectory, '*.config.json')));
|
|
623
459
|
res.download(path.join(os.tmpdir(), `matterbridge.pluginconfig.zip`), `matterbridge.pluginconfig.zip`, (error) => {
|
|
624
|
-
/* istanbul ignore if */
|
|
625
460
|
if (error) {
|
|
626
461
|
this.log.error(`Error downloading file matterbridge.pluginconfig.zip: ${error instanceof Error ? error.message : error}`);
|
|
627
462
|
res.status(500).send('Error downloading the matterbridge plugin config file');
|
|
628
463
|
}
|
|
629
464
|
});
|
|
630
465
|
});
|
|
631
|
-
// Endpoint to download the matterbridge backup (created with the backup command)
|
|
632
466
|
this.expressApp.get('/api/download-backup', async (req, res) => {
|
|
633
467
|
this.log.debug('The frontend sent /api/download-backup');
|
|
634
468
|
res.download(path.join(os.tmpdir(), `matterbridge.backup.zip`), `matterbridge.backup.zip`, (error) => {
|
|
635
|
-
/* istanbul ignore if */
|
|
636
469
|
if (error) {
|
|
637
470
|
this.log.error(`Error downloading file matterbridge.backup.zip: ${error instanceof Error ? error.message : error}`);
|
|
638
471
|
res.status(500).send(`Error downloading file matterbridge.backup.zip: ${error instanceof Error ? error.message : error}`);
|
|
639
472
|
}
|
|
640
473
|
});
|
|
641
474
|
});
|
|
642
|
-
// Endpoint to upload a package
|
|
643
475
|
this.expressApp.post('/api/uploadpackage', upload.single('file'), async (req, res) => {
|
|
644
476
|
const { filename } = req.body;
|
|
645
477
|
const file = req.file;
|
|
646
|
-
/* istanbul ignore if */
|
|
647
478
|
if (!file || !filename) {
|
|
648
479
|
this.log.error(`uploadpackage: invalid request: file and filename are required`);
|
|
649
480
|
res.status(400).send('Invalid request: file and filename are required');
|
|
650
481
|
return;
|
|
651
482
|
}
|
|
652
483
|
this.wssSendSnackbarMessage(`Installing package ${filename}. Please wait...`, 0);
|
|
653
|
-
// Define the path where the plugin file will be saved
|
|
654
484
|
const filePath = path.join(this.matterbridge.matterbridgeDirectory, 'uploads', filename);
|
|
655
485
|
try {
|
|
656
|
-
// Move the uploaded file to the specified path
|
|
657
486
|
await fs.rename(file.path, filePath);
|
|
658
487
|
this.log.info(`File ${plg}${filename}${nf} uploaded successfully`);
|
|
659
|
-
// Install the plugin package
|
|
660
488
|
if (filename.endsWith('.tgz')) {
|
|
661
489
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
662
490
|
await spawnCommand(this.matterbridge, 'npm', ['install', '-g', filePath, '--omit=dev', '--verbose']);
|
|
@@ -676,7 +504,6 @@ export class Frontend extends EventEmitter {
|
|
|
676
504
|
res.status(500).send(`Error uploading or installing plugin package ${filename}`);
|
|
677
505
|
}
|
|
678
506
|
});
|
|
679
|
-
// Fallback for routing (must be the last route)
|
|
680
507
|
this.expressApp.use((req, res) => {
|
|
681
508
|
this.log.debug(`The frontend sent ${req.url} method ${req.method}: sending index.html as fallback`);
|
|
682
509
|
res.sendFile(path.join(this.matterbridge.rootDirectory, 'frontend/build/index.html'));
|
|
@@ -685,16 +512,13 @@ export class Frontend extends EventEmitter {
|
|
|
685
512
|
}
|
|
686
513
|
async stop() {
|
|
687
514
|
this.log.debug('Stopping the frontend...');
|
|
688
|
-
// Remove listeners from the express app
|
|
689
515
|
if (this.expressApp) {
|
|
690
516
|
this.expressApp.removeAllListeners();
|
|
691
517
|
this.expressApp = undefined;
|
|
692
518
|
this.log.debug('Frontend app closed successfully');
|
|
693
519
|
}
|
|
694
|
-
// Close the WebSocket server
|
|
695
520
|
if (this.webSocketServer) {
|
|
696
521
|
this.log.debug('Closing WebSocket server...');
|
|
697
|
-
// Close all active connections
|
|
698
522
|
this.webSocketServer.clients.forEach((client) => {
|
|
699
523
|
if (client.readyState === WebSocket.OPEN) {
|
|
700
524
|
client.close();
|
|
@@ -703,7 +527,6 @@ export class Frontend extends EventEmitter {
|
|
|
703
527
|
await withTimeout(new Promise((resolve) => {
|
|
704
528
|
this.webSocketServer?.close((error) => {
|
|
705
529
|
if (error) {
|
|
706
|
-
// istanbul ignore next
|
|
707
530
|
this.log.error(`Error closing WebSocket server: ${error}`);
|
|
708
531
|
}
|
|
709
532
|
else {
|
|
@@ -716,13 +539,11 @@ export class Frontend extends EventEmitter {
|
|
|
716
539
|
this.webSocketServer.removeAllListeners();
|
|
717
540
|
this.webSocketServer = undefined;
|
|
718
541
|
}
|
|
719
|
-
// Close the http server
|
|
720
542
|
if (this.httpServer) {
|
|
721
543
|
this.log.debug('Closing http server...');
|
|
722
544
|
await withTimeout(new Promise((resolve) => {
|
|
723
545
|
this.httpServer?.close((error) => {
|
|
724
546
|
if (error) {
|
|
725
|
-
// istanbul ignore next
|
|
726
547
|
this.log.error(`Error closing http server: ${error}`);
|
|
727
548
|
}
|
|
728
549
|
else {
|
|
@@ -736,13 +557,11 @@ export class Frontend extends EventEmitter {
|
|
|
736
557
|
this.httpServer = undefined;
|
|
737
558
|
this.log.debug('Frontend http server closed successfully');
|
|
738
559
|
}
|
|
739
|
-
// Close the https server
|
|
740
560
|
if (this.httpsServer) {
|
|
741
561
|
this.log.debug('Closing https server...');
|
|
742
562
|
await withTimeout(new Promise((resolve) => {
|
|
743
563
|
this.httpsServer?.close((error) => {
|
|
744
564
|
if (error) {
|
|
745
|
-
// istanbul ignore next
|
|
746
565
|
this.log.error(`Error closing https server: ${error}`);
|
|
747
566
|
}
|
|
748
567
|
else {
|
|
@@ -758,7 +577,6 @@ export class Frontend extends EventEmitter {
|
|
|
758
577
|
}
|
|
759
578
|
this.log.debug('Frontend stopped successfully');
|
|
760
579
|
}
|
|
761
|
-
// Function to format bytes to KB, MB, or GB
|
|
762
580
|
formatMemoryUsage = (bytes) => {
|
|
763
581
|
if (bytes >= 1024 ** 3) {
|
|
764
582
|
return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
|
|
@@ -770,7 +588,6 @@ export class Frontend extends EventEmitter {
|
|
|
770
588
|
return `${(bytes / 1024).toFixed(2)} KB`;
|
|
771
589
|
}
|
|
772
590
|
};
|
|
773
|
-
// Function to format system uptime with only the most significant unit
|
|
774
591
|
formatOsUpTime = (seconds) => {
|
|
775
592
|
if (seconds >= 86400) {
|
|
776
593
|
const days = Math.floor(seconds / 86400);
|
|
@@ -786,13 +603,7 @@ export class Frontend extends EventEmitter {
|
|
|
786
603
|
}
|
|
787
604
|
return `${seconds} second${seconds !== 1 ? 's' : ''}`;
|
|
788
605
|
};
|
|
789
|
-
/**
|
|
790
|
-
* Retrieves the api settings data.
|
|
791
|
-
*
|
|
792
|
-
* @returns {Promise<{ matterbridgeInformation: MatterbridgeInformation, systemInformation: SystemInformation }>} A promise that resolve in the api settings object.
|
|
793
|
-
*/
|
|
794
606
|
async getApiSettings() {
|
|
795
|
-
// Update the system information
|
|
796
607
|
this.matterbridge.systemInformation.totalMemory = this.formatMemoryUsage(os.totalmem());
|
|
797
608
|
this.matterbridge.systemInformation.freeMemory = this.formatMemoryUsage(os.freemem());
|
|
798
609
|
this.matterbridge.systemInformation.systemUptime = this.formatOsUpTime(os.uptime());
|
|
@@ -801,7 +612,6 @@ export class Frontend extends EventEmitter {
|
|
|
801
612
|
this.matterbridge.systemInformation.rss = this.formatMemoryUsage(process.memoryUsage().rss);
|
|
802
613
|
this.matterbridge.systemInformation.heapTotal = this.formatMemoryUsage(process.memoryUsage().heapTotal);
|
|
803
614
|
this.matterbridge.systemInformation.heapUsed = this.formatMemoryUsage(process.memoryUsage().heapUsed);
|
|
804
|
-
// Update the matterbridge information
|
|
805
615
|
this.matterbridge.matterbridgeInformation.bridgeMode = this.matterbridge.bridgeMode;
|
|
806
616
|
this.matterbridge.matterbridgeInformation.restartMode = this.matterbridge.restartMode;
|
|
807
617
|
this.matterbridge.matterbridgeInformation.profile = this.matterbridge.profile;
|
|
@@ -813,7 +623,6 @@ export class Frontend extends EventEmitter {
|
|
|
813
623
|
this.matterbridge.matterbridgeInformation.matterPort = (await this.matterbridge.nodeContext?.get('matterport', 5540)) ?? 5540;
|
|
814
624
|
this.matterbridge.matterbridgeInformation.matterDiscriminator = await this.matterbridge.nodeContext?.get('matterdiscriminator');
|
|
815
625
|
this.matterbridge.matterbridgeInformation.matterPasscode = await this.matterbridge.nodeContext?.get('matterpasscode');
|
|
816
|
-
// Update the matterbridge information in bridge mode
|
|
817
626
|
if (this.matterbridge.bridgeMode === 'bridge' && this.matterbridge.serverNode && !this.matterbridge.hasCleanupStarted) {
|
|
818
627
|
this.matterbridge.matterbridgeInformation.matterbridgePaired = this.matterbridge.serverNode.state.commissioning.commissioned;
|
|
819
628
|
this.matterbridge.matterbridgeInformation.matterbridgeQrPairingCode = this.matterbridge.matterbridgeInformation.matterbridgeEndAdvertise ? undefined : this.matterbridge.serverNode.state.commissioning.pairingCodes.qrPairingCode;
|
|
@@ -823,12 +632,6 @@ export class Frontend extends EventEmitter {
|
|
|
823
632
|
}
|
|
824
633
|
return { systemInformation: this.matterbridge.systemInformation, matterbridgeInformation: this.matterbridge.matterbridgeInformation };
|
|
825
634
|
}
|
|
826
|
-
/**
|
|
827
|
-
* Retrieves the reachable attribute.
|
|
828
|
-
*
|
|
829
|
-
* @param {MatterbridgeEndpoint} device - The MatterbridgeEndpoint object.
|
|
830
|
-
* @returns {boolean} The reachable attribute.
|
|
831
|
-
*/
|
|
832
635
|
getReachability(device) {
|
|
833
636
|
if (!device.lifecycle.isReady || device.construction.status !== Lifecycle.Status.Active)
|
|
834
637
|
return false;
|
|
@@ -840,12 +643,6 @@ export class Frontend extends EventEmitter {
|
|
|
840
643
|
return true;
|
|
841
644
|
return false;
|
|
842
645
|
}
|
|
843
|
-
/**
|
|
844
|
-
* Retrieves the power source attribute.
|
|
845
|
-
*
|
|
846
|
-
* @param {MatterbridgeEndpoint} endpoint - The MatterbridgeDevice to retrieve the power source from.
|
|
847
|
-
* @returns {'ac' | 'dc' | 'ok' | 'warning' | 'critical' | undefined} The power source attribute.
|
|
848
|
-
*/
|
|
849
646
|
getPowerSource(endpoint) {
|
|
850
647
|
if (!endpoint.lifecycle.isReady || endpoint.construction.status !== Lifecycle.Status.Active)
|
|
851
648
|
return undefined;
|
|
@@ -861,21 +658,13 @@ export class Frontend extends EventEmitter {
|
|
|
861
658
|
}
|
|
862
659
|
return;
|
|
863
660
|
};
|
|
864
|
-
// Root endpoint
|
|
865
661
|
if (endpoint.hasClusterServer(PowerSource.Cluster.id))
|
|
866
662
|
return powerSource(endpoint);
|
|
867
|
-
// Child endpoints
|
|
868
663
|
for (const child of endpoint.getChildEndpoints()) {
|
|
869
664
|
if (child.hasClusterServer(PowerSource.Cluster.id))
|
|
870
665
|
return powerSource(child);
|
|
871
666
|
}
|
|
872
667
|
}
|
|
873
|
-
/**
|
|
874
|
-
* Retrieves the commissioned status, matter pairing codes, fabrics and sessions from a given device in server mode.
|
|
875
|
-
*
|
|
876
|
-
* @param {MatterbridgeEndpoint} device - The MatterbridgeEndpoint to retrieve the data from.
|
|
877
|
-
* @returns {ApiDevicesMatter | undefined} An ApiDevicesMatter object or undefined if not found.
|
|
878
|
-
*/
|
|
879
668
|
getMatterDataFromDevice(device) {
|
|
880
669
|
if (device.mode === 'server' && device.serverNode) {
|
|
881
670
|
return {
|
|
@@ -888,13 +677,6 @@ export class Frontend extends EventEmitter {
|
|
|
888
677
|
};
|
|
889
678
|
}
|
|
890
679
|
}
|
|
891
|
-
/**
|
|
892
|
-
* Retrieves the cluster text description from a given device.
|
|
893
|
-
* The output is a string with the attributes description of the cluster servers in the device to show in the frontend.
|
|
894
|
-
*
|
|
895
|
-
* @param {MatterbridgeEndpoint} device - The MatterbridgeEndpoint to retrieve the cluster text from.
|
|
896
|
-
* @returns {string} The attributes description of the cluster servers in the device.
|
|
897
|
-
*/
|
|
898
680
|
getClusterTextFromDevice(device) {
|
|
899
681
|
if (!device.lifecycle.isReady || device.construction.status !== Lifecycle.Status.Active)
|
|
900
682
|
return '';
|
|
@@ -905,7 +687,6 @@ export class Frontend extends EventEmitter {
|
|
|
905
687
|
if (composed)
|
|
906
688
|
return 'Composed: ' + composed.value;
|
|
907
689
|
}
|
|
908
|
-
// istanbul ignore next cause is not reachable
|
|
909
690
|
return '';
|
|
910
691
|
};
|
|
911
692
|
const getFixedLabel = (device) => {
|
|
@@ -915,13 +696,11 @@ export class Frontend extends EventEmitter {
|
|
|
915
696
|
if (composed)
|
|
916
697
|
return 'Composed: ' + composed.value;
|
|
917
698
|
}
|
|
918
|
-
// istanbul ignore next cause is not reacheable
|
|
919
699
|
return '';
|
|
920
700
|
};
|
|
921
701
|
let attributes = '';
|
|
922
702
|
let supportedModes = [];
|
|
923
703
|
device.forEachAttribute((clusterName, clusterId, attributeName, attributeId, attributeValue) => {
|
|
924
|
-
// console.log(`${device.deviceName} => Cluster: ${clusterName}-${clusterId} Attribute: ${attributeName}-${attributeId} Value(${typeof attributeValue}): ${attributeValue}`);
|
|
925
704
|
if (typeof attributeValue === 'undefined' || attributeValue === undefined)
|
|
926
705
|
return;
|
|
927
706
|
if (clusterName === 'onOff' && attributeName === 'onOff')
|
|
@@ -1011,17 +790,11 @@ export class Frontend extends EventEmitter {
|
|
|
1011
790
|
if (clusterName === 'userLabel' && attributeName === 'labelList')
|
|
1012
791
|
attributes += `${getUserLabel(device)} `;
|
|
1013
792
|
});
|
|
1014
|
-
// console.log(`${device.deviceName}.forEachAttribute: ${attributes}`);
|
|
1015
793
|
return attributes.trimStart().trimEnd();
|
|
1016
794
|
}
|
|
1017
|
-
/**
|
|
1018
|
-
* Retrieves the registered plugins sanitized for res.json().
|
|
1019
|
-
*
|
|
1020
|
-
* @returns {BaseRegisteredPlugin[]} An array of BaseRegisteredPlugin.
|
|
1021
|
-
*/
|
|
1022
795
|
getPlugins() {
|
|
1023
796
|
if (this.matterbridge.hasCleanupStarted)
|
|
1024
|
-
return [];
|
|
797
|
+
return [];
|
|
1025
798
|
const baseRegisteredPlugins = [];
|
|
1026
799
|
for (const plugin of this.matterbridge.plugins) {
|
|
1027
800
|
baseRegisteredPlugins.push({
|
|
@@ -1051,7 +824,6 @@ export class Frontend extends EventEmitter {
|
|
|
1051
824
|
schemaJson: plugin.schemaJson,
|
|
1052
825
|
hasWhiteList: plugin.configJson?.whiteList !== undefined,
|
|
1053
826
|
hasBlackList: plugin.configJson?.blackList !== undefined,
|
|
1054
|
-
// Childbridge mode specific data
|
|
1055
827
|
paired: plugin.serverNode && plugin.serverNode.lifecycle.isOnline ? plugin.serverNode.state.commissioning.commissioned : undefined,
|
|
1056
828
|
qrPairingCode: this.matterbridge.matterbridgeInformation.matterbridgeEndAdvertise ? undefined : plugin.serverNode && plugin.serverNode.lifecycle.isOnline ? plugin.serverNode.state.commissioning.pairingCodes.qrPairingCode : undefined,
|
|
1057
829
|
manualPairingCode: this.matterbridge.matterbridgeInformation.matterbridgeEndAdvertise ? undefined : plugin.serverNode && plugin.serverNode.lifecycle.isOnline ? plugin.serverNode.state.commissioning.pairingCodes.manualPairingCode : undefined,
|
|
@@ -1061,21 +833,13 @@ export class Frontend extends EventEmitter {
|
|
|
1061
833
|
}
|
|
1062
834
|
return baseRegisteredPlugins;
|
|
1063
835
|
}
|
|
1064
|
-
/**
|
|
1065
|
-
* Retrieves the devices from Matterbridge.
|
|
1066
|
-
*
|
|
1067
|
-
* @param {string} [pluginName] - The name of the plugin to filter devices by.
|
|
1068
|
-
* @returns {Promise<ApiDevices[]>} A promise that resolves to an array of ApiDevices for the frontend.
|
|
1069
|
-
*/
|
|
1070
836
|
async getDevices(pluginName) {
|
|
1071
837
|
if (this.matterbridge.hasCleanupStarted)
|
|
1072
|
-
return [];
|
|
838
|
+
return [];
|
|
1073
839
|
const devices = [];
|
|
1074
840
|
for (const device of this.matterbridge.devices.array()) {
|
|
1075
|
-
// Filter by pluginName if provided
|
|
1076
841
|
if (pluginName && pluginName !== device.plugin)
|
|
1077
842
|
continue;
|
|
1078
|
-
// Check if the device has the required properties
|
|
1079
843
|
if (!device.plugin || !device.deviceType || !device.name || !device.deviceName || !device.serialNumber || !device.uniqueId || !device.lifecycle.isReady)
|
|
1080
844
|
continue;
|
|
1081
845
|
devices.push({
|
|
@@ -1095,37 +859,22 @@ export class Frontend extends EventEmitter {
|
|
|
1095
859
|
}
|
|
1096
860
|
return devices;
|
|
1097
861
|
}
|
|
1098
|
-
/**
|
|
1099
|
-
* Retrieves the clusters from a given plugin and endpoint number.
|
|
1100
|
-
*
|
|
1101
|
-
* Response for /api/clusters
|
|
1102
|
-
*
|
|
1103
|
-
* @param {string} pluginName - The name of the plugin.
|
|
1104
|
-
* @param {number} endpointNumber - The endpoint number.
|
|
1105
|
-
* @returns {ApiClustersResponse | undefined} A promise that resolves to the clusters or undefined if not found.
|
|
1106
|
-
*/
|
|
1107
862
|
getClusters(pluginName, endpointNumber) {
|
|
1108
863
|
const endpoint = this.matterbridge.devices.array().find((d) => d.plugin === pluginName && d.maybeNumber === endpointNumber);
|
|
1109
864
|
if (!endpoint || !endpoint.plugin || !endpoint.maybeNumber || !endpoint.deviceName || !endpoint.serialNumber) {
|
|
1110
865
|
this.log.error(`getClusters: no device found for plugin ${pluginName} and endpoint number ${endpointNumber}`);
|
|
1111
866
|
return;
|
|
1112
867
|
}
|
|
1113
|
-
// this.log.debug(`***getClusters: getting clusters for device ${endpoint.deviceName} plugin ${pluginName} endpoint number ${endpointNumber}`);
|
|
1114
|
-
// Get the device types from the main endpoint
|
|
1115
868
|
const deviceTypes = [];
|
|
1116
869
|
const clusters = [];
|
|
1117
870
|
endpoint.state.descriptor.deviceTypeList.forEach((d) => {
|
|
1118
871
|
deviceTypes.push(d.deviceType);
|
|
1119
872
|
});
|
|
1120
|
-
// Get the clusters from the main endpoint
|
|
1121
873
|
endpoint.forEachAttribute((clusterName, clusterId, attributeName, attributeId, attributeValue) => {
|
|
1122
874
|
if (typeof attributeValue === 'undefined' || attributeValue === undefined)
|
|
1123
875
|
return;
|
|
1124
876
|
if (clusterName === 'EveHistory' && ['configDataGet', 'configDataSet', 'historyStatus', 'historyEntries', 'historyRequest', 'historySetTime', 'rLoc'].includes(attributeName))
|
|
1125
877
|
return;
|
|
1126
|
-
// console.log(
|
|
1127
|
-
// `${idn}${endpoint.deviceName}${rs}${nf} => Cluster: ${CYAN}${clusterName} (0x${clusterId.toString(16).padStart(2, '0')})${nf} Attribute: ${CYAN}${attributeName} (0x${attributeId.toString(16).padStart(2, '0')})${nf} Value: ${YELLOW}${typeof attributeValue === 'object' ? stringify(attributeValue as object) : attributeValue}${nf}`,
|
|
1128
|
-
// );
|
|
1129
878
|
clusters.push({
|
|
1130
879
|
endpoint: endpoint.number.toString(),
|
|
1131
880
|
id: 'main',
|
|
@@ -1138,19 +887,12 @@ export class Frontend extends EventEmitter {
|
|
|
1138
887
|
attributeLocalValue: attributeValue,
|
|
1139
888
|
});
|
|
1140
889
|
});
|
|
1141
|
-
// Get the child endpoints
|
|
1142
890
|
const childEndpoints = endpoint.getChildEndpoints();
|
|
1143
|
-
// if (childEndpoints.length === 0) {
|
|
1144
|
-
// this.log.debug(`***getClusters: found ${childEndpoints.length} child endpoints for device ${endpoint.deviceName} plugin ${pluginName} and endpoint number ${endpointNumber}`);
|
|
1145
|
-
// }
|
|
1146
891
|
childEndpoints.forEach((childEndpoint) => {
|
|
1147
|
-
// istanbul ignore if cause is not reachable: should never happen but ...
|
|
1148
892
|
if (!childEndpoint.maybeId || !childEndpoint.maybeNumber) {
|
|
1149
893
|
this.log.error(`getClusters: no child endpoint found for plugin ${pluginName} and endpoint number ${endpointNumber}`);
|
|
1150
894
|
return;
|
|
1151
895
|
}
|
|
1152
|
-
// this.log.debug(`***getClusters: getting clusters for child endpoint ${childEndpoint.id} of device ${endpoint.deviceName} plugin ${pluginName} endpoint number ${childEndpoint.number}`);
|
|
1153
|
-
// Get the device types of the child endpoint
|
|
1154
896
|
const deviceTypes = [];
|
|
1155
897
|
childEndpoint.state.descriptor.deviceTypeList.forEach((d) => {
|
|
1156
898
|
deviceTypes.push(d.deviceType);
|
|
@@ -1160,12 +902,9 @@ export class Frontend extends EventEmitter {
|
|
|
1160
902
|
return;
|
|
1161
903
|
if (clusterName === 'EveHistory' && ['configDataGet', 'configDataSet', 'historyStatus', 'historyEntries', 'historyRequest', 'historySetTime', 'rLoc'].includes(attributeName))
|
|
1162
904
|
return;
|
|
1163
|
-
// console.log(
|
|
1164
|
-
// `${idn}${childEndpoint.deviceName}${rs}${nf} => Cluster: ${CYAN}${clusterName} (0x${clusterId.toString(16).padStart(2, '0')})${nf} Attribute: ${CYAN}${attributeName} (0x${attributeId.toString(16).padStart(2, '0')})${nf} Value: ${YELLOW}${typeof attributeValue === 'object' ? stringify(attributeValue as object) : attributeValue}${nf}`,
|
|
1165
|
-
// );
|
|
1166
905
|
clusters.push({
|
|
1167
906
|
endpoint: childEndpoint.number.toString(),
|
|
1168
|
-
id: childEndpoint.maybeId ?? 'null',
|
|
907
|
+
id: childEndpoint.maybeId ?? 'null',
|
|
1169
908
|
deviceTypes,
|
|
1170
909
|
clusterName: capitalizeFirstLetter(clusterName),
|
|
1171
910
|
clusterId: '0x' + clusterId.toString(16).padStart(2, '0'),
|
|
@@ -1178,13 +917,6 @@ export class Frontend extends EventEmitter {
|
|
|
1178
917
|
});
|
|
1179
918
|
return { plugin: endpoint.plugin, deviceName: endpoint.deviceName, serialNumber: endpoint.serialNumber, endpoint: endpoint.maybeNumber, deviceTypes, clusters };
|
|
1180
919
|
}
|
|
1181
|
-
/**
|
|
1182
|
-
* Handles incoming websocket messages for the Matterbridge frontend.
|
|
1183
|
-
*
|
|
1184
|
-
* @param {WebSocket} client - The websocket client that sent the message.
|
|
1185
|
-
* @param {WebSocket.RawData} message - The raw data of the message received from the client.
|
|
1186
|
-
* @returns {Promise<void>} A promise that resolves when the message has been handled.
|
|
1187
|
-
*/
|
|
1188
920
|
async wsMessageHandler(client, message) {
|
|
1189
921
|
let data;
|
|
1190
922
|
try {
|
|
@@ -1231,48 +963,35 @@ export class Frontend extends EventEmitter {
|
|
|
1231
963
|
this.wssSendSnackbarMessage(`Installed package ${data.params.packageName}`, 5, 'success');
|
|
1232
964
|
const packageName = data.params.packageName.replace(/@.*$/, '');
|
|
1233
965
|
if (data.params.restart === false && packageName !== 'matterbridge') {
|
|
1234
|
-
// The install comes from InstallPlugins
|
|
1235
966
|
this.matterbridge.plugins
|
|
1236
967
|
.add(packageName)
|
|
1237
968
|
.then((plugin) => {
|
|
1238
|
-
// istanbul ignore next if
|
|
1239
969
|
if (plugin) {
|
|
1240
|
-
// The plugin is not registered
|
|
1241
970
|
this.wssSendSnackbarMessage(`Added plugin ${packageName}`, 5, 'success');
|
|
1242
|
-
// In childbridge mode the plugins server node is not started when added
|
|
1243
971
|
if (this.matterbridge.bridgeMode === 'childbridge')
|
|
1244
972
|
this.wssSendRestartRequired(true, true);
|
|
1245
973
|
this.matterbridge.plugins
|
|
1246
974
|
.load(plugin, true, 'The plugin has been added', true)
|
|
1247
|
-
// eslint-disable-next-line promise/no-nesting
|
|
1248
975
|
.then(() => {
|
|
1249
976
|
this.wssSendSnackbarMessage(`Started plugin ${packageName}`, 5, 'success');
|
|
1250
977
|
this.wssSendRefreshRequired('plugins');
|
|
1251
978
|
return;
|
|
1252
979
|
})
|
|
1253
|
-
// eslint-disable-next-line promise/no-nesting
|
|
1254
980
|
.catch((_error) => {
|
|
1255
|
-
//
|
|
1256
981
|
});
|
|
1257
982
|
}
|
|
1258
983
|
else {
|
|
1259
|
-
// The plugin is already registered
|
|
1260
984
|
this.matterbridge.matterbridgeInformation.fixedRestartRequired = true;
|
|
1261
985
|
this.wssSendRefreshRequired('plugins');
|
|
1262
986
|
this.wssSendRestartRequired(true, true);
|
|
1263
987
|
}
|
|
1264
988
|
return;
|
|
1265
989
|
})
|
|
1266
|
-
// eslint-disable-next-line promise/no-nesting
|
|
1267
990
|
.catch((_error) => {
|
|
1268
|
-
//
|
|
1269
991
|
});
|
|
1270
992
|
}
|
|
1271
993
|
else {
|
|
1272
|
-
// The package is matterbridge
|
|
1273
|
-
// istanbul ignore next
|
|
1274
994
|
this.matterbridge.matterbridgeInformation.fixedRestartRequired = true;
|
|
1275
|
-
// istanbul ignore next if
|
|
1276
995
|
if (this.matterbridge.restartMode !== '') {
|
|
1277
996
|
this.wssSendSnackbarMessage(`Restarting matterbridge...`, 0);
|
|
1278
997
|
this.matterbridge.shutdownProcess();
|
|
@@ -1294,9 +1013,7 @@ export class Frontend extends EventEmitter {
|
|
|
1294
1013
|
client.send(JSON.stringify({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter packageName in /api/uninstall' }));
|
|
1295
1014
|
return;
|
|
1296
1015
|
}
|
|
1297
|
-
// The package is a plugin
|
|
1298
1016
|
const plugin = this.matterbridge.plugins.get(data.params.packageName);
|
|
1299
|
-
// istanbul ignore next if
|
|
1300
1017
|
if (plugin) {
|
|
1301
1018
|
await this.matterbridge.plugins.shutdown(plugin, 'The plugin has been removed.', true);
|
|
1302
1019
|
await this.matterbridge.plugins.remove(data.params.packageName);
|
|
@@ -1304,7 +1021,6 @@ export class Frontend extends EventEmitter {
|
|
|
1304
1021
|
this.wssSendRefreshRequired('plugins');
|
|
1305
1022
|
this.wssSendRefreshRequired('devices');
|
|
1306
1023
|
}
|
|
1307
|
-
// Uninstall the package
|
|
1308
1024
|
this.wssSendSnackbarMessage(`Uninstalling package ${data.params.packageName}...`, 0);
|
|
1309
1025
|
const { spawnCommand } = await import('./utils/spawn.js');
|
|
1310
1026
|
spawnCommand(this.matterbridge, 'npm', ['uninstall', '-g', data.params.packageName, '--verbose'])
|
|
@@ -1345,7 +1061,6 @@ export class Frontend extends EventEmitter {
|
|
|
1345
1061
|
return;
|
|
1346
1062
|
})
|
|
1347
1063
|
.catch((_error) => {
|
|
1348
|
-
//
|
|
1349
1064
|
});
|
|
1350
1065
|
}
|
|
1351
1066
|
else {
|
|
@@ -1392,7 +1107,6 @@ export class Frontend extends EventEmitter {
|
|
|
1392
1107
|
return;
|
|
1393
1108
|
})
|
|
1394
1109
|
.catch((_error) => {
|
|
1395
|
-
//
|
|
1396
1110
|
});
|
|
1397
1111
|
}
|
|
1398
1112
|
client.send(JSON.stringify({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true }));
|
|
@@ -1418,7 +1132,6 @@ export class Frontend extends EventEmitter {
|
|
|
1418
1132
|
const plugin = this.matterbridge.plugins.get(data.params.pluginName);
|
|
1419
1133
|
await this.matterbridge.plugins.shutdown(plugin, 'The plugin is restarting.', false, true);
|
|
1420
1134
|
if (plugin.serverNode) {
|
|
1421
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1422
1135
|
await this.matterbridge.stopServerNode(plugin.serverNode);
|
|
1423
1136
|
plugin.serverNode = undefined;
|
|
1424
1137
|
}
|
|
@@ -1429,16 +1142,15 @@ export class Frontend extends EventEmitter {
|
|
|
1429
1142
|
}
|
|
1430
1143
|
}
|
|
1431
1144
|
await this.matterbridge.plugins.load(plugin, true, 'The plugin has been restarted', true);
|
|
1432
|
-
plugin.restartRequired = false;
|
|
1145
|
+
plugin.restartRequired = false;
|
|
1433
1146
|
let needRestart = 0;
|
|
1434
1147
|
for (const plugin of this.matterbridge.plugins) {
|
|
1435
1148
|
if (plugin.restartRequired)
|
|
1436
1149
|
needRestart++;
|
|
1437
1150
|
}
|
|
1438
1151
|
if (needRestart === 0) {
|
|
1439
|
-
this.wssSendRestartNotRequired(true);
|
|
1152
|
+
this.wssSendRestartNotRequired(true);
|
|
1440
1153
|
}
|
|
1441
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1442
1154
|
if (plugin.serverNode)
|
|
1443
1155
|
await this.matterbridge.startServerNode(plugin.serverNode);
|
|
1444
1156
|
this.wssSendSnackbarMessage(`Restarted plugin ${data.params.pluginName}`, 5, 'success');
|
|
@@ -1544,8 +1256,6 @@ export class Frontend extends EventEmitter {
|
|
|
1544
1256
|
else if (data.method === '/api/advertise') {
|
|
1545
1257
|
const pairingCodes = await this.matterbridge.advertiseServerNode(this.matterbridge.serverNode);
|
|
1546
1258
|
this.matterbridge.matterbridgeInformation.matterbridgeAdvertise = true;
|
|
1547
|
-
// this.matterbridge.matterbridgeQrPairingCode = pairingCodes?.qrPairingCode;
|
|
1548
|
-
// this.matterbridge.matterbridgeManualPairingCode = pairingCodes?.manualPairingCode;
|
|
1549
1259
|
this.wssSendRefreshRequired('matterbridgeAdvertise');
|
|
1550
1260
|
this.wssSendSnackbarMessage(`Started fabrics share`, 0);
|
|
1551
1261
|
client.send(JSON.stringify({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, response: pairingCodes, success: true }));
|
|
@@ -1668,22 +1378,22 @@ export class Frontend extends EventEmitter {
|
|
|
1668
1378
|
if (isValidString(data.params.value, 4)) {
|
|
1669
1379
|
this.log.debug('Matterbridge logger level:', data.params.value);
|
|
1670
1380
|
if (data.params.value === 'Debug') {
|
|
1671
|
-
await this.matterbridge.setLogLevel("debug"
|
|
1381
|
+
await this.matterbridge.setLogLevel("debug");
|
|
1672
1382
|
}
|
|
1673
1383
|
else if (data.params.value === 'Info') {
|
|
1674
|
-
await this.matterbridge.setLogLevel("info"
|
|
1384
|
+
await this.matterbridge.setLogLevel("info");
|
|
1675
1385
|
}
|
|
1676
1386
|
else if (data.params.value === 'Notice') {
|
|
1677
|
-
await this.matterbridge.setLogLevel("notice"
|
|
1387
|
+
await this.matterbridge.setLogLevel("notice");
|
|
1678
1388
|
}
|
|
1679
1389
|
else if (data.params.value === 'Warn') {
|
|
1680
|
-
await this.matterbridge.setLogLevel("warn"
|
|
1390
|
+
await this.matterbridge.setLogLevel("warn");
|
|
1681
1391
|
}
|
|
1682
1392
|
else if (data.params.value === 'Error') {
|
|
1683
|
-
await this.matterbridge.setLogLevel("error"
|
|
1393
|
+
await this.matterbridge.setLogLevel("error");
|
|
1684
1394
|
}
|
|
1685
1395
|
else if (data.params.value === 'Fatal') {
|
|
1686
|
-
await this.matterbridge.setLogLevel("fatal"
|
|
1396
|
+
await this.matterbridge.setLogLevel("fatal");
|
|
1687
1397
|
}
|
|
1688
1398
|
await this.matterbridge.nodeContext?.set('matterbridgeLogLevel', this.log.logLevel);
|
|
1689
1399
|
client.send(JSON.stringify({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true }));
|
|
@@ -1694,7 +1404,6 @@ export class Frontend extends EventEmitter {
|
|
|
1694
1404
|
this.log.debug('Matterbridge file log:', data.params.value);
|
|
1695
1405
|
this.matterbridge.matterbridgeInformation.fileLogger = data.params.value;
|
|
1696
1406
|
await this.matterbridge.nodeContext?.set('matterbridgeFileLog', data.params.value);
|
|
1697
|
-
// Create the file logger for matterbridge
|
|
1698
1407
|
if (data.params.value)
|
|
1699
1408
|
AnsiLogger.setGlobalLogfile(path.join(this.matterbridge.matterbridgeDirectory, this.matterbridge.matterbridgeLoggerFile), this.matterbridge.matterbridgeInformation.loggerLevel, true);
|
|
1700
1409
|
else
|
|
@@ -1848,19 +1557,15 @@ export class Frontend extends EventEmitter {
|
|
|
1848
1557
|
return;
|
|
1849
1558
|
}
|
|
1850
1559
|
const config = plugin.configJson;
|
|
1851
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1852
1560
|
const select = plugin.schemaJson?.properties?.blackList?.selectFrom;
|
|
1853
|
-
// this.log.debug(`SelectDevice(selectMode ${select}) data ${debugStringify(data)}`);
|
|
1854
1561
|
if (select === 'serial')
|
|
1855
1562
|
this.log.info(`Selected device serial ${data.params.serial}`);
|
|
1856
1563
|
if (select === 'name')
|
|
1857
1564
|
this.log.info(`Selected device name ${data.params.name}`);
|
|
1858
1565
|
if (config && select && (select === 'serial' || select === 'name')) {
|
|
1859
|
-
// Remove postfix from the serial if it exists
|
|
1860
1566
|
if (config.postfix) {
|
|
1861
1567
|
data.params.serial = data.params.serial.replace('-' + config.postfix, '');
|
|
1862
1568
|
}
|
|
1863
|
-
// Add the serial to the whiteList if the whiteList exists and the serial or name is not already in it
|
|
1864
1569
|
if (isValidArray(config.whiteList, 1)) {
|
|
1865
1570
|
if (select === 'serial' && !config.whiteList.includes(data.params.serial)) {
|
|
1866
1571
|
config.whiteList.push(data.params.serial);
|
|
@@ -1869,7 +1574,6 @@ export class Frontend extends EventEmitter {
|
|
|
1869
1574
|
config.whiteList.push(data.params.name);
|
|
1870
1575
|
}
|
|
1871
1576
|
}
|
|
1872
|
-
// Remove the serial from the blackList if the blackList exists and the serial or name is in it
|
|
1873
1577
|
if (isValidArray(config.blackList, 1)) {
|
|
1874
1578
|
if (select === 'serial' && config.blackList.includes(data.params.serial)) {
|
|
1875
1579
|
config.blackList = config.blackList.filter((item) => item !== data.params.serial);
|
|
@@ -1900,9 +1604,7 @@ export class Frontend extends EventEmitter {
|
|
|
1900
1604
|
return;
|
|
1901
1605
|
}
|
|
1902
1606
|
const config = plugin.configJson;
|
|
1903
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1904
1607
|
const select = plugin.schemaJson?.properties?.blackList?.selectFrom;
|
|
1905
|
-
// this.log.debug(`UnselectDevice(selectMode ${select}) data ${debugStringify(data)}`);
|
|
1906
1608
|
if (select === 'serial')
|
|
1907
1609
|
this.log.info(`Unselected device serial ${data.params.serial}`);
|
|
1908
1610
|
if (select === 'name')
|
|
@@ -1911,7 +1613,6 @@ export class Frontend extends EventEmitter {
|
|
|
1911
1613
|
if (config.postfix) {
|
|
1912
1614
|
data.params.serial = data.params.serial.replace('-' + config.postfix, '');
|
|
1913
1615
|
}
|
|
1914
|
-
// Remove the serial from the whiteList if the whiteList exists and the serial is in it
|
|
1915
1616
|
if (isValidArray(config.whiteList, 1)) {
|
|
1916
1617
|
if (select === 'serial' && config.whiteList.includes(data.params.serial)) {
|
|
1917
1618
|
config.whiteList = config.whiteList.filter((item) => item !== data.params.serial);
|
|
@@ -1920,7 +1621,6 @@ export class Frontend extends EventEmitter {
|
|
|
1920
1621
|
config.whiteList = config.whiteList.filter((item) => item !== data.params.name);
|
|
1921
1622
|
}
|
|
1922
1623
|
}
|
|
1923
|
-
// Add the serial to the blackList
|
|
1924
1624
|
if (isValidArray(config.blackList)) {
|
|
1925
1625
|
if (select === 'serial' && !config.blackList.includes(data.params.serial)) {
|
|
1926
1626
|
config.blackList.push(data.params.serial);
|
|
@@ -1954,251 +1654,126 @@ export class Frontend extends EventEmitter {
|
|
|
1954
1654
|
this.log.error(`Error parsing message "${message}" from websocket client:`, error instanceof Error ? error.message : error);
|
|
1955
1655
|
}
|
|
1956
1656
|
}
|
|
1957
|
-
/**
|
|
1958
|
-
* Sends a WebSocket log message to all connected clients. The function is called by AnsiLogger.setGlobalCallback.
|
|
1959
|
-
*
|
|
1960
|
-
* @param {string} level - The logger level of the message: debug info notice warn error fatal...
|
|
1961
|
-
* @param {string} time - The time string of the message
|
|
1962
|
-
* @param {string} name - The logger name of the message
|
|
1963
|
-
* @param {string} message - The content of the message.
|
|
1964
|
-
*
|
|
1965
|
-
* @remarks
|
|
1966
|
-
* The function removes ANSI escape codes, leading asterisks, non-printable characters, and replaces all occurrences of \t and \n.
|
|
1967
|
-
* It also replaces all occurrences of \" with " and angle-brackets with < and >.
|
|
1968
|
-
* The function sends the message to all connected clients.
|
|
1969
|
-
*/
|
|
1970
1657
|
wssSendMessage(level, time, name, message) {
|
|
1971
1658
|
if (!level || !time || !name || !message)
|
|
1972
1659
|
return;
|
|
1973
|
-
// Remove ANSI escape codes from the message
|
|
1974
|
-
// eslint-disable-next-line no-control-regex
|
|
1975
1660
|
message = message.replace(/\x1B\[[0-9;]*[m|s|u|K]/g, '');
|
|
1976
|
-
// Remove leading asterisks from the message
|
|
1977
1661
|
message = message.replace(/^\*+/, '');
|
|
1978
|
-
// Replace all occurrences of \t and \n
|
|
1979
1662
|
message = message.replace(/[\t\n]/g, '');
|
|
1980
|
-
// Remove non-printable characters
|
|
1981
|
-
// eslint-disable-next-line no-control-regex
|
|
1982
1663
|
message = message.replace(/[\x00-\x1F\x7F]/g, '');
|
|
1983
|
-
// Replace all occurrences of \" with "
|
|
1984
1664
|
message = message.replace(/\\"/g, '"');
|
|
1985
|
-
// Replace all occurrences of angle-brackets with < and >"
|
|
1986
1665
|
message = message.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
1987
|
-
// Define the maximum allowed length for continuous characters without a space
|
|
1988
1666
|
const maxContinuousLength = 100;
|
|
1989
1667
|
const keepStartLength = 20;
|
|
1990
1668
|
const keepEndLength = 20;
|
|
1991
|
-
// Split the message into words
|
|
1992
1669
|
message = message
|
|
1993
1670
|
.split(' ')
|
|
1994
1671
|
.map((word) => {
|
|
1995
|
-
// If the word length exceeds the max continuous length, insert spaces and truncate
|
|
1996
1672
|
if (word.length > maxContinuousLength) {
|
|
1997
1673
|
return word.slice(0, keepStartLength) + ' ... ' + word.slice(-keepEndLength);
|
|
1998
1674
|
}
|
|
1999
1675
|
return word;
|
|
2000
1676
|
})
|
|
2001
1677
|
.join(' ');
|
|
2002
|
-
// Send the message to all connected clients
|
|
2003
1678
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2004
1679
|
if (client.readyState === WebSocket.OPEN) {
|
|
2005
1680
|
client.send(JSON.stringify({ id: WS_ID_LOG, src: 'Matterbridge', level, time, name, message }));
|
|
2006
1681
|
}
|
|
2007
1682
|
});
|
|
2008
1683
|
}
|
|
2009
|
-
/**
|
|
2010
|
-
* Sends a need to refresh WebSocket message to all connected clients.
|
|
2011
|
-
*
|
|
2012
|
-
* @param {string} changed - The changed value. If null, the whole page will be refreshed.
|
|
2013
|
-
* possible values:
|
|
2014
|
-
* - 'matterbridgeLatestVersion'
|
|
2015
|
-
* - 'matterbridgeDevVersion'
|
|
2016
|
-
* - 'matterbridgeAdvertise'
|
|
2017
|
-
* - 'online'
|
|
2018
|
-
* - 'offline'
|
|
2019
|
-
* - 'reachability'
|
|
2020
|
-
* - 'settings'
|
|
2021
|
-
* - 'plugins'
|
|
2022
|
-
* - 'pluginsRestart'
|
|
2023
|
-
* - 'devices'
|
|
2024
|
-
* - 'fabrics'
|
|
2025
|
-
* - 'sessions'
|
|
2026
|
-
*/
|
|
2027
1684
|
wssSendRefreshRequired(changed = null) {
|
|
2028
1685
|
this.log.debug('Sending a refresh required message to all connected clients');
|
|
2029
|
-
// Send the message to all connected clients
|
|
2030
1686
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2031
1687
|
if (client.readyState === WebSocket.OPEN) {
|
|
2032
1688
|
client.send(JSON.stringify({ id: WS_ID_REFRESH_NEEDED, src: 'Matterbridge', dst: 'Frontend', method: 'refresh_required', params: { changed: changed } }));
|
|
2033
1689
|
}
|
|
2034
1690
|
});
|
|
2035
1691
|
}
|
|
2036
|
-
/**
|
|
2037
|
-
* Sends a need to restart WebSocket message to all connected clients.
|
|
2038
|
-
*
|
|
2039
|
-
* @param {boolean} snackbar - If true, a snackbar message will be sent to all connected clients. Default is true.
|
|
2040
|
-
* @param {boolean} fixed - If true, the restart is fixed and will not be reset by plugin restarts. Default is false.
|
|
2041
|
-
*/
|
|
2042
1692
|
wssSendRestartRequired(snackbar = true, fixed = false) {
|
|
2043
1693
|
this.log.debug('Sending a restart required message to all connected clients');
|
|
2044
1694
|
this.matterbridge.matterbridgeInformation.restartRequired = true;
|
|
2045
1695
|
this.matterbridge.matterbridgeInformation.fixedRestartRequired = fixed;
|
|
2046
1696
|
if (snackbar === true)
|
|
2047
1697
|
this.wssSendSnackbarMessage(`Restart required`, 0);
|
|
2048
|
-
// Send the message to all connected clients
|
|
2049
1698
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2050
1699
|
if (client.readyState === WebSocket.OPEN) {
|
|
2051
1700
|
client.send(JSON.stringify({ id: WS_ID_RESTART_NEEDED, src: 'Matterbridge', dst: 'Frontend', method: 'restart_required', params: { fixed } }));
|
|
2052
1701
|
}
|
|
2053
1702
|
});
|
|
2054
1703
|
}
|
|
2055
|
-
/**
|
|
2056
|
-
* Sends a no need to restart WebSocket message to all connected clients.
|
|
2057
|
-
*
|
|
2058
|
-
* @param {boolean} snackbar - If true, the snackbar message will be cleared from all connected clients.
|
|
2059
|
-
*/
|
|
2060
1704
|
wssSendRestartNotRequired(snackbar = true) {
|
|
2061
1705
|
this.log.debug('Sending a restart not required message to all connected clients');
|
|
2062
1706
|
this.matterbridge.matterbridgeInformation.restartRequired = false;
|
|
2063
1707
|
if (snackbar === true)
|
|
2064
1708
|
this.wssSendCloseSnackbarMessage(`Restart required`);
|
|
2065
|
-
// Send the message to all connected clients
|
|
2066
1709
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2067
1710
|
if (client.readyState === WebSocket.OPEN) {
|
|
2068
1711
|
client.send(JSON.stringify({ id: WS_ID_RESTART_NEEDED, src: 'Matterbridge', dst: 'Frontend', method: 'restart_not_required', params: {} }));
|
|
2069
1712
|
}
|
|
2070
1713
|
});
|
|
2071
1714
|
}
|
|
2072
|
-
/**
|
|
2073
|
-
* Sends a need to update WebSocket message to all connected clients.
|
|
2074
|
-
*
|
|
2075
|
-
* @param {boolean} devVersion - If true, the update is for a development version.
|
|
2076
|
-
*/
|
|
2077
1715
|
wssSendUpdateRequired(devVersion = false) {
|
|
2078
1716
|
this.log.debug('Sending an update required message to all connected clients');
|
|
2079
1717
|
this.matterbridge.matterbridgeInformation.updateRequired = true;
|
|
2080
|
-
// Send the message to all connected clients
|
|
2081
1718
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2082
1719
|
if (client.readyState === WebSocket.OPEN) {
|
|
2083
1720
|
client.send(JSON.stringify({ id: WS_ID_UPDATE_NEEDED, src: 'Matterbridge', dst: 'Frontend', method: devVersion ? 'update_required_dev' : 'update_required', params: {} }));
|
|
2084
1721
|
}
|
|
2085
1722
|
});
|
|
2086
1723
|
}
|
|
2087
|
-
/**
|
|
2088
|
-
* Sends a cpu update message to all connected clients.
|
|
2089
|
-
*
|
|
2090
|
-
* @param {number} cpuUsage - The CPU usage percentage to send.
|
|
2091
|
-
*/
|
|
2092
1724
|
wssSendCpuUpdate(cpuUsage) {
|
|
2093
1725
|
if (hasParameter('debug'))
|
|
2094
1726
|
this.log.debug('Sending a cpu update message to all connected clients');
|
|
2095
|
-
// Send the message to all connected clients
|
|
2096
1727
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2097
1728
|
if (client.readyState === WebSocket.OPEN) {
|
|
2098
1729
|
client.send(JSON.stringify({ id: WS_ID_CPU_UPDATE, src: 'Matterbridge', dst: 'Frontend', method: 'cpu_update', params: { cpuUsage } }));
|
|
2099
1730
|
}
|
|
2100
1731
|
});
|
|
2101
1732
|
}
|
|
2102
|
-
/**
|
|
2103
|
-
* Sends a memory update message to all connected clients.
|
|
2104
|
-
*
|
|
2105
|
-
* @param {string} totalMemory - The total memory in bytes.
|
|
2106
|
-
* @param {string} freeMemory - The free memory in bytes.
|
|
2107
|
-
* @param {string} rss - The resident set size in bytes.
|
|
2108
|
-
* @param {string} heapTotal - The total heap memory in bytes.
|
|
2109
|
-
* @param {string} heapUsed - The used heap memory in bytes.
|
|
2110
|
-
* @param {string} external - The external memory in bytes.
|
|
2111
|
-
* @param {string} arrayBuffers - The array buffers memory in bytes.
|
|
2112
|
-
*/
|
|
2113
1733
|
wssSendMemoryUpdate(totalMemory, freeMemory, rss, heapTotal, heapUsed, external, arrayBuffers) {
|
|
2114
1734
|
if (hasParameter('debug'))
|
|
2115
1735
|
this.log.debug('Sending a memory update message to all connected clients');
|
|
2116
|
-
// Send the message to all connected clients
|
|
2117
1736
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2118
1737
|
if (client.readyState === WebSocket.OPEN) {
|
|
2119
1738
|
client.send(JSON.stringify({ id: WS_ID_MEMORY_UPDATE, src: 'Matterbridge', dst: 'Frontend', method: 'memory_update', params: { totalMemory, freeMemory, rss, heapTotal, heapUsed, external, arrayBuffers } }));
|
|
2120
1739
|
}
|
|
2121
1740
|
});
|
|
2122
1741
|
}
|
|
2123
|
-
/**
|
|
2124
|
-
* Sends an uptime update message to all connected clients.
|
|
2125
|
-
*
|
|
2126
|
-
* @param {string} systemUptime - The system uptime in a human-readable format.
|
|
2127
|
-
* @param {string} processUptime - The process uptime in a human-readable format.
|
|
2128
|
-
*/
|
|
2129
1742
|
wssSendUptimeUpdate(systemUptime, processUptime) {
|
|
2130
1743
|
if (hasParameter('debug'))
|
|
2131
1744
|
this.log.debug('Sending a uptime update message to all connected clients');
|
|
2132
|
-
// Send the message to all connected clients
|
|
2133
1745
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2134
1746
|
if (client.readyState === WebSocket.OPEN) {
|
|
2135
1747
|
client.send(JSON.stringify({ id: WS_ID_UPTIME_UPDATE, src: 'Matterbridge', dst: 'Frontend', method: 'uptime_update', params: { systemUptime, processUptime } }));
|
|
2136
1748
|
}
|
|
2137
1749
|
});
|
|
2138
1750
|
}
|
|
2139
|
-
/**
|
|
2140
|
-
* Sends an open snackbar message to all connected clients.
|
|
2141
|
-
*
|
|
2142
|
-
* @param {string} message - The message to send.
|
|
2143
|
-
* @param {number} timeout - The timeout in seconds for the snackbar message.
|
|
2144
|
-
* @param {'info' | 'warning' | 'error' | 'success'} severity - The severity of the snackbar message (default info).
|
|
2145
|
-
*/
|
|
2146
1751
|
wssSendSnackbarMessage(message, timeout = 5, severity = 'info') {
|
|
2147
1752
|
this.log.debug('Sending a snackbar message to all connected clients');
|
|
2148
|
-
// Send the message to all connected clients
|
|
2149
1753
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2150
1754
|
if (client.readyState === WebSocket.OPEN) {
|
|
2151
1755
|
client.send(JSON.stringify({ id: WS_ID_SNACKBAR, src: 'Matterbridge', dst: 'Frontend', params: { message, timeout, severity } }));
|
|
2152
1756
|
}
|
|
2153
1757
|
});
|
|
2154
1758
|
}
|
|
2155
|
-
/**
|
|
2156
|
-
* Sends a close snackbar message to all connected clients.
|
|
2157
|
-
*
|
|
2158
|
-
* @param {string} message - The message to send.
|
|
2159
|
-
*/
|
|
2160
1759
|
wssSendCloseSnackbarMessage(message) {
|
|
2161
1760
|
this.log.debug('Sending a close snackbar message to all connected clients');
|
|
2162
|
-
// Send the message to all connected clients
|
|
2163
1761
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2164
1762
|
if (client.readyState === WebSocket.OPEN) {
|
|
2165
1763
|
client.send(JSON.stringify({ id: WS_ID_CLOSE_SNACKBAR, src: 'Matterbridge', dst: 'Frontend', params: { message } }));
|
|
2166
1764
|
}
|
|
2167
1765
|
});
|
|
2168
1766
|
}
|
|
2169
|
-
/**
|
|
2170
|
-
* Sends an attribute update message to all connected WebSocket clients.
|
|
2171
|
-
*
|
|
2172
|
-
* @param {string | undefined} plugin - The name of the plugin.
|
|
2173
|
-
* @param {string | undefined} serialNumber - The serial number of the device.
|
|
2174
|
-
* @param {string | undefined} uniqueId - The unique identifier of the device.
|
|
2175
|
-
* @param {string} cluster - The cluster name where the attribute belongs.
|
|
2176
|
-
* @param {string} attribute - The name of the attribute that changed.
|
|
2177
|
-
* @param {number | string | boolean} value - The new value of the attribute.
|
|
2178
|
-
*
|
|
2179
|
-
* @remarks
|
|
2180
|
-
* This method logs a debug message and sends a JSON-formatted message to all connected WebSocket clients
|
|
2181
|
-
* with the updated attribute information.
|
|
2182
|
-
*/
|
|
2183
1767
|
wssSendAttributeChangedMessage(plugin, serialNumber, uniqueId, cluster, attribute, value) {
|
|
2184
1768
|
this.log.debug('Sending an attribute update message to all connected clients');
|
|
2185
|
-
// Send the message to all connected clients
|
|
2186
1769
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2187
1770
|
if (client.readyState === WebSocket.OPEN) {
|
|
2188
1771
|
client.send(JSON.stringify({ id: WS_ID_STATEUPDATE, src: 'Matterbridge', dst: 'Frontend', method: 'state_update', params: { plugin, serialNumber, uniqueId, cluster, attribute, value } }));
|
|
2189
1772
|
}
|
|
2190
1773
|
});
|
|
2191
1774
|
}
|
|
2192
|
-
/**
|
|
2193
|
-
* Sends a message to all connected clients.
|
|
2194
|
-
*
|
|
2195
|
-
* @param {number} id - The message id.
|
|
2196
|
-
* @param {string} method - The message method.
|
|
2197
|
-
* @param {Record<string, string | number | boolean>} params - The message parameters.
|
|
2198
|
-
*/
|
|
2199
1775
|
wssBroadcastMessage(id, method, params) {
|
|
2200
1776
|
this.log.debug(`Sending a broadcast message id ${id} method ${method} params ${debugStringify(params ?? {})} to all connected clients`);
|
|
2201
|
-
// Send the message to all connected clients
|
|
2202
1777
|
this.webSocketServer?.clients.forEach((client) => {
|
|
2203
1778
|
if (client.readyState === WebSocket.OPEN) {
|
|
2204
1779
|
client.send(JSON.stringify({ id, src: 'Matterbridge', dst: 'Frontend', method, params }));
|
|
@@ -2206,4 +1781,3 @@ export class Frontend extends EventEmitter {
|
|
|
2206
1781
|
});
|
|
2207
1782
|
}
|
|
2208
1783
|
}
|
|
2209
|
-
//# sourceMappingURL=frontend.js.map
|