@matterbridge/core 3.11.2-dev-20261104-98c7a1f → 3.11.2-dev-20261106-e5bb80a

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/backend.js CHANGED
@@ -329,14 +329,14 @@ export class Backend extends EventEmitter {
329
329
  }
330
330
  async getApiSettings() {
331
331
  const start = performance.now();
332
- const response = await this.server.fetch({ type: 'matterbridge_apisettings', src: 'frontend', dst: 'matterbridge', params: {} });
332
+ const response = await this.server.fetch({ type: 'matterbridge_apisettings', src: this.server.name, dst: 'matterbridge', params: {} });
333
333
  if (this.diagnostic)
334
334
  writeDiagnostic('Backend', `getApiSettings() took ${(performance.now() - start).toFixed(2)} ms`);
335
335
  return response.result.data;
336
336
  }
337
337
  async getApiPlugins() {
338
338
  const start = performance.now();
339
- const response = await this.server.fetch({ type: 'plugins_apipluginarray', src: 'frontend', dst: 'plugins', params: undefined });
339
+ const response = await this.server.fetch({ type: 'plugins_apipluginarray', src: this.server.name, dst: 'plugins', params: undefined });
340
340
  if (this.diagnostic)
341
341
  writeDiagnostic('Backend', `getApiPlugins() took ${(performance.now() - start).toFixed(2)} ms`);
342
342
  return response.result.plugins;
@@ -256,12 +256,40 @@ export class BackendWsServer {
256
256
  this.wssSendRefreshRequired('matter', { matter });
257
257
  }
258
258
  else if (data.method === '/api/unregister-device') {
259
+ if (!isValidString(data.params.pluginName, 1)) {
260
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter pluginName in /api/unregister-device' });
261
+ return;
262
+ }
263
+ if (!isValidString(data.params.serialNumber, 1)) {
264
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter serialNumber in /api/unregister-device' });
265
+ return;
266
+ }
267
+ if (!isValidString(data.params.uniqueId, 1)) {
268
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter uniqueId in /api/unregister-device' });
269
+ return;
270
+ }
259
271
  this.wssSendSnackbarMessage('Resetting the device...');
260
272
  const { pluginName, serialNumber, uniqueId } = data.params;
261
273
  this.server.request({ type: 'platform_unregister_device', src: 'frontend', dst: 'platform', params: { pluginName, serialNumber, uniqueId } });
262
274
  sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true });
263
275
  }
264
276
  else if (data.method === '/api/rename-device') {
277
+ if (!isValidString(data.params.pluginName, 1)) {
278
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter pluginName in /api/rename-device' });
279
+ return;
280
+ }
281
+ if (!isValidString(data.params.serialNumber, 1)) {
282
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter serialNumber in /api/rename-device' });
283
+ return;
284
+ }
285
+ if (!isValidString(data.params.uniqueId, 1)) {
286
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter uniqueId in /api/rename-device' });
287
+ return;
288
+ }
289
+ if (!isValidString(data.params.label, 1)) {
290
+ sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, error: 'Wrong parameter label in /api/rename-device' });
291
+ return;
292
+ }
265
293
  this.wssSendSnackbarMessage('Renaming the device...');
266
294
  const { pluginName, serialNumber, uniqueId, label } = data.params;
267
295
  this.server.request({ type: 'platform_rename_device', src: 'frontend', dst: 'platform', params: { pluginName, serialNumber, uniqueId, label } });
@@ -37,6 +37,8 @@ export class MatterbridgeServiceAreaServer extends ServiceAreaServer.with(Servic
37
37
  ? { areaId: area.areaId, status: ServiceArea.OperationalStatus.Skipped, totalOperationalTime: area.totalOperationalTime, estimatedTime: area.estimatedTime }
38
38
  : area);
39
39
  }
40
+ if (response.status === ServiceArea.SkipAreaStatus.Success)
41
+ this.endpoint.emitCommand(ServiceArea, 'skipArea', request, this.context);
40
42
  return response;
41
43
  }
42
44
  }
@@ -1,20 +1,29 @@
1
1
  import { WebRtcTransportRequestorServer } from '@matter/node/behaviors/web-rtc-transport-requestor';
2
2
  import { WebRtcTransportRequestor } from '@matter/types/clusters/web-rtc-transport-requestor';
3
3
  import { protectPrototype } from '../protectPrototypes.js';
4
+ import { MatterbridgeServer } from './matterbridgeServer.js';
4
5
  export class MatterbridgeWebRtcTransportRequestorServer extends WebRtcTransportRequestorServer {
5
6
  async offer(request) {
7
+ const device = this.endpoint.stateOf(MatterbridgeServer);
8
+ device.log.info(`MatterbridgeWebRtcTransportRequestorServer: received an SDP offer for session ${request.webRtcSessionId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
6
9
  await super.offer(request);
7
10
  this.endpoint.emitCommand(WebRtcTransportRequestor, 'offer', request, this.context);
8
11
  }
9
12
  async answer(request) {
13
+ const device = this.endpoint.stateOf(MatterbridgeServer);
14
+ device.log.info(`MatterbridgeWebRtcTransportRequestorServer: received an SDP answer for session ${request.webRtcSessionId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
10
15
  await super.answer(request);
11
16
  this.endpoint.emitCommand(WebRtcTransportRequestor, 'answer', request, this.context);
12
17
  }
13
18
  async iceCandidates(request) {
19
+ const device = this.endpoint.stateOf(MatterbridgeServer);
20
+ device.log.info(`MatterbridgeWebRtcTransportRequestorServer: received ${request.iceCandidates.length} ICE candidate(s) for session ${request.webRtcSessionId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
14
21
  await super.iceCandidates(request);
15
22
  this.endpoint.emitCommand(WebRtcTransportRequestor, 'iceCandidates', request, this.context);
16
23
  }
17
24
  async end(request) {
25
+ const device = this.endpoint.stateOf(MatterbridgeServer);
26
+ device.log.info(`MatterbridgeWebRtcTransportRequestorServer: ending session ${request.webRtcSessionId} with reason ${request.reason} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
18
27
  await super.end(request);
19
28
  this.endpoint.emitCommand(WebRtcTransportRequestor, 'end', request, this.context);
20
29
  }
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from 'node:events';
2
- import type { ApiClusters, ApiDevice, ApiMatter, ApiPlugin, ApiSettings, BridgeStatus, PluginStatusUpdate, RefreshRequiredChanged, WsMessageBroadcast } from '@matterbridge/types';
2
+ import type { ApiClusters, ApiDevice, ApiMatter, BridgeStatus, PluginStatusUpdate, RefreshRequiredChanged, WsMessageBroadcast } from '@matterbridge/types';
3
3
  import { LogLevel } from 'node-ansi-logger';
4
4
  import type { Matterbridge } from './matterbridge.js';
5
5
  interface FrontendEvents {
@@ -34,8 +34,6 @@ export declare class Frontend extends EventEmitter<FrontendEvents> {
34
34
  private validateReq;
35
35
  start(port?: number): Promise<void>;
36
36
  stop(): Promise<void>;
37
- getApiSettings(): ApiSettings;
38
- getApiPlugins(): ApiPlugin[];
39
37
  getApiDevices(pluginName?: string, extended?: boolean): ApiDevice[];
40
38
  getApiCluster(pluginName: string, endpointNumber: number, serialNumber: string, uniqueId: string): ApiClusters | undefined;
41
39
  generateDiagnostic(): Promise<void>;
package/dist/frontend.js CHANGED
@@ -7,11 +7,11 @@ import { CommissioningOptions } from '@matter/types/commissioning';
7
7
  import { FabricIndex } from '@matter/types/datatype';
8
8
  import { BroadcastServer } from '@matterbridge/thread/server';
9
9
  import { MATTER_LOGGER_FILE, MATTER_STORAGE_DIR, MATTERBRIDGE_DIAGNOSTIC_FILE, MATTERBRIDGE_HISTORY_FILE, MATTERBRIDGE_LOGGER_FILE, NODE_STORAGE_DIR, plg, } from '@matterbridge/types';
10
- import { constrainedMemory, isBun, memoryFootprint } from '@matterbridge/utils/bun';
10
+ import { isBun } from '@matterbridge/utils/bun';
11
11
  import { getParameter, hasAnyParameter, hasParameter } from '@matterbridge/utils/cli';
12
12
  import { writeDiagnostic } from '@matterbridge/utils/diagnostic';
13
13
  import { getErrorMessage, inspectError, logError } from '@matterbridge/utils/error';
14
- import { formatBytes, formatPercent, formatUptime } from '@matterbridge/utils/format';
14
+ import { formatBytes } from '@matterbridge/utils/format';
15
15
  import { logModuleLoaded } from '@matterbridge/utils/loader';
16
16
  import { isValidArray, isValidBoolean, isValidNumber, isValidObject, isValidString } from '@matterbridge/utils/validate';
17
17
  import { fireAndForget, withTimeout } from '@matterbridge/utils/wait';
@@ -517,17 +517,29 @@ export class Frontend extends EventEmitter {
517
517
  };
518
518
  res.status(200).json(memoryReport);
519
519
  });
520
- this.expressApp.get('/api/settings', (req, res) => {
520
+ this.expressApp.get('/api/settings', async (req, res) => {
521
521
  this.log.debug('The frontend sent /api/settings');
522
522
  if (!this.validateReq(req, res))
523
523
  return;
524
- res.json(this.getApiSettings());
524
+ try {
525
+ res.json((await this.server.fetch({ type: 'matterbridge_apisettings', src: this.server.name, dst: 'matterbridge', params: {} }, this.serverFetchTimeout)).result.data);
526
+ }
527
+ catch (error) {
528
+ logError(this.log, 'Error in /api/settings fetching the settings from matterbridge', error);
529
+ res.status(500).send('Error fetching the settings.');
530
+ }
525
531
  });
526
- this.expressApp.get('/api/plugins', (req, res) => {
532
+ this.expressApp.get('/api/plugins', async (req, res) => {
527
533
  this.log.debug('The frontend sent /api/plugins');
528
534
  if (!this.validateReq(req, res))
529
535
  return;
530
- res.json(this.getApiPlugins());
536
+ try {
537
+ res.json((await this.server.fetch({ type: 'plugins_apipluginarray', src: this.server.name, dst: 'plugins', params: undefined }, this.serverFetchTimeout)).result.plugins);
538
+ }
539
+ catch (error) {
540
+ logError(this.log, 'Error in /api/plugins fetching the plugins from the plugin manager', error);
541
+ res.status(500).send('Error fetching the plugins.');
542
+ }
531
543
  });
532
544
  this.expressApp.get('/api/devices', (req, res) => {
533
545
  this.log.debug('The frontend sent /api/devices');
@@ -820,6 +832,8 @@ export class Frontend extends EventEmitter {
820
832
  this.log.debug(`Registering frontend route for plugin ${plg}${plugin.name}${db} at ${GREEN}/plugins/${plugin.name}${db} with path ${CYAN}${plugin.frontendPath}${db}`);
821
833
  this.expressApp.use(`/plugins/${plugin.name}`, express.static(path.dirname(plugin.frontendPath)));
822
834
  const apiHandler = async (req, res) => {
835
+ if (!this.validateReq(req, res))
836
+ return;
823
837
  const method = req.method.toUpperCase();
824
838
  const path = Array.isArray(req.params.path) ? req.params.path[0] : req.params.path;
825
839
  const query = req.query;
@@ -918,97 +932,6 @@ export class Frontend extends EventEmitter {
918
932
  }
919
933
  this.log.debug('Frontend stopped successfully');
920
934
  }
921
- getApiSettings() {
922
- this.matterbridge.systemInformation.totalMemory = formatBytes(os.totalmem());
923
- this.matterbridge.systemInformation.constrainedMemory = formatBytes(constrainedMemory());
924
- this.matterbridge.systemInformation.freeMemory = formatBytes(os.freemem());
925
- this.matterbridge.systemInformation.systemUptime = formatUptime(os.uptime());
926
- this.matterbridge.systemInformation.processUptime = formatUptime(Math.floor(process.uptime()));
927
- this.matterbridge.systemInformation.cpuUsage = formatPercent(0);
928
- this.matterbridge.systemInformation.processCpuUsage = formatPercent(0);
929
- this.matterbridge.systemInformation.rss = formatBytes(memoryFootprint());
930
- this.matterbridge.systemInformation.heapTotal = formatBytes(process.memoryUsage().heapTotal);
931
- this.matterbridge.systemInformation.heapUsed = formatBytes(process.memoryUsage().heapUsed);
932
- const info = {
933
- homeDirectory: this.matterbridge.homeDirectory,
934
- rootDirectory: this.matterbridge.rootDirectory,
935
- matterbridgeDirectory: this.matterbridge.matterbridgeDirectory,
936
- matterbridgePluginDirectory: this.matterbridge.matterbridgePluginDirectory,
937
- matterbridgeCertDirectory: this.matterbridge.matterbridgeCertDirectory,
938
- globalModulesDirectory: this.matterbridge.globalModulesDirectory,
939
- matterbridgeVersion: this.matterbridge.matterbridgeVersion,
940
- matterbridgeLatestVersion: this.matterbridge.matterbridgeLatestVersion,
941
- matterbridgeDevVersion: this.matterbridge.matterbridgeDevVersion,
942
- frontendVersion: this.matterbridge.frontendVersion,
943
- dockerDev: this.matterbridge.dockerDev,
944
- dockerVersion: this.matterbridge.dockerVersion,
945
- dockerLatestVersion: this.matterbridge.dockerLatestVersion,
946
- dockerDevVersion: this.matterbridge.dockerDevVersion,
947
- bridgeMode: this.matterbridge.bridgeMode,
948
- restartMode: this.matterbridge.restartMode,
949
- virtualMode: this.matterbridge.virtualMode,
950
- bridgeStatus: this.matterbridge.bridgeStatus,
951
- profile: this.matterbridge.profile,
952
- loggerLevel: this.matterbridge.logLevel,
953
- fileLogger: this.matterbridge.fileLogger,
954
- matterLoggerLevel: this.matterbridge.matterLogLevel,
955
- matterFileLogger: this.matterbridge.matterFileLogger,
956
- matterMdnsInterface: this.matterbridge.mdnsInterface,
957
- matterIpv4Address: this.matterbridge.ipv4Address,
958
- matterIpv6Address: this.matterbridge.ipv6Address,
959
- matterPort: this.matterbridge.initialPort || 5540,
960
- matterDiscriminator: this.matterbridge.initialDiscriminator,
961
- matterPasscode: this.matterbridge.initialPasscode,
962
- readOnly: this.matterbridge.readOnly,
963
- restartRequired: this.matterbridge.restartRequired,
964
- fixedRestartRequired: this.matterbridge.fixedRestartRequired,
965
- updateRequired: this.matterbridge.updateRequired,
966
- startupAt: this.matterbridge.startupAt,
967
- shutdownAt: this.matterbridge.shutdownAt,
968
- runningTimes: this.matterbridge.runningTimes,
969
- runningDays: this.matterbridge.runningDays,
970
- };
971
- return { systemInformation: this.matterbridge.systemInformation, matterbridgeInformation: info };
972
- }
973
- getApiPlugins() {
974
- if (this.matterbridge.hasCleanupStarted)
975
- return [];
976
- const plugins = [];
977
- for (const plugin of this.matterbridge.plugins.array()) {
978
- plugins.push({
979
- path: plugin.path,
980
- type: plugin.type,
981
- name: plugin.name,
982
- version: plugin.version,
983
- private: plugin.private,
984
- configurationVersion: plugin.configurationVersion,
985
- description: plugin.description,
986
- author: plugin.author,
987
- homepage: plugin.homepage,
988
- help: plugin.help,
989
- changelog: plugin.changelog,
990
- funding: plugin.funding,
991
- latestVersion: plugin.latestVersion,
992
- devVersion: plugin.devVersion,
993
- locked: plugin.locked,
994
- error: plugin.error,
995
- enabled: plugin.enabled,
996
- loaded: plugin.loaded,
997
- started: plugin.started,
998
- configured: plugin.configured,
999
- local: plugin.local,
1000
- restartRequired: plugin.restartRequired,
1001
- registeredDevices: plugin.registeredDevices,
1002
- configJson: plugin.configJson,
1003
- schemaJson: plugin.schemaJson,
1004
- hasWhiteList: plugin.configJson?.whiteList !== undefined,
1005
- hasBlackList: plugin.configJson?.blackList !== undefined,
1006
- frontendPath: plugin.frontendPath,
1007
- matter: plugin.serverNode ? getServerNodeData(plugin.serverNode) : undefined,
1008
- });
1009
- }
1010
- return plugins;
1011
- }
1012
935
  getApiDevices(pluginName, extended = false) {
1013
936
  if (this.matterbridge.hasCleanupStarted)
1014
937
  return [];
@@ -1448,16 +1371,17 @@ export class Frontend extends EventEmitter {
1448
1371
  }
1449
1372
  else if (data.method === '/api/settings') {
1450
1373
  const start = performance.now();
1451
- const settings = this.getApiSettings();
1374
+ const settings = (await this.server.fetch({ type: 'matterbridge_apisettings', src: this.server.name, dst: 'matterbridge', params: {} }, this.serverFetchTimeout)).result.data;
1452
1375
  if (this.diagnostic)
1453
- writeDiagnostic(`Frontend:${data.sender}`, `getApiSettings() took ${(performance.now() - start).toFixed(2)} ms`);
1376
+ writeDiagnostic(`Frontend:${data.sender}`, `/api/settings took ${(performance.now() - start).toFixed(2)} ms`);
1454
1377
  sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true, response: settings });
1455
1378
  }
1456
1379
  else if (data.method === '/api/plugins') {
1457
1380
  const start = performance.now();
1458
- const plugins = this.getApiPlugins();
1381
+ const plugins = (await this.server.fetch({ type: 'plugins_apipluginarray', src: this.server.name, dst: 'plugins', params: undefined }, this.serverFetchTimeout)).result
1382
+ .plugins;
1459
1383
  if (this.diagnostic)
1460
- writeDiagnostic(`Frontend:${data.sender}`, `getApiPlugins() took ${(performance.now() - start).toFixed(2)} ms`);
1384
+ writeDiagnostic(`Frontend:${data.sender}`, `/api/plugins took ${(performance.now() - start).toFixed(2)} ms`);
1461
1385
  sendResponse({ id: data.id, method: data.method, src: 'Matterbridge', dst: data.src, success: true, response: plugins });
1462
1386
  }
1463
1387
  else if (data.method === '/api/devices') {
@@ -297,9 +297,9 @@ export class Matterbridge extends EventEmitter {
297
297
  matterMdnsInterface: this.mdnsInterface,
298
298
  matterIpv4Address: this.ipv4Address,
299
299
  matterIpv6Address: this.ipv6Address,
300
- matterPort: this.port ?? 5540,
301
- matterDiscriminator: this.discriminator,
302
- matterPasscode: this.passcode,
300
+ matterPort: this.initialPort ?? 5540,
301
+ matterDiscriminator: this.initialDiscriminator,
302
+ matterPasscode: this.initialPasscode,
303
303
  startupAt: this.startupAt,
304
304
  shutdownAt: this.shutdownAt,
305
305
  runningTimes: this.runningTimes,
@@ -397,8 +397,9 @@ export class PluginManager extends EventEmitter {
397
397
  registeredDevices: plugin.registeredDevices,
398
398
  configJson: plugin.configJson,
399
399
  schemaJson: plugin.schemaJson,
400
- hasWhiteList: plugin.hasWhiteList,
401
- hasBlackList: plugin.hasBlackList,
400
+ frontendPath: plugin.frontendPath,
401
+ hasWhiteList: plugin.configJson?.whiteList !== undefined,
402
+ hasBlackList: plugin.configJson?.blackList !== undefined,
402
403
  matter: plugin.serverNode ? getServerNodeData(plugin.serverNode) : undefined,
403
404
  };
404
405
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matterbridge/core",
3
- "version": "3.11.2-dev-20261104-98c7a1f",
3
+ "version": "3.11.2-dev-20261106-e5bb80a",
4
4
  "description": "Matterbridge core library",
5
5
  "author": "https://github.com/Luligu",
6
6
  "homepage": "https://matterbridge.io/",
@@ -136,10 +136,10 @@
136
136
  },
137
137
  "dependencies": {
138
138
  "@matter/main": "0.18.0",
139
- "@matterbridge/dgram": "3.11.2-dev-20261104-98c7a1f",
140
- "@matterbridge/thread": "3.11.2-dev-20261104-98c7a1f",
141
- "@matterbridge/types": "3.11.2-dev-20261104-98c7a1f",
142
- "@matterbridge/utils": "3.11.2-dev-20261104-98c7a1f",
139
+ "@matterbridge/dgram": "3.11.2-dev-20261106-e5bb80a",
140
+ "@matterbridge/thread": "3.11.2-dev-20261106-e5bb80a",
141
+ "@matterbridge/types": "3.11.2-dev-20261106-e5bb80a",
142
+ "@matterbridge/utils": "3.11.2-dev-20261106-e5bb80a",
143
143
  "escape-html": "1.0.3",
144
144
  "express": "5.3.0",
145
145
  "express-rate-limit": "8.7.2",