matterbridge-example-camera 0.0.9-dev-20260727-f34a88a → 0.1.0

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
@@ -28,16 +28,44 @@ If you like this project and find it useful, please consider giving it a star on
28
28
 
29
29
  <a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="120"></a>
30
30
 
31
- ## [0.0.9] - Deb branch
31
+ ## [0.1.0] - Dev branch
32
+
33
+ ### Added
34
+
35
+ - [camera]: Bump MatterbridgeWebRtcTransportProviderServer v.2.0.0.
36
+ - [camera]: Bump MatterbridgeCameraAvStreamManagementServer v.2.0.0.
37
+ - [chip]: Add chip test toolchain.
38
+
39
+ <a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="120"></a>
40
+
41
+ ## [0.0.9] - Not published
32
42
 
33
43
  ### Added
34
44
 
35
45
  - [Dev Container]: Update Dev Container v.1.2.0.
46
+ - [scripts]: Add `scripts/run-chip-tests.mjs` to manage the `luligu/matterbridge:chip-test` docker container and run the CHIP python test suite defined in `chipTests.json`. `--start` builds and adds the plugin to a fresh container, `--stop` stops it and restores the local dev environment (reinstall, relink, rebuild), `--test NAME` filters to matching tests, and results are logged to `chipTests.log`.
47
+ - [scripts]: `run-chip-tests.mjs` now supports a per-test `"reset": true` field in `chipTests.json` that clears persisted stateful cluster storage and restarts the plugin (without recreating the container) before a test that needs a clean device state, and a per-test `"comment"` field that documents a known/expected failure, printed under its ❌ line in the run summary. The run summary is also written to `chipTestsSummary.log`, separate from the full `chipTests.log`.
48
+ - [tests]: Add `TC_AVSUM_2_1`, `TC_AVSUM_2_2`, `TC_AVSUM_2_3` and `TC_AVSUM_2_9` (Camera AV Settings User Level Management / Mechanical PTZ) to `chipTests.json` and the README, running against the `PTZCamera` example device (endpoint 7).
49
+ - [camera]: Add a `MATTERBRIDGE_STRICT_WEBRTCTRANSPORT` environment variable for `MatterbridgeWebRtcTransportProviderServer.solicitOffer`/`provideOffer`. When set to `1`: (1) a request with none of `videoStreams`, `audioStreams`, `videoStreamId` or `audioStreamId` present is rejected with `INVALID_COMMAND`, matching the Matter specification's choice conformance for these commands; (2) `videoStreams`/`audioStreams` are resolved and validated against `AllocatedVideoStreams`/`AllocatedAudioStreams` per Matter 1.6/1.5.1 §11.5.6.1.10/§11.5.6.3.5 — `INVALID_IN_STATE` when nothing is allocated, `ALREADY_EXISTS` on duplicate ids, `DYNAMIC_CONSTRAINT_ERROR` when an id isn't allocated — instead of the default lenient auto-allocate-on-demand behavior. Fixes the CHIP WebRTC Transport Provider conformance test suite's expectations (`TC_WEBRTCP_2_2`, `2_3`, `2_5`, `2_27`, `2_28`, `2_29`, `2_31`; `2_3`/`2_29` now fully pass, `2_5`/`2_31` progress past this scenario into an unrelated, still-open `StreamUsage` validation gap). Left unset (the default), behavior is completely unchanged: a completely empty request triggers automatic stream selection, and a present stream id/list is used without validating it against `Allocated*Streams` at all — required for compatibility with real clients observed in production that never call `VideoStreamAllocate`/`AudioStreamAllocate` (e.g. SmartThings, and Home Assistant's Matter camera integration).
50
+ - [tests]: Add coverage for `MATTERBRIDGE_STRICT_WEBRTCTRANSPORT`'s `Allocated*Streams` validation in `vitest/behaviors/webRtcTransportProviderServer.test.ts` (up to 53 tests, 100% statements/branches/functions/lines maintained project-wide).
51
+ - [camera]: `MatterbridgeCameraAvStreamManagementServer` now self-allocates a default video/audio/snapshot stream on construction for any feature the endpoint supports that has none allocated yet (`Camera`, `SnapshotCamera`, `AudioDoorbell`, `Intercom`, and the composite `FloodlightCamera`/`VideoDoorbell`), so `AllocatedVideoStreams`/`AllocatedAudioStreams`/`AllocatedSnapshotStreams` are never unexpectedly empty for a client that never calls `VideoStreamAllocate`/`AudioStreamAllocate`/`SnapshotStreamAllocate` itself (e.g. SmartThings in production) or after matter.js legitimately discards persisted state on a `FeatureMap` change between restarts. Add a `MATTERBRIDGE_SKIP_AUTO_ALLOCATE_CAMERA_AV_STREAM_MANAGEMENT` environment variable to disable this (set to `1`) for the CHIP conformance suite, whose `TC_AVSM_2_2`/`TC_AVSM_2_5` assert the lists are empty immediately after commissioning — see `chipTests.md`'s "Camera AV Stream Management — Default Stream Self-Allocation" for the full rationale and verification. The self-allocated default snapshot stream's `minResolution`/`maxResolution` now span the full range of the endpoint's `snapshotCapabilities` (smallest to largest entry) instead of a single fixed point (the first/smallest entry), so a real client requesting any of the device's own advertised snapshot resolutions dedup-matches this default stream in `snapshotStreamAllocate` (Matter 1.6/1.5.1 §11.2.8.8.8) instead of allocating an unwanted duplicate — confirmed against a real `python-matter-server` dashboard trace that previously allocated a second, orphaned snapshot stream for exactly this reason.
36
52
 
37
53
  ### Changed
38
54
 
39
55
  - [screenshots]: Update screenshots.
40
56
 
57
+ ### Fixed
58
+
59
+ - [chime]: `MatterbridgeChimeServer` now rejects writes to the `SelectedChime` attribute with `NOT_FOUND` when the written chime ID is not present in `InstalledChimeSounds`, per Matter 1.6 Application Cluster spec §11.8.5.2. Previously any value was silently accepted, failing `TC_CHIME_2_3`.
60
+ - [camera]: `CameraAvStreamManagement.captureSnapshot` now rejects with `NOT_FOUND` when the requested `snapshotStreamId` (or automatic selection with no allocated snapshot stream) does not match an entry in `AllocatedSnapshotStreams`, per Matter 1.6 §11.2.8.13. Previously it always returned a snapshot. Fixed `TC_AVSM_2_10`.
61
+ - [camera]: `SnapshotStreamAllocate` now reuses an existing snapshot stream whose resolution range overlaps the request (narrowing its stored resolution to the new range) instead of only matching on exact field equality, per Matter 1.6 §11.2.8.8.8. Fixed `TC_AVSM_2_15` and `TC_AVSM_StreamReuseRangeParams`.
62
+ - [camera]: `VideoStreamAllocate` now enforces `MaxConcurrentEncoders`, rejecting a new (non-reused) allocation with `RESOURCE_EXHAUSTED` once the limit is reached, and validates the `MinFrameRate`/`MaxFrameRate` and `MinBitRate`/`MaxBitRate` cross-field constraints ("1 to Max...", Matter 1.6 §11.2.8.4) with `CONSTRAINT_ERROR`, neither of which matter.js enforces automatically.
63
+ - [camera]: `MPTZSetPosition` and `MPTZRelativeMove` now reject with `INVALID_COMMAND` when all of their fields (pan/tilt/zoom, or panDelta/tiltDelta/zoomDelta) are omitted, per Matter 1.6 §11.3.7. Previously an empty command was silently accepted as a no-op. Fixed `TC_AVSUM_2_2` and `TC_AVSUM_2_3`.
64
+ - [camera]: Remove the temporary `ImageControl` feature workaround from Audio Doorbell and Intercom, now that the underlying matter.js choice-conformance bug (ImageRotation/ImageFlipHorizontal/ImageFlipVertical enforced unconditionally instead of only when `ImageControl` is enabled) is fixed upstream. Both device types now correctly omit `ImageControl` and its attributes, matching the Matter specification for their device type. Also removed the now-obsolete `comment` on `TC_DeviceConformance` in `chipTests.json`.
65
+ - [camera]: Remove the same now-unneeded `ImageControl` attributes from Snapshot Camera (Snapshot feature only). Camera keeps `ImageControl` enabled: unlike the other three device types, its `webRtcTransportProviderServer.ts` automatic stream assignment gates on `endpoint.behaviors.has(MatterbridgeCameraAvStreamManagementServer)`, an exact match against that base class's declared Video/Audio/Snapshot/ImageControl feature set, so dropping `ImageControl` there breaks WebRTC `SolicitOffer`/`ProvideOffer` auto-assignment.
66
+ - [tests]: Add `SelectedChime` write coverage (accepted and rejected chime IDs) in `vitest/behaviors/chimeServer.test.ts`.
67
+ - [tests]: Add coverage for all the `CameraAvStreamManagement` and `CameraAvSettingsUserLevelManagement` fixes above in `vitest/behaviors/cameraAvStreamManagementServer.test.ts` and `vitest/behaviors/cameraAvSettingsUserLevelManagementServer.test.ts` (both files at 100% statements/branches/functions/lines).
68
+
41
69
  <a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="120"></a>
42
70
 
43
71
  ## [0.0.8] - 2026-07-26
package/README.md CHANGED
@@ -62,10 +62,6 @@ winget install --id Gyan.FFmpeg -e
62
62
  brew install ffmpeg
63
63
  ```
64
64
 
65
- ## TODO
66
-
67
- - 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.
68
-
69
65
  ## Supported device types
70
66
 
71
67
  ### Chime
@@ -94,7 +90,7 @@ Features:
94
90
 
95
91
  Features:
96
92
 
97
- - Exposes the Camera AV Stream Management cluster with the Video, Audio and ImageControl features (the Snapshot feature is not implemented in this example; see Snapshot Camera).
93
+ - Exposes the Camera AV Stream Management cluster with the Video, Audio, Snapshot and ImageControl features.
98
94
  - Exposes the WebRtcTransportProvider cluster and registers a WebRtcTransportRequestor client, so a bound device can solicit and receive WebRTC offers.
99
95
  - Allocates WebRTC session identifiers monotonically from 0 through 65534, wrapping to 0 and skipping identifiers that still belong to active sessions, as required by Matter 1.6.
100
96
  - Automatically selects or allocates a video/audio stream when a client's `SolicitOffer`/`ProvideOffer` omits `videoStreams`/`audioStreams` (and their deprecated single-id counterparts), per the Matter specification's automatic stream selection for revision 1 clients. This is required to interoperate with clients that never allocate streams explicitly, such as Home Assistant's Matter camera integration.
@@ -116,7 +112,7 @@ Supported by:
116
112
 
117
113
  Features:
118
114
 
119
- - Exposes the Camera AV Stream Management cluster with the Snapshot and Image Control features.
115
+ - Exposes the Camera AV Stream Management cluster with the Snapshot feature.
120
116
  - Supports configurable snapshot capabilities, encoder limits, content buffer size, and network bandwidth.
121
117
  - Supports configuring stream usages and their priority order with the SetStreamPriorities command.
122
118
  - Allocates and deallocates snapshot streams with generated stream identifiers.
@@ -138,7 +134,6 @@ Features:
138
134
  - Adds the required Chime client cluster automatically via `addChimeClient`, so a bound Chime device can be triggered when the doorbell button is pressed.
139
135
  - Identify cluster is always created (it is a required server cluster for this device type), with configurable identify time and type.
140
136
  - Configurable Power Source cluster type: Rechargeable, Replaceable, Battery, Wired, or None to omit the Power Source cluster entirely.
141
- - 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 a matter.js bug where the ImageRotation/ImageFlipHorizontal/ImageFlipVertical "at least one shall be present" choice conformance is enforced unconditionally instead of only when ImageControl is enabled (see the JSDoc in `src/devices/audioDoorbell.ts`).
142
137
 
143
138
  ### Floodlight Camera
144
139
 
@@ -167,7 +162,6 @@ Features:
167
162
  - Adds the optional Chime client cluster automatically via `addChimeClient`, so a bound Chime device can be triggered.
168
163
  - Optional Identify cluster support, with configurable identify time and type. Set to Identify.IdentifyType.None to omit the cluster entirely.
169
164
  - Configurable Power Source cluster type: Rechargeable, Replaceable, Battery, Wired, or None to omit the Power Source cluster entirely.
170
- - 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.
171
165
 
172
166
  Supported by:
173
167
 
@@ -391,153 +385,3 @@ All three calibration cards above are kept well under the Matter message size ce
391
385
  A `CaptureSnapshot` response whose `data` field doesn't fit fails to send: the client gets a generic invoke failure instead of an image, since the encoder cannot represent the required plaintext length in the message header. `CameraAvStreamManagement.CaptureSnapshot` returns its image as a single field of a single command response, so it inherits this ceiling directly. Matter has a dedicated mechanism for transferring larger payloads — BDX (Bulk Data Exchange), used for OTA updates and diagnostic logs — which splits big content across a sequence of acknowledged messages instead of one oversized one, but `CaptureSnapshot` doesn't use it.
392
386
 
393
387
  WebRTC media tracks transport encoded H.264 or Opus frames in RTP packets; they do not send an MP4, Ogg, or MPEG container directly. The current MP4 transfer deliberately uses the separate data-channel path. A future video-track test should parse the relevant elementary frames, packetize them as RTP, call werift's media track `writeRtp()`, and verify reception through `onTrack` and `onReceiveRtp`.
394
-
395
- ## Chip tests
396
-
397
- ### Create the container (Linux, macOS, and Windows)
398
-
399
- Run the `luligu/matterbridge:chip-test` docker image:
400
-
401
- - frontend on port 8585
402
- - plugin mapped to .
403
- - container test logs directory mapped on ./temp directory
404
-
405
- ```shell
406
- 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
407
- ```
408
-
409
- ### Add the plugin
410
-
411
- Add the plugin and restart the container
412
-
413
- ```shell
414
- npm install --no-fund --no-audit --verbose
415
- npm link matterbridge --no-fund --no-audit --verbose
416
- npm run build
417
- npm prune --omit=dev --no-fund --no-audit --verbose
418
- docker exec -it plugin-chip-test matterbridge --add matterbridge-example-camera
419
- docker restart plugin-chip-test
420
- ```
421
-
422
- ### Run the tests inside the container
423
-
424
- Open a shell in the container
425
-
426
- ```shell
427
- docker exec -it plugin-chip-test bash
428
- ```
429
-
430
- In the shell:
431
-
432
- ```bash
433
- # Generic device composition and conformance ✅ (one test fails for a known matter.js bug)
434
- python3 src/python_testing/TC_DeviceBasicComposition.py
435
- python3 src/python_testing/TC_DeviceConformance.py --bool-arg allow_provisional:true
436
- python3 src/python_testing/TC_DefaultWarnings.py --bool-arg pixit_allow_default_vendor_id:true
437
-
438
- # Doorbell mandatory Switch server
439
- python3 src/python_testing/TC_SWTCH.py
440
-
441
- # Chime cluster ✅
442
- python3 src/python_testing/TC_CHIME_2_2.py --endpoint 2
443
- python3 src/python_testing/TC_CHIME_2_3.py --endpoint 2
444
- python3 src/python_testing/TC_CHIME_2_5.py --endpoint 2
445
- python3 src/python_testing/TC_CHIME_2_6.py --endpoint 2
446
-
447
- # Camera AV Stream Management
448
- python3 src/python_testing/TC_AVSM_2_1.py
449
- python3 src/python_testing/TC_AVSM_2_2.py
450
- python3 src/python_testing/TC_AVSM_2_3.py
451
- python3 src/python_testing/TC_AVSM_2_4.py
452
- python3 src/python_testing/TC_AVSM_2_5.py
453
- python3 src/python_testing/TC_AVSM_2_6.py
454
- python3 src/python_testing/TC_AVSM_2_7.py
455
- python3 src/python_testing/TC_AVSM_2_8.py
456
- python3 src/python_testing/TC_AVSM_2_9.py
457
- python3 src/python_testing/TC_AVSM_2_10.py
458
- python3 src/python_testing/TC_AVSM_2_11.py
459
- python3 src/python_testing/TC_AVSM_2_12.py
460
- python3 src/python_testing/TC_AVSM_2_13.py
461
- python3 src/python_testing/TC_AVSM_2_14.py
462
- python3 src/python_testing/TC_AVSM_2_15.py
463
- python3 src/python_testing/TC_AVSM_2_16.py
464
- python3 src/python_testing/TC_AVSM_2_17.py
465
- python3 src/python_testing/TC_AVSM_2_18.py
466
- python3 src/python_testing/TC_AVSM_2_19.py
467
- python3 src/python_testing/TC_AVSM_2_20.py
468
- python3 src/python_testing/TC_AVSM_2_21.py
469
-
470
- # Additional Camera AV Stream Management tests
471
- python3 src/python_testing/TC_AVSM_StreamReuseRangeParams.py
472
- python3 src/python_testing/TC_AVSM_VideoStreamsPersistence.py
473
-
474
- # Audio/Video Stream Usage Management
475
- python3 src/python_testing/TC_AVSUM_2_1.py
476
- python3 src/python_testing/TC_AVSUM_2_2.py
477
- python3 src/python_testing/TC_AVSUM_2_3.py
478
- python3 src/python_testing/TC_AVSUM_2_4.py
479
- python3 src/python_testing/TC_AVSUM_2_5.py
480
- python3 src/python_testing/TC_AVSUM_2_6.py
481
- python3 src/python_testing/TC_AVSUM_2_7.py
482
- python3 src/python_testing/TC_AVSUM_2_8.py
483
- python3 src/python_testing/TC_AVSUM_2_9.py
484
-
485
- # Push AV Stream Transport
486
- python3 src/python_testing/TC_PAVST_2_1.py
487
- python3 src/python_testing/TC_PAVST_2_2.py
488
- python3 src/python_testing/TC_PAVST_2_3.py
489
- python3 src/python_testing/TC_PAVST_2_4.py
490
- python3 src/python_testing/TC_PAVST_2_5.py
491
- python3 src/python_testing/TC_PAVST_2_6.py
492
- python3 src/python_testing/TC_PAVST_2_7.py
493
- python3 src/python_testing/TC_PAVST_2_8.py
494
- python3 src/python_testing/TC_PAVST_2_9.py
495
- python3 src/python_testing/TC_PAVST_2_10.py
496
- python3 src/python_testing/TC_PAVST_2_11.py
497
- python3 src/python_testing/TC_PAVST_2_12.py
498
- python3 src/python_testing/TC_PAVST_2_13.py
499
-
500
- # WebRTC Transport Provider
501
- python3 src/python_testing/TC_WEBRTCP_2_1.py
502
- python3 src/python_testing/TC_WEBRTCP_2_2.py
503
- python3 src/python_testing/TC_WEBRTCP_2_3.py
504
- python3 src/python_testing/TC_WEBRTCP_2_4.py
505
- python3 src/python_testing/TC_WEBRTCP_2_5.py
506
- python3 src/python_testing/TC_WEBRTCP_2_6.py
507
- python3 src/python_testing/TC_WEBRTCP_2_7.py
508
- python3 src/python_testing/TC_WEBRTCP_2_8.py
509
- python3 src/python_testing/TC_WEBRTCP_2_9.py
510
- python3 src/python_testing/TC_WEBRTCP_2_10.py
511
- python3 src/python_testing/TC_WEBRTCP_2_11.py
512
- python3 src/python_testing/TC_WEBRTCP_2_12.py
513
- python3 src/python_testing/TC_WEBRTCP_2_13.py
514
- python3 src/python_testing/TC_WEBRTCP_2_14.py
515
- python3 src/python_testing/TC_WEBRTCP_2_15.py
516
- python3 src/python_testing/TC_WEBRTCP_2_16.py
517
- python3 src/python_testing/TC_WEBRTCP_2_17.py
518
- python3 src/python_testing/TC_WEBRTCP_2_18.py
519
- python3 src/python_testing/TC_WEBRTCP_2_19.py
520
- python3 src/python_testing/TC_WEBRTCP_2_20.py
521
- python3 src/python_testing/TC_WEBRTCP_2_21.py
522
- python3 src/python_testing/TC_WEBRTCP_2_22.py
523
- python3 src/python_testing/TC_WEBRTCP_2_23.py
524
- python3 src/python_testing/TC_WEBRTCP_2_24.py
525
- python3 src/python_testing/TC_WEBRTCP_2_25.py
526
- python3 src/python_testing/TC_WEBRTCP_2_26.py
527
- python3 src/python_testing/TC_WEBRTCP_2_27.py
528
- python3 src/python_testing/TC_WEBRTCP_2_28.py
529
- python3 src/python_testing/TC_WEBRTCP_2_29.py
530
- python3 src/python_testing/TC_WEBRTCP_2_30.py
531
- python3 src/python_testing/TC_WEBRTCP_2_31.py
532
- python3 src/python_testing/TC_WEBRTCP_2_32.py
533
-
534
- # Zone Management
535
- python3 src/python_testing/TC_ZONEMGMT_2_4.py
536
- ```
537
-
538
- ### Stop the container and link the local matterbridge instance
539
-
540
- ```shell
541
- docker stop plugin-chip-test
542
- npm run link
543
- ```
@@ -9,6 +9,9 @@ export class MatterbridgeCameraAvSettingsUserLevelManagementServer extends Camer
9
9
  mptzSetPosition(request) {
10
10
  const device = this.endpoint.stateOf(MatterbridgeServer);
11
11
  const { pan, tilt, zoom } = request;
12
+ if (pan === undefined && tilt === undefined && zoom === undefined) {
13
+ throw new StatusResponseError('MPTZSetPosition requires at least one of pan, tilt or zoom to be present', Status.InvalidCommand);
14
+ }
12
15
  if (pan !== undefined && (pan < this.state.panMin || pan > this.state.panMax)) {
13
16
  throw new StatusResponseError(`Pan ${pan} is outside of the supported range [${this.state.panMin}, ${this.state.panMax}]`, Status.ConstraintError);
14
17
  }
@@ -27,6 +30,9 @@ export class MatterbridgeCameraAvSettingsUserLevelManagementServer extends Camer
27
30
  }
28
31
  mptzRelativeMove(request) {
29
32
  const device = this.endpoint.stateOf(MatterbridgeServer);
33
+ if (request.panDelta === undefined && request.tiltDelta === undefined && request.zoomDelta === undefined) {
34
+ throw new StatusResponseError('MPTZRelativeMove requires at least one of panDelta, tiltDelta or zoomDelta to be present', Status.InvalidCommand);
35
+ }
30
36
  const current = this.state.mptzPosition;
31
37
  const pan = request.panDelta === undefined ? current.pan : clamp((current.pan ?? 0) + request.panDelta, this.state.panMin, this.state.panMax);
32
38
  const tilt = request.tiltDelta === undefined ? current.tilt : clamp((current.tilt ?? 0) + request.tiltDelta, this.state.tiltMin, this.state.tiltMax);
@@ -2,8 +2,14 @@ import { readFileSync } from 'node:fs';
2
2
  import { MatterbridgeServer } from 'matterbridge/behaviors';
3
3
  import { CameraAvStreamManagementServer } from 'matterbridge/matter/behaviors';
4
4
  import { CameraAvStreamManagement } from 'matterbridge/matter/clusters';
5
- import { Status, StatusResponseError } from 'matterbridge/matter/types';
5
+ import { Status, StatusResponseError, StreamUsage } from 'matterbridge/matter/types';
6
6
  const DEFAULT_CAMERA_COLOR_TEST_RESOLUTION = '640x480';
7
+ const AUDIO_STREAM_BIT_DEPTHS = [8, 16, 24, 32];
8
+ function numericEnumValues(enumObject) {
9
+ return Object.values(enumObject).filter((value) => typeof value === 'number');
10
+ }
11
+ const AUDIO_CODECS = numericEnumValues(CameraAvStreamManagement.AudioCodec);
12
+ const VIDEO_CODECS = numericEnumValues(CameraAvStreamManagement.VideoCodec);
7
13
  const cameraColorTestJpegs = {
8
14
  '640x480': { data: readFileSync(new URL('../../assets/camera-color-test-640-480.jpeg', import.meta.url)), resolution: { width: 640, height: 480 } },
9
15
  '1280x720': { data: readFileSync(new URL('../../assets/camera-color-test-1280-720.jpeg', import.meta.url)), resolution: { width: 1280, height: 720 } },
@@ -13,6 +19,83 @@ export function cameraColorTestJpegForResolution(requestedResolution) {
13
19
  return cameraColorTestJpegs[`${requestedResolution.width}x${requestedResolution.height}`] ?? cameraColorTestJpegs[DEFAULT_CAMERA_COLOR_TEST_RESOLUTION];
14
20
  }
15
21
  export class MatterbridgeCameraAvStreamManagementServer extends CameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Video, CameraAvStreamManagement.Feature.Audio, CameraAvStreamManagement.Feature.Snapshot, CameraAvStreamManagement.Feature.ImageControl) {
22
+ #isAutoAllocateSkipped() {
23
+ return process.env.MATTERBRIDGE_SKIP_AUTO_ALLOCATE_CAMERA_AV_STREAM_MANAGEMENT === '1';
24
+ }
25
+ initialize() {
26
+ if (this.#isAutoAllocateSkipped())
27
+ return;
28
+ if (this.features.video && this.state.allocatedVideoStreams.length === 0 && this.state.rateDistortionTradeOffPoints.length > 0 && this.state.streamUsagePriorities.length > 0) {
29
+ const { rateDistortionTradeOffPoints } = this.state;
30
+ let largestTradeOffPoint = rateDistortionTradeOffPoints[0];
31
+ for (const point of rateDistortionTradeOffPoints) {
32
+ if (point.resolution.width * point.resolution.height > largestTradeOffPoint.resolution.width * largestTradeOffPoint.resolution.height)
33
+ largestTradeOffPoint = point;
34
+ }
35
+ const { codec, resolution, minBitRate } = largestTradeOffPoint;
36
+ this.state.allocatedVideoStreams = [
37
+ {
38
+ videoStreamId: 0,
39
+ streamUsage: this.state.streamUsagePriorities[0],
40
+ videoCodec: codec,
41
+ minFrameRate: 1,
42
+ maxFrameRate: this.state.videoSensorParams.maxFps,
43
+ minResolution: this.state.minViewportResolution,
44
+ maxResolution: resolution,
45
+ minBitRate,
46
+ maxBitRate: minBitRate * 4,
47
+ keyFrameInterval: 4000,
48
+ ...(this.features.watermark ? { watermarkEnabled: false } : {}),
49
+ ...(this.features.onScreenDisplay ? { osdEnabled: false } : {}),
50
+ referenceCount: 0,
51
+ },
52
+ ];
53
+ }
54
+ if (this.features.audio &&
55
+ this.state.allocatedAudioStreams.length === 0 &&
56
+ this.state.microphoneCapabilities.supportedCodecs.length > 0 &&
57
+ this.state.streamUsagePriorities.length > 0) {
58
+ const { microphoneCapabilities } = this.state;
59
+ this.state.allocatedAudioStreams = [
60
+ {
61
+ audioStreamId: 0,
62
+ streamUsage: this.state.streamUsagePriorities[0],
63
+ audioCodec: microphoneCapabilities.supportedCodecs[0],
64
+ channelCount: microphoneCapabilities.maxNumberOfChannels,
65
+ sampleRate: microphoneCapabilities.supportedSampleRates[0],
66
+ bitRate: 32_000,
67
+ bitDepth: microphoneCapabilities.supportedBitDepths[0],
68
+ referenceCount: 0,
69
+ },
70
+ ];
71
+ }
72
+ if (this.features.snapshot && this.state.allocatedSnapshotStreams.length === 0 && this.state.snapshotCapabilities.length > 0) {
73
+ const { snapshotCapabilities } = this.state;
74
+ let smallestCapability = snapshotCapabilities[0];
75
+ let largestCapability = snapshotCapabilities[0];
76
+ for (const capability of snapshotCapabilities) {
77
+ if (capability.resolution.width * capability.resolution.height < smallestCapability.resolution.width * smallestCapability.resolution.height)
78
+ smallestCapability = capability;
79
+ if (capability.resolution.width * capability.resolution.height > largestCapability.resolution.width * largestCapability.resolution.height)
80
+ largestCapability = capability;
81
+ }
82
+ this.state.allocatedSnapshotStreams = [
83
+ {
84
+ snapshotStreamId: 0,
85
+ imageCodec: largestCapability.imageCodec,
86
+ frameRate: largestCapability.maxFrameRate,
87
+ minResolution: smallestCapability.resolution,
88
+ maxResolution: largestCapability.resolution,
89
+ quality: 90,
90
+ referenceCount: 0,
91
+ encodedPixels: false,
92
+ hardwareEncoder: false,
93
+ ...(this.features.watermark ? { watermarkEnabled: false } : {}),
94
+ ...(this.features.onScreenDisplay ? { osdEnabled: false } : {}),
95
+ },
96
+ ];
97
+ }
98
+ }
16
99
  setStreamPriorities(request) {
17
100
  const device = this.endpoint.stateOf(MatterbridgeServer);
18
101
  if ((this.features.snapshot && this.state.allocatedSnapshotStreams.length > 0) ||
@@ -31,8 +114,47 @@ export class MatterbridgeCameraAvStreamManagementServer extends CameraAvStreamMa
31
114
  }
32
115
  videoStreamAllocate(request) {
33
116
  const device = this.endpoint.stateOf(MatterbridgeServer);
34
- if (!this.state.supportedStreamUsages.includes(request.streamUsage)) {
35
- throw new StatusResponseError(`Stream usage ${request.streamUsage} is not present in supportedStreamUsages`, Status.ConstraintError);
117
+ if (request.streamUsage === StreamUsage.Internal) {
118
+ throw new StatusResponseError('Stream usage Internal is not allowed for VideoStreamAllocate', Status.ConstraintError);
119
+ }
120
+ if (!this.state.streamUsagePriorities.includes(request.streamUsage)) {
121
+ throw new StatusResponseError(`Stream usage ${request.streamUsage} is not present in streamUsagePriorities`, Status.InvalidInState);
122
+ }
123
+ if (!VIDEO_CODECS.includes(request.videoCodec)) {
124
+ throw new StatusResponseError(`VideoCodec ${request.videoCodec} is not a valid VideoCodecEnum value`, Status.ConstraintError);
125
+ }
126
+ if (request.minFrameRate > request.maxFrameRate) {
127
+ throw new StatusResponseError(`MinFrameRate ${request.minFrameRate} must not be greater than MaxFrameRate ${request.maxFrameRate}`, Status.ConstraintError);
128
+ }
129
+ if (request.minBitRate > request.maxBitRate) {
130
+ throw new StatusResponseError(`MinBitRate ${request.minBitRate} must not be greater than MaxBitRate ${request.maxBitRate}`, Status.ConstraintError);
131
+ }
132
+ const matchesTradeOffPoint = this.state.rateDistortionTradeOffPoints.some((point) => point.codec === request.videoCodec &&
133
+ point.resolution.width >= request.minResolution.width &&
134
+ point.resolution.width <= request.maxResolution.width &&
135
+ point.resolution.height >= request.minResolution.height &&
136
+ point.resolution.height <= request.maxResolution.height &&
137
+ point.minBitRate <= request.maxBitRate);
138
+ if (!matchesTradeOffPoint || request.maxFrameRate > this.state.videoSensorParams.maxFps) {
139
+ throw new StatusResponseError('VideoStreamAllocate requested parameters do not match any entry in rateDistortionTradeOffPoints or exceed videoSensorParams', Status.DynamicConstraintError);
140
+ }
141
+ const existingStream = this.state.allocatedVideoStreams.find((stream) => stream.streamUsage === request.streamUsage &&
142
+ stream.videoCodec === request.videoCodec &&
143
+ stream.minFrameRate === request.minFrameRate &&
144
+ stream.maxFrameRate === request.maxFrameRate &&
145
+ stream.minResolution.width === request.minResolution.width &&
146
+ stream.minResolution.height === request.minResolution.height &&
147
+ stream.maxResolution.width === request.maxResolution.width &&
148
+ stream.maxResolution.height === request.maxResolution.height &&
149
+ stream.minBitRate === request.minBitRate &&
150
+ stream.maxBitRate === request.maxBitRate &&
151
+ stream.keyFrameInterval === request.keyFrameInterval);
152
+ if (existingStream) {
153
+ device.log.info(`Reused video stream ${existingStream.videoStreamId} for usage ${request.streamUsage} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
154
+ return { videoStreamId: existingStream.videoStreamId };
155
+ }
156
+ if (this.state.allocatedVideoStreams.length >= this.state.maxConcurrentEncoders) {
157
+ throw new StatusResponseError(`VideoStreamAllocate would exceed maxConcurrentEncoders (${this.state.maxConcurrentEncoders})`, Status.ResourceExhausted);
36
158
  }
37
159
  let videoStreamId = 0;
38
160
  for (const stream of this.state.allocatedVideoStreams) {
@@ -69,8 +191,35 @@ export class MatterbridgeCameraAvStreamManagementServer extends CameraAvStreamMa
69
191
  }
70
192
  audioStreamAllocate(request) {
71
193
  const device = this.endpoint.stateOf(MatterbridgeServer);
72
- if (!this.state.supportedStreamUsages.includes(request.streamUsage)) {
73
- throw new StatusResponseError(`Stream usage ${request.streamUsage} is not present in supportedStreamUsages`, Status.ConstraintError);
194
+ if (request.streamUsage === StreamUsage.Internal) {
195
+ throw new StatusResponseError('Stream usage Internal is not allowed for AudioStreamAllocate', Status.ConstraintError);
196
+ }
197
+ if (!this.state.streamUsagePriorities.includes(request.streamUsage)) {
198
+ throw new StatusResponseError(`Stream usage ${request.streamUsage} is not present in streamUsagePriorities`, Status.InvalidInState);
199
+ }
200
+ if (!AUDIO_CODECS.includes(request.audioCodec)) {
201
+ throw new StatusResponseError(`AudioCodec ${request.audioCodec} is not a valid AudioCodecEnum value`, Status.ConstraintError);
202
+ }
203
+ if (!AUDIO_STREAM_BIT_DEPTHS.includes(request.bitDepth)) {
204
+ throw new StatusResponseError(`BitDepth ${request.bitDepth} is not one of ${AUDIO_STREAM_BIT_DEPTHS.join(', ')}`, Status.ConstraintError);
205
+ }
206
+ const { microphoneCapabilities } = this.state;
207
+ if (!microphoneCapabilities.supportedCodecs.includes(request.audioCodec) ||
208
+ request.channelCount < 1 ||
209
+ request.channelCount > microphoneCapabilities.maxNumberOfChannels ||
210
+ !microphoneCapabilities.supportedSampleRates.includes(request.sampleRate) ||
211
+ !microphoneCapabilities.supportedBitDepths.includes(request.bitDepth)) {
212
+ throw new StatusResponseError('AudioStreamAllocate requested audioCodec, channelCount, sampleRate or bitDepth is not supported by microphoneCapabilities', Status.DynamicConstraintError);
213
+ }
214
+ const existingStream = this.state.allocatedAudioStreams.find((stream) => stream.streamUsage === request.streamUsage &&
215
+ stream.audioCodec === request.audioCodec &&
216
+ stream.channelCount === request.channelCount &&
217
+ stream.sampleRate === request.sampleRate &&
218
+ stream.bitRate === request.bitRate &&
219
+ stream.bitDepth === request.bitDepth);
220
+ if (existingStream) {
221
+ device.log.info(`Reused audio stream ${existingStream.audioStreamId} for usage ${request.streamUsage} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
222
+ return { audioStreamId: existingStream.audioStreamId };
74
223
  }
75
224
  let audioStreamId = 0;
76
225
  for (const stream of this.state.allocatedAudioStreams) {
@@ -102,6 +251,42 @@ export class MatterbridgeCameraAvStreamManagementServer extends CameraAvStreamMa
102
251
  }
103
252
  async snapshotStreamAllocate(request) {
104
253
  const device = this.endpoint.stateOf(MatterbridgeServer);
254
+ const { minResolution, maxResolution } = request;
255
+ const matchesCapability = this.state.snapshotCapabilities.some((capability) => capability.resolution.width >= minResolution.width &&
256
+ capability.resolution.width <= maxResolution.width &&
257
+ capability.resolution.height >= minResolution.height &&
258
+ capability.resolution.height <= maxResolution.height);
259
+ if (!matchesCapability) {
260
+ throw new StatusResponseError('SnapshotStreamAllocate requested minResolution/maxResolution range does not match any entry in snapshotCapabilities', Status.DynamicConstraintError);
261
+ }
262
+ const existingStream = this.state.allocatedSnapshotStreams.find((stream) => stream.imageCodec === request.imageCodec &&
263
+ stream.frameRate === request.maxFrameRate &&
264
+ stream.quality === request.quality &&
265
+ stream.watermarkEnabled === request.watermarkEnabled &&
266
+ stream.osdEnabled === request.osdEnabled &&
267
+ stream.minResolution.width <= request.maxResolution.width &&
268
+ stream.maxResolution.width >= request.minResolution.width &&
269
+ stream.minResolution.height <= request.maxResolution.height &&
270
+ stream.maxResolution.height >= request.minResolution.height);
271
+ if (existingStream) {
272
+ this.state.allocatedSnapshotStreams = this.state.allocatedSnapshotStreams.map((stream) => stream.snapshotStreamId === existingStream.snapshotStreamId
273
+ ? {
274
+ snapshotStreamId: stream.snapshotStreamId,
275
+ imageCodec: stream.imageCodec,
276
+ frameRate: stream.frameRate,
277
+ minResolution: request.minResolution,
278
+ maxResolution: request.maxResolution,
279
+ quality: stream.quality,
280
+ referenceCount: stream.referenceCount,
281
+ encodedPixels: stream.encodedPixels,
282
+ hardwareEncoder: stream.hardwareEncoder,
283
+ watermarkEnabled: stream.watermarkEnabled,
284
+ osdEnabled: stream.osdEnabled,
285
+ }
286
+ : stream);
287
+ device.log.info(`Reused snapshot stream ${existingStream.snapshotStreamId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
288
+ return { snapshotStreamId: existingStream.snapshotStreamId };
289
+ }
105
290
  let snapshotStreamId = 0;
106
291
  for (const stream of this.state.allocatedSnapshotStreams) {
107
292
  snapshotStreamId = Math.max(snapshotStreamId, stream.snapshotStreamId + 1);
@@ -133,9 +318,14 @@ export class MatterbridgeCameraAvStreamManagementServer extends CameraAvStreamMa
133
318
  this.state.allocatedSnapshotStreams = this.state.allocatedSnapshotStreams.filter((stream) => stream.snapshotStreamId !== request.snapshotStreamId);
134
319
  device.log.info(`Deallocated snapshot stream ${request.snapshotStreamId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
135
320
  }
136
- async captureSnapshot(request) {
321
+ captureSnapshot(request) {
137
322
  const device = this.endpoint.stateOf(MatterbridgeServer);
138
- device.log.info(`Capturing snapshot ${request.snapshotStreamId ?? 'auto'} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
323
+ const { snapshotStreamId } = request;
324
+ const stream = this.state.allocatedSnapshotStreams.find((s) => snapshotStreamId === null || s.snapshotStreamId === snapshotStreamId);
325
+ if (!stream) {
326
+ throw new StatusResponseError(`Snapshot stream ${snapshotStreamId ?? 'auto'} is not present in allocatedSnapshotStreams`, Status.NotFound);
327
+ }
328
+ device.log.info(`Capturing snapshot ${snapshotStreamId ?? 'auto'} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
139
329
  device.log.debug(`MatterbridgeCameraAvStreamManagementServer: captureSnapshot called with snapshotStreamId ${request.snapshotStreamId}`);
140
330
  const { data, resolution } = cameraColorTestJpegForResolution(request.requestedResolution);
141
331
  return {
@@ -3,6 +3,14 @@ import { ChimeServer } from 'matterbridge/matter/behaviors';
3
3
  import { Status, StatusResponseError } from 'matterbridge/matter/types';
4
4
  const ChimeServerBase = ChimeServer.enable({ events: { chimeStartedPlaying: true } });
5
5
  export class MatterbridgeChimeServer extends ChimeServerBase {
6
+ initialize() {
7
+ this.reactTo(this.events.selectedChime$Changing, this.#assertSelectedChime);
8
+ }
9
+ #assertSelectedChime(chimeId) {
10
+ if (!this.state.installedChimeSounds.some((chimeSound) => chimeSound.chimeId === chimeId)) {
11
+ throw new StatusResponseError(`MatterbridgeChimeServer: chime sound ${chimeId} is not present in installedChimeSounds (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`, Status.NotFound);
12
+ }
13
+ }
6
14
  async playChimeSound(request) {
7
15
  const device = this.endpoint.stateOf(MatterbridgeServer);
8
16
  if (!this.state.enabled) {
@@ -1,12 +1,14 @@
1
1
  import { MatterbridgeServer } from 'matterbridge/behaviors';
2
2
  import { Node } from 'matterbridge/matter';
3
3
  import { WebRtcTransportProviderServer, WebRtcTransportRequestorClient } from 'matterbridge/matter/behaviors';
4
+ import { WebRtcTransportDefinitions } from 'matterbridge/matter/clusters';
4
5
  import { EndpointNumber, FabricIndex, NodeId, StreamUsage, Status, StatusResponseError } from 'matterbridge/matter/types';
5
6
  import { WeriftWebRtcSession } from '../webrtc/weriftSession.js';
6
7
  import { MatterbridgeCameraAvStreamManagementServer } from './cameraAvStreamManagementServer.js';
7
8
  const DEFERRED_INVOKE_DELAY_MS = 250;
8
9
  const ICE_CANDIDATE_APPLY_TIMEOUT_MS = 5000;
9
10
  const MAX_WEB_RTC_SESSION_ID = 0xfffe;
11
+ const MAX_CONCURRENT_SESSIONS = 5;
10
12
  export function allocateWebRtcSessionId(nextCandidate, activeSessionIds) {
11
13
  const firstCandidate = nextCandidate;
12
14
  let candidate = firstCandidate;
@@ -61,6 +63,17 @@ export class MatterbridgeWebRtcTransportProviderServer extends WebRtcTransportPr
61
63
  audioStreams: request.audioStreams ?? (request.audioStreamId !== undefined && request.audioStreamId !== null ? [request.audioStreamId] : undefined),
62
64
  };
63
65
  }
66
+ #hasNoStreamFields(request) {
67
+ return request.videoStreams === undefined && request.audioStreams === undefined && request.videoStreamId === undefined && request.audioStreamId === undefined;
68
+ }
69
+ #validateNoConflictingStreamFields(request) {
70
+ if ((request.videoStreams !== undefined && request.videoStreamId !== undefined) || (request.audioStreams !== undefined && request.audioStreamId !== undefined)) {
71
+ throw new StatusResponseError('MatterbridgeWebRtcTransportProviderServer: videoStreams/audioStreams and the deprecated videoStreamId/audioStreamId fields are mutually exclusive', Status.InvalidCommand);
72
+ }
73
+ }
74
+ #isStrictWebRtcTransport() {
75
+ return process.env.MATTERBRIDGE_STRICT_WEBRTCTRANSPORT === '1';
76
+ }
64
77
  #resolveVideoResolution(videoStreams) {
65
78
  const videoStreamId = videoStreams?.[0];
66
79
  if (videoStreamId === undefined)
@@ -73,14 +86,26 @@ export class MatterbridgeWebRtcTransportProviderServer extends WebRtcTransportPr
73
86
  return undefined;
74
87
  return `${stream.maxResolution.width}x${stream.maxResolution.height}`;
75
88
  }
89
+ #selectExistingVideoStreamId(streamUsage) {
90
+ const allocatedVideoStreams = [...this.endpoint.stateOf(MatterbridgeCameraAvStreamManagementServer).allocatedVideoStreams];
91
+ return (allocatedVideoStreams.find((stream) => stream.streamUsage === streamUsage) ?? allocatedVideoStreams[0])?.videoStreamId;
92
+ }
93
+ #selectExistingAudioStreamId(streamUsage) {
94
+ const allocatedAudioStreams = [...this.endpoint.stateOf(MatterbridgeCameraAvStreamManagementServer).allocatedAudioStreams];
95
+ return (allocatedAudioStreams.find((stream) => stream.streamUsage === streamUsage) ?? allocatedAudioStreams[0])?.audioStreamId;
96
+ }
76
97
  async #autoAssignStreams(streamUsage) {
77
98
  if (!this.endpoint.behaviors.has(MatterbridgeCameraAvStreamManagementServer))
78
99
  return {};
79
100
  const state = this.endpoint.stateOf(MatterbridgeCameraAvStreamManagementServer);
80
- const allocatedVideoStreams = [...state.allocatedVideoStreams];
81
- let videoStreamId = (allocatedVideoStreams.find((stream) => stream.streamUsage === streamUsage) ?? allocatedVideoStreams[0])?.videoStreamId;
101
+ let videoStreamId = this.#selectExistingVideoStreamId(streamUsage);
82
102
  if (videoStreamId === undefined && state.rateDistortionTradeOffPoints.length > 0) {
83
- const [{ codec, resolution, minBitRate }] = state.rateDistortionTradeOffPoints;
103
+ let largestTradeOffPoint = state.rateDistortionTradeOffPoints[0];
104
+ for (const point of state.rateDistortionTradeOffPoints) {
105
+ if (point.resolution.width * point.resolution.height > largestTradeOffPoint.resolution.width * largestTradeOffPoint.resolution.height)
106
+ largestTradeOffPoint = point;
107
+ }
108
+ const { codec, resolution, minBitRate } = largestTradeOffPoint;
84
109
  ({ videoStreamId } = await this.endpoint.act((agent) => agent.get(MatterbridgeCameraAvStreamManagementServer).videoStreamAllocate({
85
110
  streamUsage,
86
111
  videoCodec: codec,
@@ -89,12 +114,11 @@ export class MatterbridgeWebRtcTransportProviderServer extends WebRtcTransportPr
89
114
  minResolution: state.minViewportResolution,
90
115
  maxResolution: resolution,
91
116
  minBitRate,
92
- maxBitRate: minBitRate,
117
+ maxBitRate: minBitRate * 4,
93
118
  keyFrameInterval: 4000,
94
119
  })));
95
120
  }
96
- const allocatedAudioStreams = [...state.allocatedAudioStreams];
97
- let audioStreamId = (allocatedAudioStreams.find((stream) => stream.streamUsage === streamUsage) ?? allocatedAudioStreams[0])?.audioStreamId;
121
+ let audioStreamId = this.#selectExistingAudioStreamId(streamUsage);
98
122
  if (audioStreamId === undefined && state.microphoneCapabilities.supportedCodecs.length > 0) {
99
123
  const { microphoneCapabilities } = state;
100
124
  ({ audioStreamId } = await this.endpoint.act((agent) => agent.get(MatterbridgeCameraAvStreamManagementServer).audioStreamAllocate({
@@ -111,16 +135,92 @@ export class MatterbridgeWebRtcTransportProviderServer extends WebRtcTransportPr
111
135
  audioStreams: audioStreamId === undefined ? undefined : [audioStreamId],
112
136
  };
113
137
  }
138
+ #validateAllocatedStreamIds(kind, ids) {
139
+ const state = this.endpoint.stateOf(MatterbridgeCameraAvStreamManagementServer);
140
+ const attributeName = kind === 'video' ? 'AllocatedVideoStreams' : 'AllocatedAudioStreams';
141
+ const allocatedIds = kind === 'video' ? state.allocatedVideoStreams.map((stream) => stream.videoStreamId) : state.allocatedAudioStreams.map((stream) => stream.audioStreamId);
142
+ if (allocatedIds.length === 0) {
143
+ throw new StatusResponseError(`MatterbridgeWebRtcTransportProviderServer: no ${kind} stream is allocated (${attributeName} is empty)`, Status.InvalidInState);
144
+ }
145
+ if (new Set(ids).size !== ids.length) {
146
+ throw new StatusResponseError(`MatterbridgeWebRtcTransportProviderServer: duplicate ${kind} stream id in the request`, Status.AlreadyExists);
147
+ }
148
+ for (const id of ids) {
149
+ if (!allocatedIds.includes(id)) {
150
+ throw new StatusResponseError(`MatterbridgeWebRtcTransportProviderServer: ${kind} stream ${id} is not present in ${attributeName}`, Status.DynamicConstraintError);
151
+ }
152
+ }
153
+ }
154
+ #validateStreamUsage(streamUsage) {
155
+ const streamUsagePriorities = this.endpoint.behaviors.has(MatterbridgeCameraAvStreamManagementServer)
156
+ ? this.endpoint.stateOf(MatterbridgeCameraAvStreamManagementServer).streamUsagePriorities
157
+ : [];
158
+ if (!streamUsagePriorities.includes(streamUsage)) {
159
+ throw new StatusResponseError(`MatterbridgeWebRtcTransportProviderServer: stream usage ${streamUsage} is not present in streamUsagePriorities`, Status.DynamicConstraintError);
160
+ }
161
+ }
162
+ #resolveStrictStreamLists(request, streamUsage) {
163
+ let videoStreams;
164
+ if (request.videoStreams !== undefined) {
165
+ videoStreams = request.videoStreams;
166
+ }
167
+ else if (request.videoStreamId === null) {
168
+ const selected = this.#selectExistingVideoStreamId(streamUsage);
169
+ videoStreams = selected === undefined ? [] : [selected];
170
+ }
171
+ else if (request.videoStreamId !== undefined) {
172
+ videoStreams = [request.videoStreamId];
173
+ }
174
+ if (videoStreams !== undefined)
175
+ this.#validateAllocatedStreamIds('video', videoStreams);
176
+ let audioStreams;
177
+ if (request.audioStreams !== undefined) {
178
+ audioStreams = request.audioStreams;
179
+ }
180
+ else if (request.audioStreamId === null) {
181
+ const selected = this.#selectExistingAudioStreamId(streamUsage);
182
+ audioStreams = selected === undefined ? [] : [selected];
183
+ }
184
+ else if (request.audioStreamId !== undefined) {
185
+ audioStreams = [request.audioStreamId];
186
+ }
187
+ if (audioStreams !== undefined)
188
+ this.#validateAllocatedStreamIds('audio', audioStreams);
189
+ return { videoStreams, audioStreams };
190
+ }
114
191
  #echoDeprecatedStreamIds(request, videoStreams, audioStreams) {
115
192
  return {
116
193
  videoStreamId: request.videoStreamId === undefined ? undefined : (videoStreams?.[0] ?? null),
117
194
  audioStreamId: request.audioStreamId === undefined ? undefined : (audioStreams?.[0] ?? null),
118
195
  };
119
196
  }
197
+ #evictIfOverCapacity(webRtcSessionId, requestorEndpoint) {
198
+ if (this.state.currentSessions.length <= MAX_CONCURRENT_SESSIONS)
199
+ return false;
200
+ this.state.currentSessions = this.state.currentSessions.filter((session) => session.id !== webRtcSessionId);
201
+ const device = this.endpoint.stateOf(MatterbridgeServer);
202
+ device.log.notice(`MatterbridgeWebRtcTransportProviderServer: session ${webRtcSessionId} exceeds MAX_CONCURRENT_SESSIONS (${MAX_CONCURRENT_SESSIONS}); evicting with WebRtcEndReason.OutOfResources (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
203
+ if (requestorEndpoint) {
204
+ this.#invokeDeferred(async () => requestorEndpoint.commandsOf(WebRtcTransportRequestorClient).end({ webRtcSessionId, reason: WebRtcTransportDefinitions.WebRtcEndReason.OutOfResources }), `End (OutOfResources) for session ${webRtcSessionId}`);
205
+ }
206
+ return true;
207
+ }
120
208
  async solicitOffer(request) {
121
- let { videoStreams, audioStreams } = this.#resolveStreamLists(request);
122
- if (!videoStreams?.length && !audioStreams?.length) {
123
- ({ videoStreams, audioStreams } = await this.#autoAssignStreams(request.streamUsage));
209
+ this.#validateNoConflictingStreamFields(request);
210
+ let videoStreams;
211
+ let audioStreams;
212
+ if (this.#isStrictWebRtcTransport()) {
213
+ if (this.#hasNoStreamFields(request)) {
214
+ throw new StatusResponseError('MatterbridgeWebRtcTransportProviderServer.solicitOffer requires at least one of videoStreams, audioStreams, videoStreamId or audioStreamId to be present', Status.InvalidCommand);
215
+ }
216
+ this.#validateStreamUsage(request.streamUsage);
217
+ ({ videoStreams, audioStreams } = this.#resolveStrictStreamLists(request, request.streamUsage));
218
+ }
219
+ else {
220
+ ({ videoStreams, audioStreams } = this.#resolveStreamLists(request));
221
+ if (!videoStreams?.length && !audioStreams?.length) {
222
+ ({ videoStreams, audioStreams } = await this.#autoAssignStreams(request.streamUsage));
223
+ }
124
224
  }
125
225
  if (!videoStreams?.length && !audioStreams?.length) {
126
226
  throw new StatusResponseError('MatterbridgeWebRtcTransportProviderServer.solicitOffer requires at least one of videoStreams or audioStreams; the camera has no video or audio stream to assign automatically', Status.ConstraintError);
@@ -138,14 +238,19 @@ export class MatterbridgeWebRtcTransportProviderServer extends WebRtcTransportPr
138
238
  metadataEnabled: request.metadataEnabled ?? false,
139
239
  videoStreams,
140
240
  audioStreams,
241
+ videoStreamId: videoStreams?.[0] ?? null,
242
+ audioStreamId: audioStreams?.[0] ?? null,
141
243
  fabricIndex,
142
244
  },
143
245
  ];
144
246
  device.log.info(`MatterbridgeWebRtcTransportProviderServer.solicitOffer: solicited a WebRTC offer for session ${webRtcSessionId} (stream usage ${request.streamUsage}) (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
247
+ const requestorEndpoint = await this.#resolvePeerRequestorEndpoint(peerNodeId, fabricIndex, request.originatingEndpointId);
248
+ if (this.#evictIfOverCapacity(webRtcSessionId, requestorEndpoint)) {
249
+ return { webRtcSessionId, deferredOffer: false, ...this.#echoDeprecatedStreamIds(request, videoStreams, audioStreams) };
250
+ }
145
251
  const webRtcPeer = new WeriftWebRtcSession(webRtcSessionId);
146
252
  this.internal.sessions.set(webRtcSessionId, webRtcPeer);
147
253
  const sdp = await webRtcPeer.createOffer({ video: !!videoStreams?.length, audio: !!audioStreams?.length, videoResolution: this.#resolveVideoResolution(videoStreams) });
148
- const requestorEndpoint = await this.#resolvePeerRequestorEndpoint(peerNodeId, fabricIndex, request.originatingEndpointId);
149
254
  if (requestorEndpoint) {
150
255
  this.#invokeDeferred(async () => requestorEndpoint.commandsOf(WebRtcTransportRequestorClient).offer({ webRtcSessionId, sdp }), `Offer for session ${webRtcSessionId}`);
151
256
  device.log.info(`MatterbridgeWebRtcTransportProviderServer.solicitOffer: invoking Offer on the peer's WebRtcTransportRequestor for session ${webRtcSessionId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
@@ -153,15 +258,27 @@ export class MatterbridgeWebRtcTransportProviderServer extends WebRtcTransportPr
153
258
  else {
154
259
  device.log.info(`MatterbridgeWebRtcTransportProviderServer.solicitOffer: could not reach the peer's WebRtcTransportRequestor; the Offer for session ${webRtcSessionId} was not sent (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
155
260
  }
156
- return { webRtcSessionId, deferredOffer: true, ...this.#echoDeprecatedStreamIds(request, videoStreams, audioStreams) };
261
+ return { webRtcSessionId, deferredOffer: false, ...this.#echoDeprecatedStreamIds(request, videoStreams, audioStreams) };
157
262
  }
158
263
  async provideOffer(request) {
159
264
  const device = this.endpoint.stateOf(MatterbridgeServer);
160
265
  let webRtcSessionId = request.webRtcSessionId;
161
266
  if (webRtcSessionId === null) {
162
- let { videoStreams, audioStreams } = this.#resolveStreamLists(request);
163
- if (!videoStreams?.length && !audioStreams?.length) {
164
- ({ videoStreams, audioStreams } = await this.#autoAssignStreams(request.streamUsage ?? StreamUsage.LiveView));
267
+ this.#validateNoConflictingStreamFields(request);
268
+ let videoStreams;
269
+ let audioStreams;
270
+ if (this.#isStrictWebRtcTransport()) {
271
+ if (this.#hasNoStreamFields(request)) {
272
+ throw new StatusResponseError('MatterbridgeWebRtcTransportProviderServer.provideOffer requires at least one of videoStreams, audioStreams, videoStreamId or audioStreamId to be present', Status.InvalidCommand);
273
+ }
274
+ this.#validateStreamUsage(request.streamUsage ?? StreamUsage.LiveView);
275
+ ({ videoStreams, audioStreams } = this.#resolveStrictStreamLists(request, request.streamUsage ?? StreamUsage.LiveView));
276
+ }
277
+ else {
278
+ ({ videoStreams, audioStreams } = this.#resolveStreamLists(request));
279
+ if (!videoStreams?.length && !audioStreams?.length) {
280
+ ({ videoStreams, audioStreams } = await this.#autoAssignStreams(request.streamUsage ?? StreamUsage.LiveView));
281
+ }
165
282
  }
166
283
  if (!videoStreams?.length && !audioStreams?.length) {
167
284
  throw new StatusResponseError('MatterbridgeWebRtcTransportProviderServer.provideOffer requires at least one of videoStreams or audioStreams; the camera has no video or audio stream to assign automatically', Status.ConstraintError);
@@ -178,9 +295,15 @@ export class MatterbridgeWebRtcTransportProviderServer extends WebRtcTransportPr
178
295
  metadataEnabled: request.metadataEnabled ?? false,
179
296
  videoStreams,
180
297
  audioStreams,
298
+ videoStreamId: videoStreams?.[0] ?? null,
299
+ audioStreamId: audioStreams?.[0] ?? null,
181
300
  fabricIndex,
182
301
  },
183
302
  ];
303
+ const requestorEndpointForCapacityCheck = await this.#resolvePeerRequestorEndpoint(peerNodeId, fabricIndex, request.originatingEndpointId ?? EndpointNumber(0));
304
+ if (this.#evictIfOverCapacity(webRtcSessionId, requestorEndpointForCapacityCheck)) {
305
+ return { webRtcSessionId, ...this.#echoDeprecatedStreamIds(request, videoStreams, audioStreams) };
306
+ }
184
307
  }
185
308
  else if (!this.state.currentSessions.some((session) => session.id === webRtcSessionId)) {
186
309
  throw new StatusResponseError(`WebRTC session ${webRtcSessionId} is not present in currentSessions`, Status.NotFound);
@@ -46,7 +46,7 @@ export class AudioDoorbell extends MatterbridgeEndpoint {
46
46
  }
47
47
  }
48
48
  export function createDefaultAudioCameraAvStreamManagementClusterServer(endpoint, options) {
49
- endpoint.behaviors.require(MatterbridgeCameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Audio, CameraAvStreamManagement.Feature.ImageControl), {
49
+ endpoint.behaviors.require(MatterbridgeCameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Audio), {
50
50
  ...options,
51
51
  hardPrivacyModeOn: false,
52
52
  statusLightEnabled: false,
@@ -56,9 +56,6 @@ export function createDefaultAudioCameraAvStreamManagementClusterServer(endpoint
56
56
  microphoneMaxLevel: 254,
57
57
  microphoneMinLevel: 0,
58
58
  microphoneAgcEnabled: false,
59
- imageRotation: 0,
60
- imageFlipVertical: false,
61
- imageFlipHorizontal: false,
62
59
  });
63
60
  return endpoint;
64
61
  }
@@ -7,11 +7,15 @@ import { addWebRtcTransportRequestorClient } from '../behaviors/clients.js';
7
7
  import { MatterbridgeWebRtcTransportProviderServer } from '../behaviors/webRtcTransportProviderServer.js';
8
8
  export class Camera extends MatterbridgeEndpoint {
9
9
  constructor(name, serial, options = {}) {
10
- const { identifyTime = 0, identifyType = Identify.IdentifyType.None, powerSourceType = 'Wired', ptz = false, maxContentBufferSize = 4_194_304, maxNetworkBandwidth = 10_000_000, supportedStreamUsages = [StreamUsage.LiveView, StreamUsage.Recording], streamUsagePriorities = supportedStreamUsages, maxConcurrentEncoders = 1, maxEncodedPixelRate = 1920 * 1080 * 30, videoSensorParams = { sensorWidth: 1920, sensorHeight: 1080, maxFps: 30 }, minViewportResolution = { width: 640, height: 360 }, rateDistortionTradeOffPoints = [{ codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 1920, height: 1080 }, minBitRate: 1_000_000 }], currentFrameRate = 30, viewport = { x1: 0, y1: 0, x2: videoSensorParams.sensorWidth, y2: videoSensorParams.sensorHeight }, microphoneCapabilities = { maxNumberOfChannels: 1, supportedCodecs: [CameraAvStreamManagement.AudioCodec.Opus], supportedSampleRates: [48000], supportedBitDepths: [16] }, snapshotCapabilities = [
10
+ const { identifyTime = 0, identifyType = Identify.IdentifyType.None, powerSourceType = 'Wired', ptz = false, maxContentBufferSize = 4_194_304, maxNetworkBandwidth = 10_000_000, supportedStreamUsages = [StreamUsage.LiveView, StreamUsage.Recording], streamUsagePriorities = supportedStreamUsages, maxConcurrentEncoders = 1, maxEncodedPixelRate = 1920 * 1080 * 60, videoSensorParams = { sensorWidth: 1920, sensorHeight: 1080, maxFps: 60 }, minViewportResolution = { width: 640, height: 360 }, rateDistortionTradeOffPoints = [
11
+ { codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 640, height: 480 }, minBitRate: 250_000 },
12
+ { codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 1280, height: 720 }, minBitRate: 500_000 },
13
+ { codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 1920, height: 1080 }, minBitRate: 1_000_000 },
14
+ ], currentFrameRate = 30, viewport = { x1: 0, y1: 0, x2: videoSensorParams.sensorWidth, y2: videoSensorParams.sensorHeight }, microphoneCapabilities = { maxNumberOfChannels: 1, supportedCodecs: [CameraAvStreamManagement.AudioCodec.Opus], supportedSampleRates: [48000], supportedBitDepths: [16] }, snapshotCapabilities = [
11
15
  { resolution: { width: 640, height: 480 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
12
16
  { resolution: { width: 1280, height: 720 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
13
17
  { resolution: { width: 1920, height: 1080 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
14
- ], allocatedSnapshotStreams = [], panMin = -170, panMax = 170, tiltMin = -20, tiltMax = 90, zoomMax = 10, mptzPosition = { pan: 0, tilt: 0, zoom: 1 }, id, number, tagList, mode, } = options;
18
+ ], panMin = -170, panMax = 170, tiltMin = -20, tiltMax = 90, zoomMax = 10, mptzPosition = { pan: 0, tilt: 0, zoom: 1 }, id, number, tagList, mode, } = options;
15
19
  super(powerSourceType === 'None' ? [camera] : [camera, powerSource], { id: id ?? `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}`, number, tagList, mode });
16
20
  if (identifyType !== Identify.IdentifyType.None) {
17
21
  this.createDefaultIdentifyClusterServer(identifyTime, identifyType);
@@ -48,7 +52,6 @@ export class Camera extends MatterbridgeEndpoint {
48
52
  viewport,
49
53
  microphoneCapabilities,
50
54
  snapshotCapabilities,
51
- allocatedSnapshotStreams,
52
55
  });
53
56
  if (ptz)
54
57
  createDefaultCameraAvSettingsUserLevelManagementClusterServer(this, { panMin, panMax, tiltMin, tiltMax, zoomMax, mptzPosition });
@@ -65,6 +68,7 @@ export function createDefaultCameraAvStreamManagementClusterServer(endpoint, opt
65
68
  statusLightBrightness: ThreeLevelAuto.Auto,
66
69
  allocatedVideoStreams: [],
67
70
  allocatedAudioStreams: [],
71
+ allocatedSnapshotStreams: [],
68
72
  microphoneMuted: false,
69
73
  microphoneVolumeLevel: 128,
70
74
  microphoneMaxLevel: 254,
@@ -33,11 +33,15 @@ export class FloodlightCamera extends MatterbridgeEndpoint {
33
33
  }
34
34
  fireAndForget(this.addFixedLabel('composed', 'FloodlightCamera'), this.log, 'Error adding composed label to floodlight camera');
35
35
  this.addRequiredClusters();
36
- const { identifyTime = 0, identifyType = Identify.IdentifyType.None, maxContentBufferSize = 4_194_304, maxNetworkBandwidth = 10_000_000, supportedStreamUsages = [StreamUsage.LiveView, StreamUsage.Recording], streamUsagePriorities = supportedStreamUsages, maxConcurrentEncoders = 1, maxEncodedPixelRate = 1920 * 1080 * 30, videoSensorParams = { sensorWidth: 1920, sensorHeight: 1080, maxFps: 30 }, minViewportResolution = { width: 640, height: 360 }, rateDistortionTradeOffPoints = [{ codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 1920, height: 1080 }, minBitRate: 1_000_000 }], currentFrameRate = 30, viewport = { x1: 0, y1: 0, x2: videoSensorParams.sensorWidth, y2: videoSensorParams.sensorHeight }, microphoneCapabilities = { maxNumberOfChannels: 1, supportedCodecs: [CameraAvStreamManagement.AudioCodec.Opus], supportedSampleRates: [48000], supportedBitDepths: [16] }, snapshotCapabilities = [
36
+ const { identifyTime = 0, identifyType = Identify.IdentifyType.None, maxContentBufferSize = 4_194_304, maxNetworkBandwidth = 10_000_000, supportedStreamUsages = [StreamUsage.LiveView, StreamUsage.Recording], streamUsagePriorities = supportedStreamUsages, maxConcurrentEncoders = 1, maxEncodedPixelRate = 1920 * 1080 * 60, videoSensorParams = { sensorWidth: 1920, sensorHeight: 1080, maxFps: 60 }, minViewportResolution = { width: 640, height: 360 }, rateDistortionTradeOffPoints = [
37
+ { codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 640, height: 480 }, minBitRate: 250_000 },
38
+ { codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 1280, height: 720 }, minBitRate: 500_000 },
39
+ { codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 1920, height: 1080 }, minBitRate: 1_000_000 },
40
+ ], currentFrameRate = 30, viewport = { x1: 0, y1: 0, x2: videoSensorParams.sensorWidth, y2: videoSensorParams.sensorHeight }, microphoneCapabilities = { maxNumberOfChannels: 1, supportedCodecs: [CameraAvStreamManagement.AudioCodec.Opus], supportedSampleRates: [48000], supportedBitDepths: [16] }, snapshotCapabilities = [
37
41
  { resolution: { width: 640, height: 480 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
38
42
  { resolution: { width: 1280, height: 720 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
39
43
  { resolution: { width: 1920, height: 1080 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
40
- ], allocatedSnapshotStreams = [], } = cameraOptions;
44
+ ], } = cameraOptions;
41
45
  const cameraChild = this.addChildDeviceType('Camera', camera, {});
42
46
  cameraChild.log.logName = 'Camera';
43
47
  if (identifyType !== Identify.IdentifyType.None) {
@@ -57,7 +61,6 @@ export class FloodlightCamera extends MatterbridgeEndpoint {
57
61
  viewport,
58
62
  microphoneCapabilities,
59
63
  snapshotCapabilities,
60
- allocatedSnapshotStreams,
61
64
  });
62
65
  createDefaultWebRtcTransportProviderClusterServer(cameraChild);
63
66
  addWebRtcTransportRequestorClient(cameraChild);
@@ -52,7 +52,7 @@ export class Intercom extends MatterbridgeEndpoint {
52
52
  }
53
53
  }
54
54
  export function createDefaultIntercomCameraAvStreamManagementClusterServer(endpoint, options) {
55
- endpoint.behaviors.require(MatterbridgeCameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Audio, CameraAvStreamManagement.Feature.Speaker, CameraAvStreamManagement.Feature.ImageControl), {
55
+ endpoint.behaviors.require(MatterbridgeCameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Audio, CameraAvStreamManagement.Feature.Speaker), {
56
56
  ...options,
57
57
  hardPrivacyModeOn: false,
58
58
  statusLightEnabled: false,
@@ -66,9 +66,6 @@ export function createDefaultIntercomCameraAvStreamManagementClusterServer(endpo
66
66
  speakerVolumeLevel: 128,
67
67
  speakerMaxLevel: 254,
68
68
  speakerMinLevel: 0,
69
- imageRotation: 0,
70
- imageFlipVertical: false,
71
- imageFlipHorizontal: false,
72
69
  });
73
70
  return endpoint;
74
71
  }
@@ -8,7 +8,7 @@ export class SnapshotCamera extends MatterbridgeEndpoint {
8
8
  { resolution: { width: 640, height: 480 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
9
9
  { resolution: { width: 1280, height: 720 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
10
10
  { resolution: { width: 1920, height: 1080 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
11
- ], maxNetworkBandwidth = 10000, supportedStreamUsages = [StreamUsage.Recording], allocatedSnapshotStreams = [], streamUsagePriorities = [StreamUsage.Recording], id, number, tagList, mode, } = options;
11
+ ], maxNetworkBandwidth = 10000, supportedStreamUsages = [StreamUsage.Recording], streamUsagePriorities = [StreamUsage.Recording], id, number, tagList, mode, } = options;
12
12
  super(powerSourceType === 'None' ? [snapshotCamera] : [snapshotCamera, powerSource], {
13
13
  id: id ?? `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}`,
14
14
  number,
@@ -42,14 +42,13 @@ export class SnapshotCamera extends MatterbridgeEndpoint {
42
42
  snapshotCapabilities,
43
43
  maxNetworkBandwidth,
44
44
  supportedStreamUsages,
45
- allocatedSnapshotStreams,
46
45
  streamUsagePriorities,
47
46
  });
48
47
  this.addRequiredClusters();
49
48
  }
50
49
  }
51
50
  export function createDefaultSnapshotCameraAvStreamManagementClusterServer(endpoint, options) {
52
- endpoint.behaviors.require(MatterbridgeCameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Snapshot, CameraAvStreamManagement.Feature.ImageControl), {
51
+ endpoint.behaviors.require(MatterbridgeCameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Snapshot), {
53
52
  maxContentBufferSize: options.maxContentBufferSize,
54
53
  maxNetworkBandwidth: options.maxNetworkBandwidth,
55
54
  supportedStreamUsages: options.supportedStreamUsages,
@@ -57,10 +56,7 @@ export function createDefaultSnapshotCameraAvStreamManagementClusterServer(endpo
57
56
  maxConcurrentEncoders: options.maxConcurrentEncoders,
58
57
  maxEncodedPixelRate: options.maxEncodedPixelRate,
59
58
  snapshotCapabilities: options.snapshotCapabilities,
60
- allocatedSnapshotStreams: options.allocatedSnapshotStreams,
61
- imageRotation: 0,
62
- imageFlipVertical: false,
63
- imageFlipHorizontal: false,
59
+ allocatedSnapshotStreams: [],
64
60
  });
65
61
  return endpoint;
66
62
  }
@@ -32,11 +32,15 @@ export class VideoDoorbell extends MatterbridgeEndpoint {
32
32
  }
33
33
  fireAndForget(this.addFixedLabel('composed', 'VideoDoorbell'), this.log, 'Error adding composed label to video doorbell');
34
34
  this.addRequiredClusters();
35
- const { identifyTime: cameraIdentifyTime = 0, identifyType: cameraIdentifyType = Identify.IdentifyType.None, maxContentBufferSize = 4_194_304, maxNetworkBandwidth = 10_000_000, supportedStreamUsages = [StreamUsage.LiveView, StreamUsage.Recording], streamUsagePriorities = supportedStreamUsages, maxConcurrentEncoders = 1, maxEncodedPixelRate = 1920 * 1080 * 30, videoSensorParams = { sensorWidth: 1920, sensorHeight: 1080, maxFps: 30 }, minViewportResolution = { width: 640, height: 360 }, rateDistortionTradeOffPoints = [{ codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 1920, height: 1080 }, minBitRate: 1_000_000 }], currentFrameRate = 30, viewport = { x1: 0, y1: 0, x2: videoSensorParams.sensorWidth, y2: videoSensorParams.sensorHeight }, microphoneCapabilities = { maxNumberOfChannels: 1, supportedCodecs: [CameraAvStreamManagement.AudioCodec.Opus], supportedSampleRates: [48000], supportedBitDepths: [16] }, snapshotCapabilities = [
35
+ const { identifyTime: cameraIdentifyTime = 0, identifyType: cameraIdentifyType = Identify.IdentifyType.None, maxContentBufferSize = 4_194_304, maxNetworkBandwidth = 10_000_000, supportedStreamUsages = [StreamUsage.LiveView, StreamUsage.Recording], streamUsagePriorities = supportedStreamUsages, maxConcurrentEncoders = 1, maxEncodedPixelRate = 1920 * 1080 * 60, videoSensorParams = { sensorWidth: 1920, sensorHeight: 1080, maxFps: 60 }, minViewportResolution = { width: 640, height: 360 }, rateDistortionTradeOffPoints = [
36
+ { codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 640, height: 480 }, minBitRate: 250_000 },
37
+ { codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 1280, height: 720 }, minBitRate: 500_000 },
38
+ { codec: CameraAvStreamManagement.VideoCodec.H264, resolution: { width: 1920, height: 1080 }, minBitRate: 1_000_000 },
39
+ ], currentFrameRate = 30, viewport = { x1: 0, y1: 0, x2: videoSensorParams.sensorWidth, y2: videoSensorParams.sensorHeight }, microphoneCapabilities = { maxNumberOfChannels: 1, supportedCodecs: [CameraAvStreamManagement.AudioCodec.Opus], supportedSampleRates: [48000], supportedBitDepths: [16] }, snapshotCapabilities = [
36
40
  { resolution: { width: 640, height: 480 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
37
41
  { resolution: { width: 1280, height: 720 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
38
42
  { resolution: { width: 1920, height: 1080 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
39
- ], allocatedSnapshotStreams = [], } = cameraOptions;
43
+ ], } = cameraOptions;
40
44
  const cameraChild = this.addChildDeviceType('Camera', camera, {});
41
45
  cameraChild.log.logName = 'Camera';
42
46
  if (cameraIdentifyType !== Identify.IdentifyType.None) {
@@ -56,7 +60,6 @@ export class VideoDoorbell extends MatterbridgeEndpoint {
56
60
  viewport,
57
61
  microphoneCapabilities,
58
62
  snapshotCapabilities,
59
- allocatedSnapshotStreams,
60
63
  });
61
64
  createDefaultWebRtcTransportProviderClusterServer(cameraChild);
62
65
  addWebRtcTransportRequestorClient(cameraChild);
package/dist/module.js CHANGED
@@ -82,7 +82,7 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
82
82
  const exampleDoorbell = new Doorbell('Doorbell', 'DOORBELL-001', {
83
83
  identifyTime: 5,
84
84
  identifyType: Identify.IdentifyType.VisibleIndicator,
85
- powerSourceType: 'Replaceable',
85
+ powerSourceType: 'Rechargeable',
86
86
  });
87
87
  await this.addDevice(exampleDoorbell);
88
88
  const exampleAudioDoorbell = new AudioDoorbell('Audio Doorbell', 'AUDIODOORBELL-001', {
@@ -107,7 +107,7 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
107
107
  });
108
108
  await this.addDevice(examplePtzCamera);
109
109
  const exampleFloodlightCamera = new FloodlightCamera('Floodlight Camera', 'FLOODLIGHTCAMERA-001', {
110
- powerSourceType: 'Wired',
110
+ powerSourceType: 'Battery',
111
111
  cameraOptions: { identifyTime: 5, identifyType: Identify.IdentifyType.VisibleIndicator },
112
112
  lightOptions: { name: 'Floodlight' },
113
113
  });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "matterbridge-example-camera",
3
- "version": "0.0.9-dev-20260727-f34a88a",
3
+ "version": "0.1.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "matterbridge-example-camera",
9
- "version": "0.0.9-dev-20260727-f34a88a",
9
+ "version": "0.1.0",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "node-ansi-logger": "3.3.0",
@@ -21,15 +21,6 @@
21
21
  "url": "https://www.buymeacoffee.com/luligugithub"
22
22
  }
23
23
  },
24
- "node_modules/@babel/runtime": {
25
- "version": "7.29.7",
26
- "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.29.7.tgz",
27
- "integrity": "sha512-Nq8OhGWiZIZGV6hLHoyAKLLcJihP/xFeBMGJoUrxTX2psI8dCifzLhZISFb+VWS3wFMRDmCGw5R+dOySCqPLhw==",
28
- "license": "MIT",
29
- "engines": {
30
- "node": ">=6.9.0"
31
- }
32
- },
33
24
  "node_modules/@fidm/asn1": {
34
25
  "version": "1.0.4",
35
26
  "resolved": "https://registry.npmjs.org/@fidm/asn1/-/asn1-1.0.4.tgz",
@@ -58,12 +49,6 @@
58
49
  "integrity": "sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==",
59
50
  "license": "MIT"
60
51
  },
61
- "node_modules/@minhducsun2002/leb128": {
62
- "version": "1.0.0",
63
- "resolved": "https://registry.npmjs.org/@minhducsun2002/leb128/-/leb128-1.0.0.tgz",
64
- "integrity": "sha512-eFrYUPDVHeuwWHluTG1kwNQUEUcFjVKYwPkU8z9DR1JH3AW7JtJsG9cRVGmwz809kKtGfwGJj58juCZxEvnI/g==",
65
- "license": "MIT"
66
- },
67
52
  "node_modules/@noble/curves": {
68
53
  "version": "1.9.7",
69
54
  "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.9.7.tgz",
@@ -281,12 +266,6 @@
281
266
  "integrity": "sha512-O5hkiFIcjjszPIYyUSyvScyvrBoV3NOEEZx/pMlsu44TKzWNkLVBBxnxJz42in5n3QIolYOcBYFCPZZ0h8SkwQ==",
282
267
  "license": "MIT"
283
268
  },
284
- "node_modules/aes-js": {
285
- "version": "3.1.2",
286
- "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz",
287
- "integrity": "sha512-e5pEa2kBnBOgR4Y/p20pskXI74UEz7de8ZGVo58asOtvSVG5YAbJeELPZxOmt+Bnz3rX753YKhfIn4X4l1PPRQ==",
288
- "license": "MIT"
289
- },
290
269
  "node_modules/asn1js": {
291
270
  "version": "3.0.10",
292
271
  "resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.0.10.tgz",
@@ -354,22 +333,6 @@
354
333
  "node": ">=8.0.0"
355
334
  }
356
335
  },
357
- "node_modules/date-fns": {
358
- "version": "2.30.0",
359
- "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.30.0.tgz",
360
- "integrity": "sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==",
361
- "license": "MIT",
362
- "dependencies": {
363
- "@babel/runtime": "^7.21.0"
364
- },
365
- "engines": {
366
- "node": ">=0.11"
367
- },
368
- "funding": {
369
- "type": "opencollective",
370
- "url": "https://opencollective.com/date-fns"
371
- }
372
- },
373
336
  "node_modules/debug": {
374
337
  "version": "4.4.0",
375
338
  "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz",
@@ -474,9 +437,9 @@
474
437
  "license": "MIT"
475
438
  },
476
439
  "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==",
440
+ "version": "1.52.2",
441
+ "resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.52.2.tgz",
442
+ "integrity": "sha512-HIgqL2BAWsWJtaqZRrqcrv7cEajQtCT9noR0dO8cGLKZKML9mmL4BjZOtm6j5I9qAp0v/hr/NmRZhuR6HZyQ7Q==",
480
443
  "license": "MPL-2.0",
481
444
  "workspaces": [
482
445
  ".",
@@ -491,12 +454,6 @@
491
454
  "url": "https://github.com/sponsors/Vanilagy"
492
455
  }
493
456
  },
494
- "node_modules/mp4box": {
495
- "version": "0.5.4",
496
- "resolved": "https://registry.npmjs.org/mp4box/-/mp4box-0.5.4.tgz",
497
- "integrity": "sha512-GcCH0fySxBurJtvr0dfhz0IxHZjc1RP+F+I8xw+LIwkU1a+7HJx8NCDiww1I5u4Hz6g4eR1JlGADEGJ9r4lSfA==",
498
- "license": "BSD-3-Clause"
499
- },
500
457
  "node_modules/ms": {
501
458
  "version": "2.1.3",
502
459
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
@@ -699,18 +656,16 @@
699
656
  }
700
657
  },
701
658
  "node_modules/werift-dtls": {
702
- "version": "0.5.7",
703
- "resolved": "https://registry.npmjs.org/werift-dtls/-/werift-dtls-0.5.7.tgz",
704
- "integrity": "sha512-z2fjbP7fFUFmu/Ky4bCKXzdgPTtmSY1DYi0TUf3GG2zJT4jMQ3TQmGY8y7BSSNGetvL4h3pRZ5un0EcSOWpPog==",
659
+ "version": "0.5.8",
660
+ "resolved": "https://registry.npmjs.org/werift-dtls/-/werift-dtls-0.5.8.tgz",
661
+ "integrity": "sha512-oH39cdCpVLqKcPZRMGQLcN+tIBixvMGqjCB9qCrH39Tu9Mmu8u2+zTzyl0Fod87EK6PNPgoNqMJt64xlSMfLnw==",
705
662
  "license": "MIT",
706
663
  "dependencies": {
707
664
  "@fidm/x509": "^1.2.1",
708
- "@noble/curves": "^1.3.0",
709
- "@peculiar/x509": "^1.9.2",
665
+ "@noble/curves": "^1.8.1",
666
+ "@peculiar/x509": "^1.12.3",
710
667
  "@shinyoshiaki/binary-data": "^0.6.1",
711
- "date-fns": "^2.29.3",
712
- "lodash": "^4.17.21",
713
- "rx.mini": "^1.2.2",
668
+ "debug": "4.4.0",
714
669
  "tweetnacl": "^1.0.3"
715
670
  },
716
671
  "engines": {
@@ -735,16 +690,14 @@
735
690
  }
736
691
  },
737
692
  "node_modules/werift-rtp": {
738
- "version": "0.8.8",
739
- "resolved": "https://registry.npmjs.org/werift-rtp/-/werift-rtp-0.8.8.tgz",
740
- "integrity": "sha512-GiYMSdvCyScQaw5bnEsraSoHUVZpjfokJAiLV4R1FsiB06t6XiebPYPpkqB9nYNNKiA8Z/cYWsym7wISq1sYSQ==",
693
+ "version": "0.8.9",
694
+ "resolved": "https://registry.npmjs.org/werift-rtp/-/werift-rtp-0.8.9.tgz",
695
+ "integrity": "sha512-uLFOawIXw8FblIp1akfIVYFuRNtNo7csRxYypLz0t++sUNCN7sPeghVqET/c3Mq7Tg2QA3oAb15fXIIuJEp2AA==",
741
696
  "license": "MIT",
742
697
  "dependencies": {
743
- "@minhducsun2002/leb128": "^1.0.0",
744
- "@shinyoshiaki/jspack": "^0.0.6",
745
- "aes-js": "^3.1.2",
746
698
  "buffer": "^6.0.3",
747
- "mp4box": "^0.5.3"
699
+ "debug": "4.4.0",
700
+ "mediabunny": "^1.45.2"
748
701
  },
749
702
  "engines": {
750
703
  "node": ">=10"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matterbridge-example-camera",
3
- "version": "0.0.9-dev-20260727-f34a88a",
3
+ "version": "0.1.0",
4
4
  "description": "Matterbridge camera example plugin",
5
5
  "author": "https://github.com/Luligu",
6
6
  "license": "Apache-2.0",