matterbridge-example-camera 0.0.4 → 0.0.5

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,6 +28,28 @@ 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.5] - 2026-07-20
32
+
33
+ ### Added
34
+
35
+ - [wirift]: Add codec negotiation and ffmpeg windows path.
36
+ - [audio doorbell]: Add the Audio Doorbell device type with the required Identify, Switch (MomentarySwitch feature), Camera AV Stream Management (Audio feature), and WebRtcTransportProvider clusters, plus the Chime and WebRtcTransportRequestor client clusters, and Power Source support.
37
+ - [clients]: Add `src/behaviors/clients.ts` with `addChimeClient`/`addWebRtcTransportRequestorClient` helpers, shared by `Doorbell`, `AudioDoorbell`, and `Camera`.
38
+ - [tests]: Add `vitest/behaviors/clients.test.ts` covering `addChimeClient`/`addWebRtcTransportRequestorClient`, and assert in `doorbell.test.ts`, `camera.test.ts`, and `audioDoorbell.test.ts` that the required client clusters are registered in `MatterbridgeBindingServer`'s `clientList` and `type.clientClusters`.
39
+ - [platform]: Add a server Chime and Doorbell to test binding.
40
+
41
+ ### Changed
42
+
43
+ - [package]: Update dependencies.
44
+ - [package]: Upgrade package.
45
+ - [camera]: Use the shared `addWebRtcTransportRequestorClient` helper from `clients.ts` instead of a local duplicate.
46
+ - [doorbell]: Use the shared `addChimeClient` helper from `clients.ts` instead of inline binding code.
47
+ - [devices]: `DoorbellOptions`, `AudioDoorbellOptions`, `ChimeOptions`, `CameraOptions`, and `SnapshotCameraOptions` now extend `MatterbridgeEndpointOptions`, forwarding `id`/`number`/`tagList`/`mode` to the underlying `MatterbridgeEndpoint` (`id` defaults to `${name}-${serial}` when not provided), and document the default value of each `identifyTime`/`identifyType`/`powerSourceType` option in JSDoc.
48
+ - [module]: Register the `AudioDoorbell` example device in `onStart` and verify it's registered in `onConfigure`, alongside the existing `Chime`, `Doorbell`, `SnapshotCamera`, and `Camera` example devices.
49
+ - [tests]: Add `vitest/module.test.ts` coverage for the `AudioDoorbell` and `Camera` "device not registered" `onConfigure` error paths, and for the `animationInterval` configuration option (periodic `animationHandler` execution, phase wraparound, and interval cleanup on shutdown).
50
+
51
+ <a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="80"></a>
52
+
31
53
  ## [0.0.4] - 2026-07-19
32
54
 
33
55
  ### Added
package/README.md CHANGED
@@ -77,6 +77,18 @@ Features:
77
77
  - Optional Identify cluster support, with configurable identify time and type. Set to Identify.IdentifyType.None to omit the cluster entirely.
78
78
  - Configurable Power Source cluster type: Rechargeable, Replaceable, Battery, Wired, or None to omit the Power Source cluster entirely.
79
79
 
80
+ ### Audio Doorbell
81
+
82
+ Features:
83
+
84
+ - Exposes the Switch cluster with the MomentarySwitch feature only, as required by the Matter specification for this device type.
85
+ - Exposes the Camera AV Stream Management cluster with the Audio feature only (the Video and Snapshot features are not present, per the Matter specification for this device type; see Camera for a device implementing those).
86
+ - Exposes the WebRtcTransportProvider cluster and registers a WebRtcTransportRequestor client, so a bound controller can solicit and receive WebRTC offers, same as Camera.
87
+ - Adds the required Chime client cluster automatically via `addChimeClient`, so a bound Chime device can be triggered when the doorbell button is pressed.
88
+ - Identify cluster is always created (it is a required server cluster for this device type), with configurable identify time and type.
89
+ - Configurable Power Source cluster type: Rechargeable, Replaceable, Battery, Wired, or None to omit the Power Source cluster entirely.
90
+ - 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`).
91
+
80
92
  ## WebRTC test video injection
81
93
 
82
94
  `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.
@@ -90,7 +102,7 @@ The video source defaults to a synthetic SMPTE bars test pattern, or can be swit
90
102
 
91
103
  A real client's resolution/quality picker (e.g. in Home Assistant) takes precedence over `MATTERBRIDGE_CAMERA_WEBCAM_RESOLUTION`: it allocates a video stream with `CameraAvStreamManagement.VideoStreamAllocate` before soliciting or providing a WebRTC offer, and `MatterbridgeWebRtcTransportProviderServer` looks up that stream's `maxResolution` to select the webcam capture resolution for the session. `MATTERBRIDGE_CAMERA_WEBCAM_RESOLUTION` is used when no matching allocated stream is found, or when the requested resolution isn't one of the three supported above.
92
104
 
93
- Requires `ffmpeg` to be installed and reachable on `PATH` (or under `/usr/bin`, `/bin`, or `/usr/local/bin`).
105
+ Requires `ffmpeg` to be installed. The resolver first tries `PATH`, then `/usr/bin/ffmpeg`, `/bin/ffmpeg`, and `/usr/local/bin/ffmpeg`. On Windows it also checks winget/Gyan installs under `%LOCALAPPDATA%\Microsoft\WinGet\Packages\Gyan.FFmpeg_*\ffmpeg-*\bin\ffmpeg.exe`, plus `%ProgramFiles%\ffmpeg\bin\ffmpeg.exe`, `%ProgramFiles%\Gyan\FFmpeg\bin\ffmpeg.exe`, `%ProgramFiles(x86)%\ffmpeg\bin\ffmpeg.exe`, and `%ProgramFiles(x86)%\Gyan\FFmpeg\bin\ffmpeg.exe`.
94
106
 
95
107
  Example, capturing from a real Linux webcam at 720p:
96
108
 
@@ -145,9 +157,20 @@ The `assets` directory contains deterministic three-second media fixtures for ex
145
157
  - `test-video.h264`: raw H.264 Constrained Baseline video, 640×360 at 15 FPS, with a moving test pattern. Use this elementary stream when implementing H.264 NAL-unit parsing and RTP packetization.
146
158
  - `test-audio.opus`: Ogg container with mono Opus audio at 48 kHz and 64 kbit/s, containing a 1 kHz test tone. Use the Opus packets for an audio RTP track; the Ogg container itself is not sent over WebRTC.
147
159
  - `test-camera.mp4`: playable reference containing the same 640×360 H.264 test pattern and a mono 1 kHz AAC track. The werift test transfers the complete file over its SCTP data channel and verifies its integrity. This exercises binary file transport, not a WebRTC video RTP track.
148
- - `camera-color-test-1920-1080.jpeg`: 1920×1080 broadcast-style snapshot calibration card returned by the example's `CaptureSnapshot` command. It contains color bars, grayscale references, geometry targets, focus patterns, safe-area guides, and near-black/near-white patches for inspecting hue, saturation, brightness, contrast, geometry, overscan, and focus.
149
- - `camera-color-test-1280-720.jpeg`: 1280×720 SMPTE color-bars test pattern (mire) returned by the example's `CaptureSnapshot` command, generated with `ffmpeg -f lavfi -i smptebars=size=1280x720`.
150
- - `camera-color-test-640-480.jpeg`: 640×480 SMPTE color-bars test pattern (mire) returned by the example's `CaptureSnapshot` command, generated with `ffmpeg -f lavfi -i smptebars=size=640x480`.
160
+ - `camera-color-1920-1080.jpeg`: 1920×1080 simplified ffmpeg-generated color-rectangle snapshot returned by the example's `CaptureSnapshot` command.
161
+ - `camera-color-1280-720.jpeg`: 1280×720 simplified ffmpeg-generated color-rectangle snapshot returned by the example's `CaptureSnapshot` command.
162
+ - `camera-color-640-480.jpeg`: 640×480 simplified ffmpeg-generated color-rectangle snapshot returned by the example's `CaptureSnapshot` command.
163
+ - `camera-color-test-1920-1080.jpeg`, `camera-color-test-1280-720.jpeg`, `camera-color-test-960-540.jpeg`, `camera-color-test-640-480.jpeg`, and `camera-color-test-480-270.jpeg`: additional SMPTE color-bars snapshot fixtures.
164
+
165
+ #### Why the snapshot calibration cards stay under ~64 KB
166
+
167
+ All three calibration cards above are kept well under the Matter message size ceiling, which caps at **65535 bytes** for a single message and cannot be worked around by tuning TCP:
168
+
169
+ - Every Matter message is encrypted with AES-128-CCM, using a 13-byte nonce built from the security flags, message counter, and node ID (`Session.generateNonce`, part of the Matter message-security spec, not a matter.js choice).
170
+ - AES-CCM (RFC 3610 / NIST SP 800-38C) requires the nonce length `N` and the length-field size `L` to satisfy `N + L = 15` bytes for a 128-bit block cipher. With `N = 13`, that leaves `L = 2`.
171
+ - A 2-byte length field caps the plaintext of a single CCM-encrypted message at `2^16 - 1 = 65535` bytes — a cryptographic ceiling, not a networking one. matter.js's `DEFAULT_MAX_TCP_MESSAGE_SIZE` (64000) is just a round number kept safely under that limit.
172
+
173
+ 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.
151
174
 
152
175
  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`.
153
176
 
@@ -0,0 +1,24 @@
1
+ import { MatterbridgeBindingServer } from 'matterbridge/behaviors';
2
+ import { ChimeClient, WebRtcTransportRequestorClient } from 'matterbridge/matter/behaviors';
3
+ import { Chime, WebRtcTransportRequestor } from 'matterbridge/matter/clusters';
4
+ function addBindingClientListEntry(endpoint, clusterId) {
5
+ if (endpoint.behaviors.has(MatterbridgeBindingServer)) {
6
+ const existing = endpoint.behaviors.optionsFor(MatterbridgeBindingServer)?.clientList ?? [];
7
+ if (!existing.includes(clusterId)) {
8
+ endpoint.behaviors.inject(MatterbridgeBindingServer, { clientList: [...existing, clusterId] });
9
+ }
10
+ }
11
+ else {
12
+ endpoint.behaviors.require(MatterbridgeBindingServer, { clientList: [clusterId] });
13
+ }
14
+ }
15
+ export function addChimeClient(endpoint) {
16
+ addBindingClientListEntry(endpoint, Chime.id);
17
+ endpoint.type.clientClusters.chime ??= ChimeClient;
18
+ return endpoint;
19
+ }
20
+ export function addWebRtcTransportRequestorClient(endpoint) {
21
+ addBindingClientListEntry(endpoint, WebRtcTransportRequestor.id);
22
+ endpoint.type.clientClusters.webRtcTransportRequestor ??= WebRtcTransportRequestorClient;
23
+ return endpoint;
24
+ }
@@ -1,7 +1,6 @@
1
- import { MatterbridgeBindingServer, MatterbridgeServer } from 'matterbridge/behaviors';
1
+ import { MatterbridgeServer } from 'matterbridge/behaviors';
2
2
  import { Node } from 'matterbridge/matter';
3
3
  import { WebRtcTransportProviderServer, WebRtcTransportRequestorClient } from 'matterbridge/matter/behaviors';
4
- import { WebRtcTransportRequestor } from 'matterbridge/matter/clusters';
5
4
  import { EndpointNumber, FabricIndex, NodeId, StreamUsage, Status, StatusResponseError } from 'matterbridge/matter/types';
6
5
  import { WeriftWebRtcSession } from '../webrtc/weriftSession.js';
7
6
  import { MatterbridgeCameraAvStreamManagementServer } from './cameraAvStreamManagementServer.js';
@@ -260,17 +259,3 @@ export function createDefaultWebRtcTransportProviderClusterServer(endpoint) {
260
259
  endpoint.behaviors.require(MatterbridgeWebRtcTransportProviderServer, { currentSessions: [] });
261
260
  return endpoint;
262
261
  }
263
- export function addWebRtcTransportRequestorClient(endpoint) {
264
- if (endpoint.behaviors.has(MatterbridgeBindingServer)) {
265
- const existing = endpoint.behaviors.optionsFor(MatterbridgeBindingServer)?.clientList ?? [];
266
- if (!existing.includes(WebRtcTransportRequestor.id)) {
267
- endpoint.behaviors.inject(MatterbridgeBindingServer, { clientList: [...existing, WebRtcTransportRequestor.id] });
268
- }
269
- }
270
- else {
271
- endpoint.behaviors.require(MatterbridgeBindingServer, { clientList: [WebRtcTransportRequestor.id] });
272
- }
273
- const clientClusters = endpoint.type.clientClusters;
274
- clientClusters.webRtcTransportRequestor ??= WebRtcTransportRequestorClient;
275
- return endpoint;
276
- }
@@ -0,0 +1,64 @@
1
+ import { audioDoorbell, 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, addWebRtcTransportRequestorClient } from '../behaviors/clients.js';
6
+ import { createDefaultWebRtcTransportProviderClusterServer } from '../behaviors/webRtcTransportProviderServer.js';
7
+ export class AudioDoorbell extends MatterbridgeEndpoint {
8
+ constructor(name, serial, options = {}) {
9
+ 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] }, id, number, tagList, mode, } = options;
10
+ super(powerSourceType === 'None' ? [audioDoorbell] : [audioDoorbell, powerSource], {
11
+ id: id ?? `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}`,
12
+ number,
13
+ tagList,
14
+ mode,
15
+ });
16
+ this.createDefaultIdentifyClusterServer(identifyTime, identifyType);
17
+ this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Matterbridge Audio Doorbell');
18
+ switch (powerSourceType) {
19
+ case 'Rechargeable':
20
+ this.createDefaultPowerSourceRechargeableBatteryClusterServer();
21
+ break;
22
+ case 'Replaceable':
23
+ this.createDefaultPowerSourceReplaceableBatteryClusterServer();
24
+ break;
25
+ case 'Battery':
26
+ this.createDefaultPowerSourceBatteryClusterServer();
27
+ break;
28
+ case 'Wired':
29
+ this.createDefaultPowerSourceWiredClusterServer();
30
+ break;
31
+ case 'None':
32
+ break;
33
+ }
34
+ this.createDefaultMomentarySwitchClusterServer();
35
+ createDefaultAudioCameraAvStreamManagementClusterServer(this, {
36
+ maxContentBufferSize,
37
+ maxNetworkBandwidth,
38
+ supportedStreamUsages,
39
+ streamUsagePriorities,
40
+ microphoneCapabilities,
41
+ });
42
+ createDefaultWebRtcTransportProviderClusterServer(this);
43
+ addChimeClient(this);
44
+ addWebRtcTransportRequestorClient(this);
45
+ this.addRequiredClusters();
46
+ }
47
+ }
48
+ export function createDefaultAudioCameraAvStreamManagementClusterServer(endpoint, options) {
49
+ endpoint.behaviors.require(MatterbridgeCameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Audio, CameraAvStreamManagement.Feature.ImageControl), {
50
+ ...options,
51
+ hardPrivacyModeOn: false,
52
+ statusLightEnabled: false,
53
+ allocatedAudioStreams: [],
54
+ microphoneMuted: false,
55
+ microphoneVolumeLevel: 128,
56
+ microphoneMaxLevel: 254,
57
+ microphoneMinLevel: 0,
58
+ microphoneAgcEnabled: false,
59
+ imageRotation: 0,
60
+ imageFlipVertical: false,
61
+ imageFlipHorizontal: false,
62
+ });
63
+ return endpoint;
64
+ }
@@ -1,9 +1,8 @@
1
1
  import { camera, MatterbridgeEndpoint, powerSource } from 'matterbridge';
2
- import { MatterbridgeBindingServer } from 'matterbridge/behaviors';
3
- import { WebRtcTransportRequestorClient } from 'matterbridge/matter/behaviors';
4
- import { CameraAvStreamManagement, Identify, WebRtcTransportRequestor } from 'matterbridge/matter/clusters';
2
+ import { CameraAvStreamManagement, Identify } from 'matterbridge/matter/clusters';
5
3
  import { StreamUsage, ThreeLevelAuto } from 'matterbridge/matter/types';
6
4
  import { MatterbridgeCameraAvStreamManagementServer } from '../behaviors/cameraAvStreamManagementServer.js';
5
+ import { addWebRtcTransportRequestorClient } from '../behaviors/clients.js';
7
6
  import { MatterbridgeWebRtcTransportProviderServer } from '../behaviors/webRtcTransportProviderServer.js';
8
7
  export class Camera extends MatterbridgeEndpoint {
9
8
  constructor(name, serial, options = {}) {
@@ -11,8 +10,8 @@ export class Camera extends MatterbridgeEndpoint {
11
10
  { resolution: { width: 640, height: 480 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
12
11
  { resolution: { width: 1280, height: 720 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
13
12
  { resolution: { width: 1920, height: 1080 }, maxFrameRate: 10, imageCodec: CameraAvStreamManagement.ImageCodec.Jpeg, requiresEncodedPixels: false },
14
- ], allocatedSnapshotStreams = [], } = options;
15
- super(powerSourceType === 'None' ? [camera] : [camera, powerSource], { id: `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}` });
13
+ ], allocatedSnapshotStreams = [], id, number, tagList, mode, } = options;
14
+ super(powerSourceType === 'None' ? [camera] : [camera, powerSource], { id: id ?? `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}`, number, tagList, mode });
16
15
  if (identifyType !== Identify.IdentifyType.None) {
17
16
  this.createDefaultIdentifyClusterServer(identifyTime, identifyType);
18
17
  }
@@ -78,8 +77,3 @@ export function createDefaultWebRtcTransportProviderClusterServer(endpoint) {
78
77
  endpoint.behaviors.require(MatterbridgeWebRtcTransportProviderServer, { currentSessions: [] });
79
78
  return endpoint;
80
79
  }
81
- export function addWebRtcTransportRequestorClient(endpoint) {
82
- endpoint.behaviors.require(MatterbridgeBindingServer, { clientList: [WebRtcTransportRequestor.id] });
83
- endpoint.type.clientClusters['webRtcTransportRequestor'] ??= WebRtcTransportRequestorClient;
84
- return endpoint;
85
- }
@@ -8,8 +8,8 @@ export class Chime extends MatterbridgeEndpoint {
8
8
  chimeId: 0,
9
9
  name: 'Default Chime',
10
10
  },
11
- ], selectedChime = 0, enabled = true, } = options;
12
- super(powerSourceType === 'None' ? [chime] : [chime, powerSource], { id: `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}` });
11
+ ], selectedChime = 0, enabled = true, id, number, tagList, mode, } = options;
12
+ super(powerSourceType === 'None' ? [chime] : [chime, powerSource], { id: id ?? `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}`, number, tagList, mode });
13
13
  if (identifyType !== Identify.IdentifyType.None) {
14
14
  this.createDefaultIdentifyClusterServer(identifyTime, identifyType);
15
15
  }
@@ -1,11 +1,10 @@
1
1
  import { doorbell, MatterbridgeEndpoint, powerSource } from 'matterbridge';
2
- import { MatterbridgeBindingServer } from 'matterbridge/behaviors';
3
- import { ChimeClient } from 'matterbridge/matter/behaviors';
4
- import { Chime, Identify } from 'matterbridge/matter/clusters';
2
+ import { Identify } from 'matterbridge/matter/clusters';
3
+ import { addChimeClient } from '../behaviors/clients.js';
5
4
  export class Doorbell extends MatterbridgeEndpoint {
6
5
  constructor(name, serial, options = {}) {
7
- const { identifyTime = 0, identifyType = Identify.IdentifyType.None, powerSourceType = 'Wired' } = options;
8
- super(powerSourceType === 'None' ? [doorbell] : [doorbell, powerSource], { id: `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}` });
6
+ const { identifyTime = 0, identifyType = Identify.IdentifyType.None, powerSourceType = 'Wired', id, number, tagList, mode } = options;
7
+ super(powerSourceType === 'None' ? [doorbell] : [doorbell, powerSource], { id: id ?? `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}`, number, tagList, mode });
9
8
  this.createDefaultIdentifyClusterServer(identifyTime, identifyType);
10
9
  this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Matterbridge Doorbell');
11
10
  switch (powerSourceType) {
@@ -25,8 +24,7 @@ export class Doorbell extends MatterbridgeEndpoint {
25
24
  break;
26
25
  }
27
26
  this.createDefaultMomentarySwitchClusterServer();
28
- this.behaviors.require(MatterbridgeBindingServer, { clientList: [Chime.id] });
29
- this.type.clientClusters['chime'] ??= ChimeClient;
27
+ addChimeClient(this);
30
28
  this.addRequiredClusters();
31
29
  }
32
30
  }
@@ -8,8 +8,13 @@ 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], } = options;
12
- super(powerSourceType === 'None' ? [snapshotCamera] : [snapshotCamera, powerSource], { id: `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}` });
11
+ ], maxNetworkBandwidth = 10000, supportedStreamUsages = [StreamUsage.Recording], allocatedSnapshotStreams = [], streamUsagePriorities = [StreamUsage.Recording], id, number, tagList, mode, } = options;
12
+ super(powerSourceType === 'None' ? [snapshotCamera] : [snapshotCamera, powerSource], {
13
+ id: id ?? `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}`,
14
+ number,
15
+ tagList,
16
+ mode,
17
+ });
13
18
  if (identifyType !== Identify.IdentifyType.None) {
14
19
  this.createDefaultIdentifyClusterServer(identifyTime, identifyType);
15
20
  }
package/dist/module.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import './patches/objectSchemaInjectFieldFix.js';
2
2
  import { MatterbridgeDynamicPlatform } from 'matterbridge';
3
3
  import { Identify, Chime as ChimeCluster, PowerSource } from 'matterbridge/matter/clusters';
4
+ import { AudioDoorbell } from './devices/audioDoorbell.js';
4
5
  import { Camera } from './devices/camera.js';
5
6
  import { Chime } from './devices/chime.js';
6
7
  import { Doorbell } from './devices/doorbell.js';
@@ -9,8 +10,12 @@ export default function initializePlugin(matterbridge, log, config) {
9
10
  return new ExampleMatterbridgeCameraPlatform(matterbridge, log, config);
10
11
  }
11
12
  export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatform {
13
+ config;
14
+ animationPhase = 0;
15
+ animationInterval;
12
16
  constructor(matterbridge, log, config) {
13
17
  super(matterbridge, log, config);
18
+ this.config = config;
14
19
  if (typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('3.10.0')) {
15
20
  throw new Error(`This plugin requires Matterbridge version >= "3.10.0". Please update Matterbridge to the latest version in the frontend.`);
16
21
  }
@@ -38,7 +43,13 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
38
43
  powerSourceType: 'Replaceable',
39
44
  });
40
45
  await this.registerDevice(exampleDoorbell);
41
- const exampleSnapshotCamera = new SnapshotCamera('Snapshot Camera', 'SNAPSHOT-001', {
46
+ const exampleAudioDoorbell = new AudioDoorbell('Audio Doorbell', 'AUDIODOORBELL-001', {
47
+ identifyTime: 5,
48
+ identifyType: Identify.IdentifyType.VisibleIndicator,
49
+ powerSourceType: 'Replaceable',
50
+ });
51
+ await this.registerDevice(exampleAudioDoorbell);
52
+ const exampleSnapshotCamera = new SnapshotCamera('Snapshot Camera', 'SNAPSHOTCAMERA-001', {
42
53
  identifyTime: 5,
43
54
  identifyType: Identify.IdentifyType.VisibleIndicator,
44
55
  powerSourceType: 'Wired',
@@ -46,6 +57,10 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
46
57
  await this.registerDevice(exampleSnapshotCamera);
47
58
  const exampleCamera = new Camera('Camera', 'CAMERA-001');
48
59
  await this.registerDevice(exampleCamera);
60
+ const serverChime = new Chime('Server Chime', 'SERVER-CHIME-001', { mode: 'server' });
61
+ await this.registerDevice(serverChime);
62
+ const serverDoorbell = new Doorbell('Server Doorbell', 'SERVER-DOORBELL-001', { mode: 'server' });
63
+ await this.registerDevice(serverDoorbell);
49
64
  this.log.info(`Platform ${this.config.name} started successfully`);
50
65
  }
51
66
  async onConfigure() {
@@ -59,14 +74,31 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
59
74
  const exampleDoorbell = this.getDeviceById('Doorbell-DOORBELL-001');
60
75
  if (!exampleDoorbell)
61
76
  throw new Error(`Doorbell device not found. Please ensure the device is registered before configuration.`);
62
- const exampleSnapshotCamera = this.getDeviceById('SnapshotCamera-SNAPSHOT-001');
77
+ const exampleAudioDoorbell = this.getDeviceById('AudioDoorbell-AUDIODOORBELL-001');
78
+ if (!exampleAudioDoorbell)
79
+ throw new Error(`Audio doorbell device not found. Please ensure the device is registered before configuration.`);
80
+ const exampleSnapshotCamera = this.getDeviceById('SnapshotCamera-SNAPSHOTCAMERA-001');
63
81
  if (!exampleSnapshotCamera)
64
82
  throw new Error(`Snapshot camera device not found. Please ensure the device is registered before configuration.`);
83
+ const exampleCamera = this.getDeviceById('Camera-CAMERA-001');
84
+ if (!exampleCamera)
85
+ throw new Error(`Camera device not found. Please ensure the device is registered before configuration.`);
86
+ if (this.config.animationInterval > 0) {
87
+ clearInterval(this.animationInterval);
88
+ this.animationInterval = setInterval(() => void this.animationHandler(), this.config.animationInterval * 1000);
89
+ }
65
90
  this.log.info(`Platform ${this.config.name} configured successfully`);
66
91
  }
92
+ async animationHandler() {
93
+ this.animationPhase = this.animationPhase + 1;
94
+ this.animationPhase = this.animationPhase > 10 ? 0 : this.animationPhase;
95
+ this.log.info(`Platform ${this.config.name} animation phase: ${this.animationPhase}`);
96
+ }
67
97
  async onShutdown(reason) {
68
98
  await super.onShutdown(reason);
69
99
  this.log.info(`Shutting down platform ${this.config.name} with reason: ${reason ?? 'No reason provided'}...`);
100
+ clearInterval(this.animationInterval);
101
+ this.animationInterval = undefined;
70
102
  if (this.config.unregisterOnShutdown)
71
103
  await this.unregisterAllDevices();
72
104
  this.log.info(`Platform ${this.config.name} shut down successfully`);
@@ -1,8 +1,9 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { createSocket } from 'node:dgram';
3
3
  import { constants } from 'node:fs';
4
- import { access } from 'node:fs/promises';
5
- import { RTCPeerConnection, RTCRtpCodecParameters } from 'werift';
4
+ import { access, readdir } from 'node:fs/promises';
5
+ import path from 'node:path';
6
+ import { RTCPeerConnection, RTCRtpCodecParameters, useH264, useOPUS, usePCMU, useVP8 } from 'werift';
6
7
  import { navigator } from 'werift/nonstandard';
7
8
  export class WeriftWebRtcSession {
8
9
  peerConnection;
@@ -12,7 +13,7 @@ export class WeriftWebRtcSession {
12
13
  testVideoUdpDisposer;
13
14
  testVideoAttached = false;
14
15
  constructor(logger, label = 'WebRTC session') {
15
- this.peerConnection = new RTCPeerConnection();
16
+ this.peerConnection = new RTCPeerConnection({ codecs: { audio: [useOPUS(), usePCMU()], video: [useVP8(), useH264()] } });
16
17
  this.logger = logger;
17
18
  this.label = label;
18
19
  this.log('debug', 'Created RTCPeerConnection');
@@ -52,8 +53,43 @@ export class WeriftWebRtcSession {
52
53
  }
53
54
  return false;
54
55
  }
56
+ async getWindowsCommandCandidates(command) {
57
+ if (process.platform !== 'win32')
58
+ return [];
59
+ const commandName = command.toLowerCase().replace(/\.exe$/, '');
60
+ const executable = command.toLowerCase().endsWith('.exe') ? command : `${command}.exe`;
61
+ const candidates = [];
62
+ if (commandName === 'ffmpeg' && process.env.LOCALAPPDATA) {
63
+ const wingetPackages = path.join(process.env.LOCALAPPDATA, 'Microsoft', 'WinGet', 'Packages');
64
+ try {
65
+ const packageDirs = await readdir(wingetPackages, { withFileTypes: true });
66
+ for (const packageDir of packageDirs) {
67
+ if (!packageDir.isDirectory() || !packageDir.name.startsWith('Gyan.FFmpeg_'))
68
+ continue;
69
+ const packagePath = path.join(wingetPackages, packageDir.name);
70
+ try {
71
+ const versionDirs = await readdir(packagePath, { withFileTypes: true });
72
+ for (const versionDir of versionDirs) {
73
+ if (versionDir.isDirectory() && versionDir.name.startsWith('ffmpeg-'))
74
+ candidates.push(path.join(packagePath, versionDir.name, 'bin', executable));
75
+ }
76
+ }
77
+ catch {
78
+ }
79
+ }
80
+ }
81
+ catch {
82
+ }
83
+ }
84
+ for (const programFiles of [process.env.ProgramFiles, process.env['ProgramFiles(x86)']]) {
85
+ if (!programFiles)
86
+ continue;
87
+ candidates.push(path.join(programFiles, 'ffmpeg', 'bin', executable), path.join(programFiles, 'Gyan', 'FFmpeg', 'bin', executable));
88
+ }
89
+ return candidates;
90
+ }
55
91
  async resolveCommand(command) {
56
- const candidates = [command, `/usr/bin/${command}`, `/bin/${command}`, `/usr/local/bin/${command}`];
92
+ const candidates = [command, `/usr/bin/${command}`, `/bin/${command}`, `/usr/local/bin/${command}`, ...(await this.getWindowsCommandCandidates(command))];
57
93
  for (const candidate of candidates) {
58
94
  if (candidate.includes('/')) {
59
95
  try {
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "matterbridge-example-camera",
3
+ "type": "DynamicPlatform",
4
+ "whiteList": [],
5
+ "blackList": [],
6
+ "animationInterval": 60,
7
+ "debug": false,
8
+ "unregisterOnShutdown": false
9
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "title": "Matterbridge example camera plugin",
3
+ "description": "matterbridge-example-camera v. 1.0.0 by https://github.com/Luligu",
4
+ "type": "object",
5
+ "required": [],
6
+ "properties": {
7
+ "name": {
8
+ "description": "Plugin Name",
9
+ "type": "string",
10
+ "readOnly": true,
11
+ "ui:widget": "hidden"
12
+ },
13
+ "type": {
14
+ "description": "Plugin Type",
15
+ "type": "string",
16
+ "readOnly": true,
17
+ "ui:widget": "hidden"
18
+ },
19
+ "whiteList": {
20
+ "title": "White List",
21
+ "description": "Only the devices in the list will be exposed. If the list is empty, all the devices will be exposed.",
22
+ "type": "array",
23
+ "items": {
24
+ "type": "string"
25
+ },
26
+ "uniqueItems": true,
27
+ "selectFrom": "name"
28
+ },
29
+ "blackList": {
30
+ "title": "Black List",
31
+ "description": "The devices in the list will not be exposed. If the list is empty, no devices will be excluded.",
32
+ "type": "array",
33
+ "items": {
34
+ "type": "string"
35
+ },
36
+ "uniqueItems": true,
37
+ "selectFrom": "name"
38
+ },
39
+ "animationInterval": {
40
+ "title": "Animation Interval",
41
+ "description": "Interval to refresh the devices (in seconds). Use 0 to disable the animation.",
42
+ "type": "number",
43
+ "default": 60
44
+ },
45
+ "debug": {
46
+ "title": "Enable Debug",
47
+ "description": "Enable the debug for the plugin (development only)",
48
+ "type": "boolean",
49
+ "default": false
50
+ },
51
+ "unregisterOnShutdown": {
52
+ "title": "Unregister On Shutdown",
53
+ "description": "Unregister all devices on shutdown (development only)",
54
+ "type": "boolean",
55
+ "default": false
56
+ }
57
+ }
58
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "matterbridge-example-camera",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "matterbridge-example-camera",
9
- "version": "0.0.4",
9
+ "version": "0.0.5",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "node-ansi-logger": "3.3.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matterbridge-example-camera",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Matterbridge camera example plugin",
5
5
  "author": "https://github.com/Luligu",
6
6
  "license": "Apache-2.0",