matterbridge-example-camera 0.0.7-dev-20260723-3d59764 → 0.0.7-dev-20260725-bcbe2ca

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 CHANGED
@@ -32,14 +32,23 @@ If you like this project and find it useful, please consider giving it a star on
32
32
 
33
33
  ### Added
34
34
 
35
+ - [tests]: Add `vitest/webrtc/weriftSession.test.ts` coverage for the audio track injection path in `WeriftWebRtcSession`: an SDP answer without an injectable audio codec when the remote offer only supports PCMU, skipping non-audio transceivers when selecting the preferred audio codec, only adjusting the audio transceiver(s) that actually negotiated the preferred codec, the `MATTERBRIDGE_CAMERA_DISABLE_TEST_AUDIO=1` toggle, a missing ffmpeg dependency on the audio path, and not re-attaching a test-audio track on a subsequent `createAnswer`. `weriftSession.ts` is back to 100% statement/branch/function/line coverage. Also mark the audio generator's spawn-error handler, its catch block, and the unreachable `adjustedTransceivers === 0` branch in `preferAudioCodecOnTransceivers` as `v8 ignore`, mirroring the already-ignored video counterparts for the same reasons (child-process/werift-internals mocking, and a mimeType that's always found on at least one transceiver).
35
36
  - [platform]: Add log of config.
36
37
  - [platform]: Add animation interval in 10 phases.
37
38
  - [doorbell]: Add use of cluster client Chime of Server Doorbell in the animation. It needs the Server Doorbell and Server Chime to be paired and a binding in Matter Server dashboard from Server Doorbell Chime client cluster to Server Chime Chime server cluster: [bindings](screenshots/bindings.png).
38
39
  - [chip-test]: Add full shell script to run the chip tests.
39
40
 
41
+ ### Changed
42
+
43
+ - [package]: Update dependencies and update package.
44
+ - [package]: Bump `werift` to v.0.24.1. This release tightens `setRemoteDescription`/`setLocalDescription` toward W3C `RTCPeerConnection` spec compliance (signaling-state validation, SDP media-section handling), which is stricter than the previous 0.23.0 behavior.
45
+ - [package]: Update agents configs.
46
+
40
47
  ### Fixed
41
48
 
42
49
  - [chime]: Fix behavior when enabled is false. All chip tests pass.
50
+ - [webrtc]: `createAnswer()` no longer calls `ensureTestAudioTrack()` when the remote offer negotiated no injectable audio codec (e.g. PCMU-only). Previously it still ran with an `undefined` codec and silently defaulted to Opus/payload type 111, injecting RTP the peer never negotiated.
51
+ - [tests]: Fix `vitest/behaviors/webRtcTransportProviderServer.test.ts` session reuse that broke under werift 0.24.1's stricter signaling-state validation: `provideOffer`/`provideAnswer` on an "existing session" test now use dedicated sessions instead of layering a media-less fake re-offer/answer onto the same real, already-negotiated session 1, which used to silently work only because of werift 0.23.0's laxer validation.
43
52
 
44
53
  <a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="120"></a>
45
54
 
@@ -48,8 +57,12 @@ If you like this project and find it useful, please consider giving it a star on
48
57
  ### Added
49
58
 
50
59
  - [floodlight camera]: Add the Floodlight Camera device type. It is a composed device: the root endpoint carries Basic Information and, unless disabled, Power Source; the mandatory Camera child endpoint and the mandatory On/Off Light child endpoint required by Matter specs 1.6.0 chapter 16.2 are both created automatically by the constructor, the Camera child with the same CameraAvStreamManagement/WebRtcTransportProvider wiring as the standalone `Camera` device; `addLight()` adds further On/Off Light child endpoints beyond the mandatory one.
51
- - [platform]: Register a Floodlight Camera example device in `onStart`, and verify it's registered in `onConfigure`.
52
- - [tests]: Add `vitest/devices/floodlightCamera.test.ts` covering default options, custom `lightOptions`, camera identify, power source variants, additional tagged lights, and custom stream usages; extend `vitest/module.test.ts` with the Floodlight Camera "device not registered" `onConfigure` error path.
60
+ - [intercom]: Add the Intercom device type with the Camera AV Stream Management (Audio and Speaker features, for genuine two-way audio), WebRtcTransportProvider, and WebRtcTransportRequestor server clusters, plus the WebRtcTransportProvider, WebRtcTransportRequestor, and Chime client clusters, Identify, and Power Source support.
61
+ - [clients]: Add `addWebRtcTransportProviderClient` helper to `src/behaviors/clients.ts`, shared by `Intercom`, mirroring `addWebRtcTransportRequestorClient`.
62
+ - [behaviors]: Add `src/behaviors/webRtcTransportRequestorServer.ts` with `createDefaultWebRtcTransportRequestorClusterServer`, using matter.js's default `WebRtcTransportRequestorServer` implementation directly.
63
+ - [tests]: Add `vitest/devices/floodlightCamera.test.ts` covering default options, custom `lightOptions`, camera identify, power source variants, additional tagged lights, and custom stream usages; add `vitest/devices/intercom.test.ts`; extend `vitest/module.test.ts` with the Floodlight Camera "device not registered" `onConfigure` error path; extend `vitest/behaviors/clients.test.ts` to cover `addWebRtcTransportProviderClient`.
64
+ - [platform]: Register a Floodlight Camera and two Intercom example devices, `Intercom 1` (bridged) and `Intercom 2` (`mode: 'server'`, its own Matter node, alongside the existing `Server Chime`/`Server Doorbell`), in `onStart`, and verify Intercom 1 is registered in `onConfigure`. Intercom 1 and Intercom 2 can be bound to each other to test two-way calling (see the new README pairing section).
65
+ - [docs]: Document how to pair two Intercom devices for two-way calling (Binding and ACL requirements, with chip-tool examples) in the README.
53
66
 
54
67
  ### Changed
55
68
 
package/README.md CHANGED
@@ -36,6 +36,10 @@ Thanks to [Ludovic BOUÉ](https://github.com/lboue) for his contributions to thi
36
36
  - `src/devices/` contains all single class device types (it will be moved directly in matterbridge core package).
37
37
  - `src/behaviors/` contains all required behaviors (it will be moved directly in matterbridge core package).
38
38
 
39
+ ## TODO
40
+
41
+ - Track matter.js PR #4128 (https://github.com/matter-js/matter.js/pull/4128) and, once merged and released in the consumed `@matter/*` version, remove the temporary ImageControl workaround used by Audio Doorbell and Intercom for CameraAvStreamManagement choice conformance.
42
+
39
43
  ## Supported device types
40
44
 
41
45
  ### Chime
@@ -113,6 +117,54 @@ Features:
113
117
  - Configurable Power Source cluster type on the root endpoint: Rechargeable, Replaceable, Battery, Wired, or None to omit the Power Source cluster entirely.
114
118
  - The Camera child endpoint's Identify and CameraAvStreamManagement configuration can be customized via the `cameraOptions` constructor option, using the same fields and defaults as the standalone Camera device. The mandatory light's name, tagList, and initial state can be customized via the `lightOptions` constructor option.
115
119
 
120
+ ### Intercom
121
+
122
+ Features:
123
+
124
+ - Exposes the Camera AV Stream Management cluster with the Audio and Speaker features (the Video and Snapshot features are not present, per the Matter specification for this device type; see Camera for a device implementing those). The Speaker feature is what makes an Intercom genuinely two-way: unlike Audio Doorbell, it can both capture and play back audio. Configurable speaker capabilities (codec, sample rates, channels) and two-way talk support (NotSupported, HalfDuplex, FullDuplex; default FullDuplex).
125
+ - Unlike Camera and Audio Doorbell, an Intercom both hosts and invokes WebRtcTransportProvider and WebRtcTransportRequestor: it exposes both cluster servers, and registers both as client clusters via `addWebRtcTransportProviderClient`/`addWebRtcTransportRequestorClient`, so it can both receive and solicit WebRTC offers to/from a peer intercom.
126
+ - Adds the optional Chime client cluster automatically via `addChimeClient`, so a bound Chime device can be triggered.
127
+ - Optional Identify cluster support, with configurable identify time and type. Set to Identify.IdentifyType.None to omit the cluster entirely.
128
+ - Configurable Power Source cluster type: Rechargeable, Replaceable, Battery, Wired, or None to omit the Power Source cluster entirely.
129
+ - Deviation from the Matter specification: the CameraAvStreamManagement ImageControl feature is also enabled, even though the specification only allows it when Video or Snapshot is present, to work around the same matter.js bug described above for Audio Doorbell.
130
+
131
+ #### Pairing two Intercoms for two-way calling
132
+
133
+ `src/module.ts` registers exactly this pair for testing: `Intercom 1` (bridged, under the Matterbridge aggregator) and `Intercom 2` (`mode: 'server'`, its own Matter node) — commission both and follow the steps below to bind them together.
134
+
135
+ `Intercom 2` has to be `mode: 'server'` rather than a second bridged endpoint: peer resolution (see below) identifies the caller from the `peerNodeId`/`fabricIndex` of the command's CASE session, and a CASE session only exists between two distinct node identities on the fabric. Two bridged endpoints share the bridge's single node identity, so there is no CASE session, Binding, or ACL between them to test — invoking one from the other would just be a local, in-process behavior call. `mode: 'server'` is what gives an endpoint its own independent Matter node, which is what a real second, physical Intercom would be.
136
+
137
+ Unlike a Doorbell/Chime pair, where only the Doorbell invokes commands on the Chime, an Intercom both hosts (server) and invokes (client) WebRtcTransportProvider and WebRtcTransportRequestor (see `#resolvePeerRequestorEndpoint` in `src/behaviors/webRtcTransportProviderServer.ts`). Once a peer invokes SolicitOffer/ProvideOffer on an Intercom's WebRtcTransportProvider, that Intercom resolves the caller's WebRtcTransportRequestor endpoint directly from the invoking peer's node id/fabric index carried by the command's CASE session — not via the Binding cluster — so the Offer/Answer "return leg" needs no binding of its own. Only the initiating invoke needs one.
138
+
139
+ So, to let either Intercom 1 or Intercom 2 start a call, on the fabric they share (commission both onto the same controller/ecosystem first, e.g. via chip-tool, Apple Home, or Google Home):
140
+
141
+ 1. **Binding on 1 → 2**, so Intercom 1 knows where to send SolicitOffer/ProvideOffer. Binding on 2 → 1 is the mirror, for the other direction:
142
+
143
+ ```bash
144
+ chip-tool binding write binding '[{"fabricIndex": 1, "node": <NODE_ID_2>, "endpoint": <ENDPOINT_2>, "cluster": 1363}]' <NODE_ID_1> <ENDPOINT_1>
145
+ chip-tool binding write binding '[{"fabricIndex": 1, "node": <NODE_ID_1>, "endpoint": <ENDPOINT_1>, "cluster": 1363}]' <NODE_ID_2> <ENDPOINT_2>
146
+ ```
147
+
148
+ `1363` (`0x553`) is the WebRtcTransportProvider cluster id; `<ENDPOINT_1>`/`<ENDPOINT_2>` are each Intercom's endpoint number (find them from the commissioning output or the Matterbridge frontend).
149
+
150
+ 2. **ACL on 2 granting 1**, and **ACL on 1 granting 2**, Operate access to both WebRtcTransportProvider (`1363`) and WebRtcTransportRequestor (`1364`, `0x554`) — Intercom 1 needs it on 2 for the initiating invoke, and Intercom 2 needs it on 1 for the return invoke, regardless of who starts the call:
151
+
152
+ ```bash
153
+ chip-tool accesscontrol write acl '[
154
+ {"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [<ADMIN_NODE_ID>], "targets": null},
155
+ {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": [<NODE_ID_1>], "targets": [{"cluster": 1363, "endpoint": null, "deviceType": null}, {"cluster": 1364, "endpoint": null, "deviceType": null}]}
156
+ ]' <NODE_ID_2> 0
157
+
158
+ chip-tool accesscontrol write acl '[
159
+ {"fabricIndex": 1, "privilege": 5, "authMode": 2, "subjects": [<ADMIN_NODE_ID>], "targets": null},
160
+ {"fabricIndex": 1, "privilege": 3, "authMode": 2, "subjects": [<NODE_ID_2>], "targets": [{"cluster": 1363, "endpoint": null, "deviceType": null}, {"cluster": 1364, "endpoint": null, "deviceType": null}]}
161
+ ]' <NODE_ID_1> 0
162
+ ```
163
+
164
+ The ACL attribute is a full replace, not a merge: keep the existing Administer entry for `<ADMIN_NODE_ID>` (your controller/commissioner) in the list, or you lock yourself out of that node.
165
+
166
+ With both directions in place, either Intercom can call the other; a call initiated the other way only needs its own binding/ACL pair, already covered above since both were set up symmetrically.
167
+
116
168
  ## WebRTC test video injection
117
169
 
118
170
  `WeriftWebRtcSession` (see `src/webrtc/weriftSession.ts`) wraps a real werift `RTCPeerConnection` for each WebRtcTransportProvider session (see `MatterbridgeWebRtcTransportProviderServer` in `src/behaviors/webRtcTransportProviderServer.ts`), so the session's SDP offer/answer and ICE candidates are handled by a real WebRTC peer connection instead of being just recorded. It can also inject a real ffmpeg-generated video track into the negotiated connection, so the end-to-end media path can be validated without a real camera capture pipeline.
@@ -235,29 +287,40 @@ WebRTC media tracks transport encoded H.264 or Opus frames in RTP packets; they
235
287
 
236
288
  ## Chip tests
237
289
 
238
- ### Create and run the container (Linux, macOS, and Windows)
290
+ ### Create the container (Linux, macOS, and Windows)
239
291
 
240
- Run the `luligu/matterbridge:chip-test` docker image, add the plugin, restart and open a shell in the container:
292
+ Run the `luligu/matterbridge:chip-test` docker image:
241
293
 
242
294
  - frontend on port 8585
243
295
  - plugin mapped to .
244
296
  - container test logs directory mapped on ./temp directory
245
297
 
246
298
  ```shell
247
- docker rm matterbridge-chip-test-hub -f && docker pull luligu/matterbridge:chip-test && docker run -dit --network matterbridge --restart always --stop-timeout 60 --name matterbridge-chip-test-hub -p 8585:8283 -v "$(pwd)/temp:/tmp/matter_testing/logs" -v "$(pwd):/root/Matterbridge/matterbridge-example-camera" luligu/matterbridge:chip-test
248
- docker exec -it matterbridge-chip-test-hub matterbridge --add matterbridge-example-camera
249
- docker restart matterbridge-chip-test-hub
250
- docker exec -it matterbridge-chip-test-hub bash
299
+ docker rm plugin-chip-test -f && docker pull luligu/matterbridge:chip-test && docker run -dit --network matterbridge --restart always --stop-timeout 60 --name plugin-chip-test -p 8585:8283 -v "$(pwd)/temp:/tmp/matter_testing/logs" -v "$(pwd):/root/Matterbridge/matterbridge-example-camera" luligu/matterbridge:chip-test
251
300
  ```
252
301
 
253
- Stop the container and softRest (needed if running on macOS or Windows)
302
+ ### Add the plugin
303
+
304
+ Add the plugin and restart the container
254
305
 
255
306
  ```shell
256
- docker stop matterbridge-chip-test-hub
257
- npm run softReset
307
+ npm install --no-fund --no-audit --verbose
308
+ npm link matterbridge --no-fund --no-audit --verbose
309
+ npm run build
310
+ npm prune --omit=dev --no-fund --no-audit --verbose
311
+ docker exec -it plugin-chip-test matterbridge --add matterbridge-example-camera
312
+ docker restart plugin-chip-test
258
313
  ```
259
314
 
260
- ### Inside the container
315
+ ### Run the tests inside the container
316
+
317
+ Open a shell in the container
318
+
319
+ ```shell
320
+ docker exec -it plugin-chip-test bash
321
+ ```
322
+
323
+ In the shell:
261
324
 
262
325
  ```bash
263
326
  # Generic device composition and conformance ✅ (one test fails for a known matter.js bug)
@@ -364,3 +427,10 @@ python3 src/python_testing/TC_WEBRTCP_2_32.py
364
427
  # Zone Management
365
428
  python3 src/python_testing/TC_ZONEMGMT_2_4.py
366
429
  ```
430
+
431
+ ### Stop the container and link the local matterbridge instance
432
+
433
+ ```shell
434
+ docker stop plugin-chip-test
435
+ npm run link
436
+ ```
Binary file
@@ -1,6 +1,6 @@
1
1
  import { MatterbridgeBindingServer } from 'matterbridge/behaviors';
2
- import { ChimeClient, WebRtcTransportRequestorClient } from 'matterbridge/matter/behaviors';
3
- import { Chime, WebRtcTransportRequestor } from 'matterbridge/matter/clusters';
2
+ import { ChimeClient, WebRtcTransportProviderClient, WebRtcTransportRequestorClient } from 'matterbridge/matter/behaviors';
3
+ import { Chime, WebRtcTransportProvider, WebRtcTransportRequestor } from 'matterbridge/matter/clusters';
4
4
  function addBindingClientListEntry(endpoint, clusterId) {
5
5
  if (endpoint.behaviors.has(MatterbridgeBindingServer)) {
6
6
  const existing = endpoint.behaviors.optionsFor(MatterbridgeBindingServer)?.clientList ?? [];
@@ -22,3 +22,8 @@ export function addWebRtcTransportRequestorClient(endpoint) {
22
22
  endpoint.type.clientClusters.webRtcTransportRequestor ??= WebRtcTransportRequestorClient;
23
23
  return endpoint;
24
24
  }
25
+ export function addWebRtcTransportProviderClient(endpoint) {
26
+ addBindingClientListEntry(endpoint, WebRtcTransportProvider.id);
27
+ endpoint.type.clientClusters.webRtcTransportProvider ??= WebRtcTransportProviderClient;
28
+ return endpoint;
29
+ }
@@ -0,0 +1,5 @@
1
+ import { WebRtcTransportRequestorServer } from 'matterbridge/matter/behaviors';
2
+ export function createDefaultWebRtcTransportRequestorClusterServer(endpoint) {
3
+ endpoint.behaviors.require(WebRtcTransportRequestorServer, { currentSessions: [] });
4
+ return endpoint;
5
+ }
@@ -0,0 +1,74 @@
1
+ import { intercom, MatterbridgeEndpoint, powerSource } from 'matterbridge';
2
+ import { CameraAvStreamManagement, Identify } from 'matterbridge/matter/clusters';
3
+ import { StreamUsage } from 'matterbridge/matter/types';
4
+ import { MatterbridgeCameraAvStreamManagementServer } from '../behaviors/cameraAvStreamManagementServer.js';
5
+ import { addChimeClient, addWebRtcTransportProviderClient, addWebRtcTransportRequestorClient } from '../behaviors/clients.js';
6
+ import { createDefaultWebRtcTransportProviderClusterServer } from '../behaviors/webRtcTransportProviderServer.js';
7
+ import { createDefaultWebRtcTransportRequestorClusterServer } from '../behaviors/webRtcTransportRequestorServer.js';
8
+ export class Intercom extends MatterbridgeEndpoint {
9
+ constructor(name, serial, options = {}) {
10
+ const { identifyTime = 0, identifyType = Identify.IdentifyType.None, powerSourceType = 'Wired', maxContentBufferSize = 65_536, maxNetworkBandwidth = 128_000, supportedStreamUsages = [StreamUsage.LiveView], streamUsagePriorities = supportedStreamUsages, microphoneCapabilities = { maxNumberOfChannels: 1, supportedCodecs: [CameraAvStreamManagement.AudioCodec.Opus], supportedSampleRates: [48000], supportedBitDepths: [16] }, speakerCapabilities = { maxNumberOfChannels: 1, supportedCodecs: [CameraAvStreamManagement.AudioCodec.Opus], supportedSampleRates: [48000], supportedBitDepths: [16] }, twoWayTalkSupport = CameraAvStreamManagement.TwoWayTalkSupportType.FullDuplex, id, number, tagList, mode, } = options;
11
+ super(powerSourceType === 'None' ? [intercom] : [intercom, powerSource], {
12
+ id: id ?? `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}`,
13
+ number,
14
+ tagList,
15
+ mode,
16
+ });
17
+ if (identifyType !== Identify.IdentifyType.None) {
18
+ this.createDefaultIdentifyClusterServer(identifyTime, identifyType);
19
+ }
20
+ this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Matterbridge Intercom');
21
+ switch (powerSourceType) {
22
+ case 'Rechargeable':
23
+ this.createDefaultPowerSourceRechargeableBatteryClusterServer();
24
+ break;
25
+ case 'Replaceable':
26
+ this.createDefaultPowerSourceReplaceableBatteryClusterServer();
27
+ break;
28
+ case 'Battery':
29
+ this.createDefaultPowerSourceBatteryClusterServer();
30
+ break;
31
+ case 'Wired':
32
+ this.createDefaultPowerSourceWiredClusterServer();
33
+ break;
34
+ case 'None':
35
+ break;
36
+ }
37
+ createDefaultIntercomCameraAvStreamManagementClusterServer(this, {
38
+ maxContentBufferSize,
39
+ maxNetworkBandwidth,
40
+ supportedStreamUsages,
41
+ streamUsagePriorities,
42
+ microphoneCapabilities,
43
+ speakerCapabilities,
44
+ twoWayTalkSupport,
45
+ });
46
+ createDefaultWebRtcTransportProviderClusterServer(this);
47
+ createDefaultWebRtcTransportRequestorClusterServer(this);
48
+ addWebRtcTransportProviderClient(this);
49
+ addWebRtcTransportRequestorClient(this);
50
+ addChimeClient(this);
51
+ this.addRequiredClusters();
52
+ }
53
+ }
54
+ export function createDefaultIntercomCameraAvStreamManagementClusterServer(endpoint, options) {
55
+ endpoint.behaviors.require(MatterbridgeCameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Audio, CameraAvStreamManagement.Feature.Speaker, CameraAvStreamManagement.Feature.ImageControl), {
56
+ ...options,
57
+ hardPrivacyModeOn: false,
58
+ statusLightEnabled: false,
59
+ allocatedAudioStreams: [],
60
+ microphoneMuted: false,
61
+ microphoneVolumeLevel: 128,
62
+ microphoneMaxLevel: 254,
63
+ microphoneMinLevel: 0,
64
+ microphoneAgcEnabled: false,
65
+ speakerMuted: false,
66
+ speakerVolumeLevel: 128,
67
+ speakerMaxLevel: 254,
68
+ speakerMinLevel: 0,
69
+ imageRotation: 0,
70
+ imageFlipVertical: false,
71
+ imageFlipHorizontal: false,
72
+ });
73
+ return endpoint;
74
+ }
package/dist/module.js CHANGED
@@ -10,6 +10,7 @@ import { Camera } from './devices/camera.js';
10
10
  import { Chime } from './devices/chime.js';
11
11
  import { Doorbell } from './devices/doorbell.js';
12
12
  import { FloodlightCamera } from './devices/floodlightCamera.js';
13
+ import { Intercom } from './devices/intercom.js';
13
14
  import { SnapshotCamera } from './devices/snapshotCamera.js';
14
15
  export default function initializePlugin(matterbridge, log, config) {
15
16
  return new ExampleMatterbridgeCameraPlatform(matterbridge, log, config);
@@ -92,6 +93,12 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
92
93
  lightOptions: { name: 'Floodlight' },
93
94
  });
94
95
  await this.addDevice(exampleFloodlightCamera);
96
+ const exampleIntercom1 = new Intercom('Intercom 1', 'INTERCOM1-001', {
97
+ identifyTime: 5,
98
+ identifyType: Identify.IdentifyType.VisibleIndicator,
99
+ powerSourceType: 'Replaceable',
100
+ });
101
+ await this.addDevice(exampleIntercom1);
95
102
  const serverChime = new Chime('Server Chime', 'SERVER-CHIME-001', {
96
103
  identifyTime: 5,
97
104
  identifyType: Identify.IdentifyType.AudibleBeep,
@@ -111,6 +118,8 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
111
118
  });
112
119
  const serverDoorbell = new Doorbell('Server Doorbell', 'SERVER-DOORBELL-001', { mode: 'server' });
113
120
  await this.addDevice(serverDoorbell);
121
+ const exampleIntercom2 = new Intercom('Intercom 2', 'INTERCOM2-001', { mode: 'server' });
122
+ await this.addDevice(exampleIntercom2);
114
123
  this.log.info(`Platform ${this.config.name} started successfully`);
115
124
  }
116
125
  async onConfigure() {
@@ -119,6 +128,9 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
119
128
  const exampleChime = this.getDeviceById('Chime-CHIME-001');
120
129
  await exampleChime?.setCluster(PowerSource, { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 150, batQuantity: 2, batReplacementDescription: 'AA' }, exampleChime.log);
121
130
  await exampleChime?.setCluster(ChimeCluster, { enabled: true, selectedChime: 0 }, exampleChime.log);
131
+ const exampleIntercom1 = this.getDeviceById('Intercom1-INTERCOM1-001');
132
+ if (!exampleIntercom1)
133
+ throw new Error(`Intercom device not found. Please ensure the device is registered before configuration.`);
122
134
  const serverChime = this.getDeviceById('ServerChime-SERVER-CHIME-001');
123
135
  await serverChime?.setCluster(PowerSource, { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 150, batVoltage: 2900, batReplacementNeeded: false }, serverChime.log);
124
136
  await serverChime?.setCluster(ChimeCluster, { enabled: true, selectedChime: 0 }, serverChime.log);
@@ -3,6 +3,7 @@ import { createSocket } from 'node:dgram';
3
3
  import { constants } from 'node:fs';
4
4
  import { access, readdir } from 'node:fs/promises';
5
5
  import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
6
7
  import { AnsiLogger, MAGENTA } from 'matterbridge/logger';
7
8
  import { RTCPeerConnection, RTCRtpCodecParameters, useH264, useOPUS, usePCMU, useVP8 } from 'werift';
8
9
  import { navigator } from 'werift/nonstandard';
@@ -12,6 +13,9 @@ export class WeriftWebRtcSession {
12
13
  testVideoGenerator;
13
14
  testVideoUdpDisposer;
14
15
  testVideoAttached = false;
16
+ testAudioGenerator;
17
+ testAudioUdpDisposer;
18
+ testAudioAttached = false;
15
19
  constructor(webRtcSessionId) {
16
20
  this.peerConnection = new RTCPeerConnection({ codecs: { audio: [useOPUS(), usePCMU()], video: [useH264(), useVP8()] } });
17
21
  this.log = new AnsiLogger({ logName: `WebRTC session ${webRtcSessionId}`, logLevel: "debug", logNameColor: MAGENTA, logTimestampFormat: 4 });
@@ -152,6 +156,19 @@ export class WeriftWebRtcSession {
152
156
  this.log.debug('No preferred injectable video codec (VP8/H264) negotiated on any video transceiver');
153
157
  return undefined;
154
158
  }
159
+ getPreferredInjectableAudioCodec() {
160
+ for (const transceiver of this.peerConnection.getTransceivers()) {
161
+ if (transceiver.kind !== 'audio')
162
+ continue;
163
+ const preferredCodec = transceiver.codecs.find((codec) => codec.mimeType.toLowerCase() === 'audio/opus');
164
+ if (preferredCodec) {
165
+ this.log.debug(`Preferred injectable audio codec: ${preferredCodec.mimeType}`);
166
+ return preferredCodec;
167
+ }
168
+ }
169
+ this.log.debug('No preferred injectable audio codec (Opus) negotiated on any audio transceiver');
170
+ return undefined;
171
+ }
155
172
  static SUPPORTED_WEBCAM_RESOLUTIONS = ['640x480', '1280x720', '1920x1080'];
156
173
  static DEFAULT_BITRATE_KBPS = 1000;
157
174
  getConfiguredWebcamBitrate() {
@@ -299,6 +316,85 @@ export class WeriftWebRtcSession {
299
316
  this.log.debug(`Preferred ${mimeType.toUpperCase()} codecs on ${adjustedTransceivers} video transceiver(s)`);
300
317
  }
301
318
  }
319
+ preferAudioCodecOnTransceivers(mimeType) {
320
+ let adjustedTransceivers = 0;
321
+ for (const transceiver of this.peerConnection.getTransceivers()) {
322
+ if (transceiver.kind !== 'audio')
323
+ continue;
324
+ const preferredCodecs = transceiver.codecs.filter((codec) => codec.mimeType.toLowerCase() === mimeType);
325
+ if (!preferredCodecs.length)
326
+ continue;
327
+ transceiver.codecs = preferredCodecs;
328
+ adjustedTransceivers += 1;
329
+ }
330
+ if (adjustedTransceivers > 0) {
331
+ this.log.debug(`Preferred ${mimeType.toUpperCase()} codecs on ${adjustedTransceivers} audio transceiver(s)`);
332
+ }
333
+ }
334
+ static TEST_VOICE_PATH = fileURLToPath(new URL('../../assets/test-voice.opus', import.meta.url));
335
+ async ensureTestAudioTrack(codec) {
336
+ if (this.testAudioAttached)
337
+ return;
338
+ if (process.env.MATTERBRIDGE_CAMERA_DISABLE_TEST_AUDIO === '1') {
339
+ this.log.debug('Test audio injection disabled by MATTERBRIDGE_CAMERA_DISABLE_TEST_AUDIO=1');
340
+ return;
341
+ }
342
+ const ffmpegCommand = await this.resolveCommand('ffmpeg');
343
+ if (!ffmpegCommand) {
344
+ this.log.warn('Cannot inject audio stream: missing dependency ffmpeg');
345
+ return;
346
+ }
347
+ const selectedMimeType = codec.mimeType.toLowerCase();
348
+ const selectedPayloadType = codec.payloadType;
349
+ const clockRate = codec.clockRate;
350
+ const channels = codec.channels;
351
+ try {
352
+ const udpPort = await this.getFreeUdpPort();
353
+ const { track, disposer } = navigator.mediaDevices.getUdpMedia({
354
+ port: udpPort,
355
+ codec: new RTCRtpCodecParameters({ mimeType: selectedMimeType, clockRate, channels, payloadType: selectedPayloadType }),
356
+ });
357
+ this.peerConnection.addTrack(track);
358
+ const ffmpegArgs = [
359
+ '-hide_banner',
360
+ '-loglevel',
361
+ 'error',
362
+ '-re',
363
+ '-stream_loop',
364
+ '-1',
365
+ '-i',
366
+ WeriftWebRtcSession.TEST_VOICE_PATH,
367
+ '-vn',
368
+ '-af',
369
+ 'volume=6dB',
370
+ '-c:a',
371
+ 'libopus',
372
+ '-b:a',
373
+ '32k',
374
+ '-ac',
375
+ String(channels),
376
+ '-ar',
377
+ String(clockRate),
378
+ '-f',
379
+ 'rtp',
380
+ '-payload_type',
381
+ String(selectedPayloadType),
382
+ `rtp://127.0.0.1:${udpPort}`,
383
+ ];
384
+ this.log.debug(`Spawning ffmpeg: ${ffmpegCommand} ${ffmpegArgs.join(' ')}`);
385
+ const generator = spawn(ffmpegCommand, ffmpegArgs);
386
+ generator.once('error', (error) => {
387
+ this.log.warn(`Audio generator failed: ${error instanceof Error ? error.message : String(error)}`);
388
+ });
389
+ this.testAudioUdpDisposer = disposer;
390
+ this.testAudioGenerator = generator;
391
+ this.testAudioAttached = true;
392
+ this.log.info(`Attached test-voice audio track (ffmpeg=${ffmpegCommand}, codec=${selectedMimeType}, payloadType=${selectedPayloadType}, sourcePort=${udpPort})`);
393
+ }
394
+ catch (error) {
395
+ this.log.warn(`Failed to attach test-voice audio track: ${error instanceof Error ? error.message : String(error)}`);
396
+ }
397
+ }
302
398
  cleanupTestVideoArtifacts() {
303
399
  if (this.testVideoGenerator) {
304
400
  this.testVideoGenerator.kill('SIGTERM');
@@ -308,6 +404,15 @@ export class WeriftWebRtcSession {
308
404
  this.testVideoUdpDisposer = undefined;
309
405
  this.testVideoAttached = false;
310
406
  }
407
+ cleanupTestAudioArtifacts() {
408
+ if (this.testAudioGenerator) {
409
+ this.testAudioGenerator.kill('SIGTERM');
410
+ this.testAudioGenerator = undefined;
411
+ }
412
+ this.testAudioUdpDisposer?.();
413
+ this.testAudioUdpDisposer = undefined;
414
+ this.testAudioAttached = false;
415
+ }
311
416
  async createOffer(options) {
312
417
  this.log.debug(`CreateOffer requested (video=${options.video}, audio=${options.audio}, videoResolution=${options.videoResolution ?? 'undefined'})`);
313
418
  if (options.video) {
@@ -345,6 +450,18 @@ export class WeriftWebRtcSession {
345
450
  }
346
451
  await this.generateVideoTrack(preferredCodec, videoResolution);
347
452
  }
453
+ const hasAudioTransceiver = this.peerConnection.getTransceivers().some((transceiver) => transceiver.kind === 'audio');
454
+ this.log.debug(`Remote offer created audio transceiver: ${hasAudioTransceiver}`);
455
+ if (hasAudioTransceiver) {
456
+ const preferredAudioCodec = this.getPreferredInjectableAudioCodec();
457
+ if (preferredAudioCodec) {
458
+ this.preferAudioCodecOnTransceivers(preferredAudioCodec.mimeType.toLowerCase());
459
+ await this.ensureTestAudioTrack(preferredAudioCodec);
460
+ }
461
+ else {
462
+ this.log.warn('No injectable audio codec available on negotiated transceivers (supported: Opus)');
463
+ }
464
+ }
348
465
  for (const transceiver of this.peerConnection.getTransceivers()) {
349
466
  transceiver.setDirection('sendonly');
350
467
  }
@@ -367,6 +484,7 @@ export class WeriftWebRtcSession {
367
484
  this.log.debug('Closing RTCPeerConnection');
368
485
  await this.peerConnection.close();
369
486
  this.cleanupTestVideoArtifacts();
487
+ this.cleanupTestAudioArtifacts();
370
488
  this.log.info(`RTCPeerConnection closed (connectionState=${this.peerConnection.connectionState})`);
371
489
  }
372
490
  }
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "matterbridge-example-camera",
3
- "version": "0.0.7-dev-20260723-3d59764",
3
+ "version": "0.0.7-dev-20260725-bcbe2ca",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "matterbridge-example-camera",
9
- "version": "0.0.7-dev-20260723-3d59764",
9
+ "version": "0.0.7-dev-20260725-bcbe2ca",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "node-ansi-logger": "3.3.0",
13
13
  "node-persist-manager": "2.1.0",
14
- "werift": "0.23.0"
14
+ "werift": "0.24.1"
15
15
  },
16
16
  "engines": {
17
17
  "node": ">=20.19.0 <21.0.0 || >=22.13.0 <23.0.0 || >=24.0.0 <25.0.0 || >=26.0.0 <27.0.0"
@@ -266,6 +266,21 @@
266
266
  "resolved": "https://registry.npmjs.org/@shinyoshiaki/jspack/-/jspack-0.0.6.tgz",
267
267
  "integrity": "sha512-SdsNhLjQh4onBlyPrn4ia1Pdx5bXT88G/LIEpOYAjx2u4xeY/m/HB5yHqlkJB1uQR3Zw4R3hBWLj46STRAN0rg=="
268
268
  },
269
+ "node_modules/@types/dom-mediacapture-transform": {
270
+ "version": "0.1.12",
271
+ "resolved": "https://registry.npmjs.org/@types/dom-mediacapture-transform/-/dom-mediacapture-transform-0.1.12.tgz",
272
+ "integrity": "sha512-d7/QsLRwF864A5mgIM/YrfiglHoYn7zgCcAoJgW404r+2DwnNr7EBbLnCWpmOMgH8y0te73L1AV6H1bmauaWFw==",
273
+ "license": "MIT",
274
+ "dependencies": {
275
+ "@types/dom-webcodecs": "*"
276
+ }
277
+ },
278
+ "node_modules/@types/dom-webcodecs": {
279
+ "version": "0.1.13",
280
+ "resolved": "https://registry.npmjs.org/@types/dom-webcodecs/-/dom-webcodecs-0.1.13.tgz",
281
+ "integrity": "sha512-O5hkiFIcjjszPIYyUSyvScyvrBoV3NOEEZx/pMlsu44TKzWNkLVBBxnxJz42in5n3QIolYOcBYFCPZZ0h8SkwQ==",
282
+ "license": "MIT"
283
+ },
269
284
  "node_modules/aes-js": {
270
285
  "version": "3.1.2",
271
286
  "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz",
@@ -384,12 +399,6 @@
384
399
  "node": ">=6"
385
400
  }
386
401
  },
387
- "node_modules/fast-deep-equal": {
388
- "version": "3.1.3",
389
- "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
390
- "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
391
- "license": "MIT"
392
- },
393
402
  "node_modules/generate-function": {
394
403
  "version": "2.3.1",
395
404
  "resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.3.1.tgz",
@@ -420,9 +429,9 @@
420
429
  "license": "BSD-3-Clause"
421
430
  },
422
431
  "node_modules/int64-buffer": {
423
- "version": "1.1.0",
424
- "resolved": "https://registry.npmjs.org/int64-buffer/-/int64-buffer-1.1.0.tgz",
425
- "integrity": "sha512-94smTCQOvigN4d/2R/YDjz8YVG0Sufvv2aAh8P5m42gwhCsDAJqnbNOrxJsrADuAFAA69Q/ptGzxvNcNuIJcvw==",
432
+ "version": "1.1.1",
433
+ "resolved": "https://registry.npmjs.org/int64-buffer/-/int64-buffer-1.1.1.tgz",
434
+ "integrity": "sha512-xp/v0/im2q7n7ISFJXcYsr/aVsUdZKPUZS1uYtoM9I9Cfmm5YuAi7SQts2TrEXwAKIE0wyn3KxJbo35goJgvwQ==",
426
435
  "license": "MIT"
427
436
  },
428
437
  "node_modules/ip": {
@@ -464,6 +473,24 @@
464
473
  "integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==",
465
474
  "license": "MIT"
466
475
  },
476
+ "node_modules/mediabunny": {
477
+ "version": "1.51.0",
478
+ "resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.51.0.tgz",
479
+ "integrity": "sha512-u327374xU8Ho0gCaMII7fUK8t0PnqkabCox1k8uUwvgvGb9o6YQGZEG2Qr4DTe7nTMpzfL7ukgnHDvDROySZ+Q==",
480
+ "license": "MPL-2.0",
481
+ "workspaces": [
482
+ ".",
483
+ "packages/*"
484
+ ],
485
+ "dependencies": {
486
+ "@types/dom-mediacapture-transform": "^0.1.11",
487
+ "@types/dom-webcodecs": "0.1.13"
488
+ },
489
+ "funding": {
490
+ "type": "individual",
491
+ "url": "https://github.com/sponsors/Vanilagy"
492
+ }
493
+ },
467
494
  "node_modules/mp4box": {
468
495
  "version": "0.5.4",
469
496
  "resolved": "https://registry.npmjs.org/mp4box/-/mp4box-0.5.4.tgz",
@@ -634,24 +661,18 @@
634
661
  "license": "Unlicense"
635
662
  },
636
663
  "node_modules/werift": {
637
- "version": "0.23.0",
638
- "resolved": "https://registry.npmjs.org/werift/-/werift-0.23.0.tgz",
639
- "integrity": "sha512-/WcIN5DHFG9Ri4anGOmIkp8gxBGFMWSIB/m4sfZ5CWlLfD3iMhiaAUuTBuc+KV3SY9NDmvmLtiN2uaM7k3lVzw==",
664
+ "version": "0.24.1",
665
+ "resolved": "https://registry.npmjs.org/werift/-/werift-0.24.1.tgz",
666
+ "integrity": "sha512-8Mpf0FWO2pkd9UQyZ0Hb1CcimydlNh8KCvZGD2X/D0ucVY6ubJxX91cndOpTOnPA7wleopop044VSNZeCEwgeA==",
640
667
  "license": "MIT",
641
668
  "dependencies": {
642
669
  "@fidm/x509": "^1.2.1",
643
- "@minhducsun2002/leb128": "^1.0.0",
644
670
  "@noble/curves": "^1.8.1",
645
671
  "@peculiar/x509": "^1.12.3",
646
672
  "@shinyoshiaki/binary-data": "^0.6.1",
647
- "@shinyoshiaki/jspack": "^0.0.6",
648
- "aes-js": "^3.1.2",
649
673
  "buffer": "^6.0.3",
650
674
  "debug": "4.4.0",
651
- "fast-deep-equal": "^3.1.3",
652
- "int64-buffer": "1.1.0",
653
- "ip": "^2.0.1",
654
- "mp4box": "^0.5.3",
675
+ "mediabunny": "^1.45.2",
655
676
  "multicast-dns": "^7.2.5",
656
677
  "tweetnacl": "^1.0.3",
657
678
  "werift-common": "*",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matterbridge-example-camera",
3
- "version": "0.0.7-dev-20260723-3d59764",
3
+ "version": "0.0.7-dev-20260725-bcbe2ca",
4
4
  "description": "Matterbridge camera example plugin",
5
5
  "author": "https://github.com/Luligu",
6
6
  "license": "Apache-2.0",
@@ -69,6 +69,6 @@
69
69
  "dependencies": {
70
70
  "node-ansi-logger": "3.3.0",
71
71
  "node-persist-manager": "2.1.0",
72
- "werift": "0.23.0"
72
+ "werift": "0.24.1"
73
73
  }
74
74
  }