matterbridge-example-camera 0.0.2-dev-20260714-b39fe14 → 0.0.2-dev-20260714-3c75ee7

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
@@ -31,11 +31,12 @@ If you like this project and find it useful, please consider giving it a star on
31
31
 
32
32
  ### Breaking changes
33
33
 
34
- - [matterbridge]: Require Matterbrdige 3.9.5 (from 3.9.5-git-438aa9a).
34
+ - [matterbridge]: Require Matterbrdige 3.9.5 (from 3.9.5-git-623095608a9ab3f792c80e288cf236e0b5de878a).
35
35
  - [DevContainer]: Bump DevContainer config v.1.1.0. Rebuild the container.
36
36
 
37
37
  ### Added
38
38
 
39
+ - [doorbell]: Add the Doorbell device type with the required Identify, Switch (MomentarySwitch feature) and Chime client clusters, and Power Source support.
39
40
  - [chime]: Add validation in `MatterbridgeChimeServer.playChimeSound` to reject a `chimeId` that is not present in `installedChimeSounds` with a `NotFound` status response.
40
41
  - [snapshot camera]: Add the Snapshot Camera device with configurable snapshot capabilities, stream allocation, stream priorities, snapshot capture, Identify, and Power Source support.
41
42
  - [snapshot camera]: Add `MatterbridgeCameraAvStreamManagementServer` with the Snapshot and Image Control features.
package/README.md CHANGED
@@ -43,6 +43,16 @@ Features:
43
43
  - Optional Identify cluster support, with configurable identify time and type. Set to Identify.IdentifyType.None to omit the cluster entirely.
44
44
  - Configurable Power Source cluster type: Rechargeable, Replaceable, Battery, Wired, or None to omit the Power Source cluster entirely.
45
45
 
46
+ ### Doorbell
47
+
48
+ Features:
49
+
50
+ - Exposes the Switch cluster with the MomentarySwitch feature only, as required by the Matter specification for this device type.
51
+ - Adds the required Chime client cluster automatically via `addRequiredClusters()`, so a bound Chime device can be triggered when the doorbell button is pressed.
52
+ - Supports simulating a button press with `triggerSwitchEvent('Single', ...)`.
53
+ - Identify cluster is always created (it is a required server cluster for this device type), with configurable identify time and type.
54
+ - Configurable Power Source cluster type: Rechargeable, Replaceable, Battery, Wired, or None to omit the Power Source cluster entirely.
55
+
46
56
  ### Snapshot Camera
47
57
 
48
58
  Features:
@@ -2,7 +2,94 @@ import { MatterbridgeServer } from 'matterbridge/behaviors';
2
2
  import { CameraAvStreamManagementServer } from 'matterbridge/matter/behaviors';
3
3
  import { CameraAvStreamManagement } from 'matterbridge/matter/clusters';
4
4
  import { Status, StatusResponseError } from 'matterbridge/matter/types';
5
- export class MatterbridgeCameraAvStreamManagementServer extends CameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Snapshot, CameraAvStreamManagement.Feature.ImageControl) {
5
+ export class MatterbridgeCameraAvStreamManagementServer extends CameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Video, CameraAvStreamManagement.Feature.Audio, CameraAvStreamManagement.Feature.Snapshot, CameraAvStreamManagement.Feature.ImageControl) {
6
+ setStreamPriorities(request) {
7
+ const device = this.endpoint.stateOf(MatterbridgeServer);
8
+ if ((this.features.snapshot && this.state.allocatedSnapshotStreams.length > 0) ||
9
+ (this.features.video && this.state.allocatedVideoStreams.length > 0) ||
10
+ (this.features.audio && this.state.allocatedAudioStreams.length > 0)) {
11
+ throw new StatusResponseError('setStreamPriorities cannot be invoked while snapshot, video or audio streams are allocated', Status.InvalidInState);
12
+ }
13
+ if (!request.streamPriorities.every((usage) => this.state.supportedStreamUsages.includes(usage))) {
14
+ throw new StatusResponseError('streamPriorities shall only contain entries found in supportedStreamUsages', Status.DynamicConstraintError);
15
+ }
16
+ if (new Set(request.streamPriorities).size !== request.streamPriorities.length) {
17
+ throw new StatusResponseError('streamPriorities shall not contain duplicate values', Status.AlreadyExists);
18
+ }
19
+ device.log.info(`Setting stream priorities to [${request.streamPriorities.join(', ')}] (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
20
+ this.state.streamUsagePriorities = request.streamPriorities;
21
+ }
22
+ videoStreamAllocate(request) {
23
+ const device = this.endpoint.stateOf(MatterbridgeServer);
24
+ if (!this.state.supportedStreamUsages.includes(request.streamUsage)) {
25
+ throw new StatusResponseError(`Stream usage ${request.streamUsage} is not present in supportedStreamUsages`, Status.ConstraintError);
26
+ }
27
+ let videoStreamId = 0;
28
+ for (const stream of this.state.allocatedVideoStreams) {
29
+ videoStreamId = Math.max(videoStreamId, stream.videoStreamId + 1);
30
+ }
31
+ this.state.allocatedVideoStreams = [
32
+ ...this.state.allocatedVideoStreams,
33
+ {
34
+ videoStreamId,
35
+ streamUsage: request.streamUsage,
36
+ videoCodec: request.videoCodec,
37
+ minFrameRate: request.minFrameRate,
38
+ maxFrameRate: request.maxFrameRate,
39
+ minResolution: request.minResolution,
40
+ maxResolution: request.maxResolution,
41
+ minBitRate: request.minBitRate,
42
+ maxBitRate: request.maxBitRate,
43
+ keyFrameInterval: request.keyFrameInterval,
44
+ watermarkEnabled: request.watermarkEnabled,
45
+ osdEnabled: request.osdEnabled,
46
+ referenceCount: 0,
47
+ },
48
+ ];
49
+ device.log.info(`Allocated video stream ${videoStreamId} for usage ${request.streamUsage} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
50
+ return { videoStreamId };
51
+ }
52
+ videoStreamDeallocate(request) {
53
+ const device = this.endpoint.stateOf(MatterbridgeServer);
54
+ if (!this.state.allocatedVideoStreams.some((stream) => stream.videoStreamId === request.videoStreamId)) {
55
+ throw new StatusResponseError(`Video stream ${request.videoStreamId} is not present in allocatedVideoStreams`, Status.NotFound);
56
+ }
57
+ this.state.allocatedVideoStreams = this.state.allocatedVideoStreams.filter((stream) => stream.videoStreamId !== request.videoStreamId);
58
+ device.log.info(`Deallocated video stream ${request.videoStreamId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
59
+ }
60
+ audioStreamAllocate(request) {
61
+ const device = this.endpoint.stateOf(MatterbridgeServer);
62
+ if (!this.state.supportedStreamUsages.includes(request.streamUsage)) {
63
+ throw new StatusResponseError(`Stream usage ${request.streamUsage} is not present in supportedStreamUsages`, Status.ConstraintError);
64
+ }
65
+ let audioStreamId = 0;
66
+ for (const stream of this.state.allocatedAudioStreams) {
67
+ audioStreamId = Math.max(audioStreamId, stream.audioStreamId + 1);
68
+ }
69
+ this.state.allocatedAudioStreams = [
70
+ ...this.state.allocatedAudioStreams,
71
+ {
72
+ audioStreamId,
73
+ streamUsage: request.streamUsage,
74
+ audioCodec: request.audioCodec,
75
+ channelCount: request.channelCount,
76
+ sampleRate: request.sampleRate,
77
+ bitRate: request.bitRate,
78
+ bitDepth: request.bitDepth,
79
+ referenceCount: 0,
80
+ },
81
+ ];
82
+ device.log.info(`Allocated audio stream ${audioStreamId} for usage ${request.streamUsage} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
83
+ return { audioStreamId };
84
+ }
85
+ audioStreamDeallocate(request) {
86
+ const device = this.endpoint.stateOf(MatterbridgeServer);
87
+ if (!this.state.allocatedAudioStreams.some((stream) => stream.audioStreamId === request.audioStreamId)) {
88
+ throw new StatusResponseError(`Audio stream ${request.audioStreamId} is not present in allocatedAudioStreams`, Status.NotFound);
89
+ }
90
+ this.state.allocatedAudioStreams = this.state.allocatedAudioStreams.filter((stream) => stream.audioStreamId !== request.audioStreamId);
91
+ device.log.info(`Deallocated audio stream ${request.audioStreamId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
92
+ }
6
93
  async snapshotStreamAllocate(request) {
7
94
  const device = this.endpoint.stateOf(MatterbridgeServer);
8
95
  let snapshotStreamId = 0;
@@ -46,9 +133,4 @@ export class MatterbridgeCameraAvStreamManagementServer extends CameraAvStreamMa
46
133
  resolution: request.requestedResolution,
47
134
  };
48
135
  }
49
- async setStreamPriorities(request) {
50
- const device = this.endpoint.stateOf(MatterbridgeServer);
51
- device.log.info(`Setting stream priorities to ${request.streamPriorities.join(', ')} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
52
- this.state.streamUsagePriorities = request.streamPriorities;
53
- }
54
136
  }
@@ -0,0 +1,114 @@
1
+ import { MatterbridgeBindingServer, MatterbridgeServer } from 'matterbridge/behaviors';
2
+ import { WebRtcTransportProviderServer, WebRtcTransportRequestorClient } from 'matterbridge/matter/behaviors';
3
+ import { WebRtcTransportRequestor } from 'matterbridge/matter/clusters';
4
+ import { EndpointNumber, FabricIndex, NodeId, StreamUsage, Status, StatusResponseError } from 'matterbridge/matter/types';
5
+ const MOCK_SDP_OFFER = 'v=0\r\no=- 0 0 IN IP4 0.0.0.0\r\ns=-\r\nt=0 0\r\n';
6
+ export class MatterbridgeWebRtcTransportProviderServer extends WebRtcTransportProviderServer {
7
+ #getPeerInfo() {
8
+ const session = this.context.session;
9
+ return {
10
+ peerNodeId: session?.peerNodeId ?? NodeId(0),
11
+ fabricIndex: session?.fabric?.fabricIndex ?? FabricIndex(1),
12
+ };
13
+ }
14
+ #resolveStreamLists(request) {
15
+ return {
16
+ videoStreams: request.videoStreams ?? (request.videoStreamId !== undefined && request.videoStreamId !== null ? [request.videoStreamId] : undefined),
17
+ audioStreams: request.audioStreams ?? (request.audioStreamId !== undefined && request.audioStreamId !== null ? [request.audioStreamId] : undefined),
18
+ };
19
+ }
20
+ async solicitOffer(request) {
21
+ const { videoStreams, audioStreams } = this.#resolveStreamLists(request);
22
+ if (!videoStreams?.length && !audioStreams?.length) {
23
+ throw new StatusResponseError('solicitOffer requires at least one of videoStreams or audioStreams; automatic stream assignment is not implemented', Status.ConstraintError);
24
+ }
25
+ const device = this.endpoint.stateOf(MatterbridgeServer);
26
+ let webRtcSessionId = 0;
27
+ for (const session of this.state.currentSessions) {
28
+ webRtcSessionId = Math.max(webRtcSessionId, session.id + 1);
29
+ }
30
+ const { peerNodeId, fabricIndex } = this.#getPeerInfo();
31
+ this.state.currentSessions = [
32
+ ...this.state.currentSessions,
33
+ {
34
+ id: webRtcSessionId,
35
+ peerNodeId,
36
+ peerEndpointId: request.originatingEndpointId,
37
+ streamUsage: request.streamUsage,
38
+ metadataEnabled: request.metadataEnabled ?? false,
39
+ videoStreams,
40
+ audioStreams,
41
+ fabricIndex,
42
+ },
43
+ ];
44
+ device.log.info(`Solicited a WebRTC offer for session ${webRtcSessionId} (stream usage ${request.streamUsage}) (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
45
+ const requestorEndpoint = this.endpoint.behaviors.has(MatterbridgeBindingServer)
46
+ ? this.agent.get(MatterbridgeBindingServer).getEndpoint(WebRtcTransportRequestor.id)
47
+ : undefined;
48
+ if (requestorEndpoint) {
49
+ await requestorEndpoint.act((agent) => agent.get(WebRtcTransportRequestorClient).offer({ webRtcSessionId, sdp: MOCK_SDP_OFFER }));
50
+ device.log.info(`Invoked Offer on the bound WebRtcTransportRequestor for session ${webRtcSessionId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
51
+ }
52
+ else {
53
+ device.log.info(`No WebRtcTransportRequestor is bound yet; the Offer for session ${webRtcSessionId} was not sent (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
54
+ }
55
+ return { webRtcSessionId, deferredOffer: true };
56
+ }
57
+ provideOffer(request) {
58
+ const device = this.endpoint.stateOf(MatterbridgeServer);
59
+ let webRtcSessionId = request.webRtcSessionId;
60
+ if (webRtcSessionId === null) {
61
+ const { videoStreams, audioStreams } = this.#resolveStreamLists(request);
62
+ if (!videoStreams?.length && !audioStreams?.length) {
63
+ throw new StatusResponseError('provideOffer requires at least one of videoStreams or audioStreams; automatic stream assignment is not implemented', Status.ConstraintError);
64
+ }
65
+ webRtcSessionId = 0;
66
+ for (const session of this.state.currentSessions) {
67
+ webRtcSessionId = Math.max(webRtcSessionId, session.id + 1);
68
+ }
69
+ const { peerNodeId, fabricIndex } = this.#getPeerInfo();
70
+ this.state.currentSessions = [
71
+ ...this.state.currentSessions,
72
+ {
73
+ id: webRtcSessionId,
74
+ peerNodeId,
75
+ peerEndpointId: request.originatingEndpointId ?? EndpointNumber(0),
76
+ streamUsage: request.streamUsage ?? StreamUsage.LiveView,
77
+ metadataEnabled: request.metadataEnabled ?? false,
78
+ videoStreams,
79
+ audioStreams,
80
+ fabricIndex,
81
+ },
82
+ ];
83
+ }
84
+ else if (!this.state.currentSessions.some((session) => session.id === webRtcSessionId)) {
85
+ throw new StatusResponseError(`WebRTC session ${webRtcSessionId} is not present in currentSessions`, Status.NotFound);
86
+ }
87
+ device.log.info(`Received an SDP offer for session ${webRtcSessionId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
88
+ device.log.debug(`MatterbridgeWebRtcTransportProviderServer: received SDP offer for session ${webRtcSessionId}: ${request.sdp}`);
89
+ return { webRtcSessionId };
90
+ }
91
+ provideAnswer(request) {
92
+ const device = this.endpoint.stateOf(MatterbridgeServer);
93
+ if (!this.state.currentSessions.some((session) => session.id === request.webRtcSessionId)) {
94
+ throw new StatusResponseError(`WebRTC session ${request.webRtcSessionId} is not present in currentSessions`, Status.NotFound);
95
+ }
96
+ device.log.info(`Received an SDP answer for session ${request.webRtcSessionId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
97
+ device.log.debug(`MatterbridgeWebRtcTransportProviderServer: received SDP answer for session ${request.webRtcSessionId}: ${request.sdp}`);
98
+ }
99
+ provideIceCandidates(request) {
100
+ const device = this.endpoint.stateOf(MatterbridgeServer);
101
+ if (!this.state.currentSessions.some((session) => session.id === request.webRtcSessionId)) {
102
+ throw new StatusResponseError(`WebRTC session ${request.webRtcSessionId} is not present in currentSessions`, Status.NotFound);
103
+ }
104
+ device.log.info(`Received ${request.iceCandidates.length} ICE candidate(s) for session ${request.webRtcSessionId} (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
105
+ }
106
+ endSession(request) {
107
+ const device = this.endpoint.stateOf(MatterbridgeServer);
108
+ if (!this.state.currentSessions.some((session) => session.id === request.webRtcSessionId)) {
109
+ throw new StatusResponseError(`WebRTC session ${request.webRtcSessionId} is not present in currentSessions`, Status.NotFound);
110
+ }
111
+ this.state.currentSessions = this.state.currentSessions.filter((session) => session.id !== request.webRtcSessionId);
112
+ device.log.info(`Ended WebRTC session ${request.webRtcSessionId} (reason ${request.reason}) (endpoint ${this.endpoint.maybeId}.${this.endpoint.maybeNumber})`);
113
+ }
114
+ }
@@ -0,0 +1,79 @@
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';
5
+ import { StreamUsage, ThreeLevelAuto } from 'matterbridge/matter/types';
6
+ import { MatterbridgeCameraAvStreamManagementServer } from '../behaviors/cameraAvStreamManagementServer.js';
7
+ import { MatterbridgeWebRtcTransportProviderServer } from '../behaviors/webRtcTransportProviderServer.js';
8
+ export class Camera extends MatterbridgeEndpoint {
9
+ constructor(name, serial, options = {}) {
10
+ const { identifyTime = 0, identifyType = Identify.IdentifyType.None, powerSourceType = 'Wired', 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] }, } = options;
11
+ super(powerSourceType === 'None' ? [camera] : [camera, powerSource], { id: `${name.replaceAll(' ', '')}-${serial.replaceAll(' ', '')}` });
12
+ if (identifyType !== Identify.IdentifyType.None) {
13
+ this.createDefaultIdentifyClusterServer(identifyTime, identifyType);
14
+ }
15
+ this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Matterbridge Chime');
16
+ switch (powerSourceType) {
17
+ case 'Rechargeable':
18
+ this.createDefaultPowerSourceRechargeableBatteryClusterServer();
19
+ break;
20
+ case 'Replaceable':
21
+ this.createDefaultPowerSourceReplaceableBatteryClusterServer();
22
+ break;
23
+ case 'Battery':
24
+ this.createDefaultPowerSourceBatteryClusterServer();
25
+ break;
26
+ case 'Wired':
27
+ this.createDefaultPowerSourceWiredClusterServer();
28
+ break;
29
+ case 'None':
30
+ break;
31
+ }
32
+ this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Matterbridge Camera');
33
+ createDefaultCameraAvStreamManagementClusterServer(this, {
34
+ maxContentBufferSize,
35
+ maxNetworkBandwidth,
36
+ supportedStreamUsages,
37
+ streamUsagePriorities,
38
+ maxConcurrentEncoders,
39
+ maxEncodedPixelRate,
40
+ videoSensorParams,
41
+ minViewportResolution,
42
+ rateDistortionTradeOffPoints,
43
+ currentFrameRate,
44
+ viewport,
45
+ microphoneCapabilities,
46
+ });
47
+ createDefaultWebRtcTransportProviderClusterServer(this);
48
+ addWebRtcTransportRequestorClient(this);
49
+ this.addRequiredClusters();
50
+ }
51
+ }
52
+ export function createDefaultCameraAvStreamManagementClusterServer(endpoint, options) {
53
+ endpoint.behaviors.require(MatterbridgeCameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Video, CameraAvStreamManagement.Feature.Audio, CameraAvStreamManagement.Feature.ImageControl), {
54
+ ...options,
55
+ hardPrivacyModeOn: false,
56
+ statusLightEnabled: false,
57
+ statusLightBrightness: ThreeLevelAuto.Auto,
58
+ allocatedVideoStreams: [],
59
+ allocatedAudioStreams: [],
60
+ microphoneMuted: false,
61
+ microphoneVolumeLevel: 128,
62
+ microphoneMaxLevel: 254,
63
+ microphoneMinLevel: 0,
64
+ microphoneAgcEnabled: false,
65
+ imageRotation: 0,
66
+ imageFlipVertical: false,
67
+ imageFlipHorizontal: false,
68
+ });
69
+ return endpoint;
70
+ }
71
+ export function createDefaultWebRtcTransportProviderClusterServer(endpoint) {
72
+ endpoint.behaviors.require(MatterbridgeWebRtcTransportProviderServer, { currentSessions: [] });
73
+ return endpoint;
74
+ }
75
+ export function addWebRtcTransportRequestorClient(endpoint) {
76
+ endpoint.behaviors.require(MatterbridgeBindingServer, { clientList: [WebRtcTransportRequestor.id] });
77
+ endpoint.type.clientClusters['webRtcTransportRequestor'] ??= WebRtcTransportRequestorClient;
78
+ return endpoint;
79
+ }
@@ -0,0 +1,32 @@
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';
5
+ export class Doorbell extends MatterbridgeEndpoint {
6
+ 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(' ', '')}` });
9
+ this.createDefaultIdentifyClusterServer(identifyTime, identifyType);
10
+ this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Matterbridge Doorbell');
11
+ switch (powerSourceType) {
12
+ case 'Rechargeable':
13
+ this.createDefaultPowerSourceRechargeableBatteryClusterServer();
14
+ break;
15
+ case 'Replaceable':
16
+ this.createDefaultPowerSourceReplaceableBatteryClusterServer();
17
+ break;
18
+ case 'Battery':
19
+ this.createDefaultPowerSourceBatteryClusterServer();
20
+ break;
21
+ case 'Wired':
22
+ this.createDefaultPowerSourceWiredClusterServer();
23
+ break;
24
+ case 'None':
25
+ break;
26
+ }
27
+ this.createDefaultMomentarySwitchClusterServer();
28
+ this.behaviors.require(MatterbridgeBindingServer, { clientList: [Chime.id] });
29
+ this.type.clientClusters['chime'] ??= ChimeClient;
30
+ this.addRequiredClusters();
31
+ }
32
+ }
@@ -33,20 +33,29 @@ export class SnapshotCamera extends MatterbridgeEndpoint {
33
33
  case 'None':
34
34
  break;
35
35
  }
36
- createDefaultCameraAvStreamManagementClusterServer(this, maxConcurrentEncoders, maxEncodedPixelRate, maxContentBufferSize, snapshotCapabilities, maxNetworkBandwidth, supportedStreamUsages, allocatedSnapshotStreams, streamUsagePriorities);
36
+ createDefaultSnapshotCameraAvStreamManagementClusterServer(this, {
37
+ maxConcurrentEncoders,
38
+ maxEncodedPixelRate,
39
+ maxContentBufferSize,
40
+ snapshotCapabilities,
41
+ maxNetworkBandwidth,
42
+ supportedStreamUsages,
43
+ allocatedSnapshotStreams,
44
+ streamUsagePriorities,
45
+ });
37
46
  this.addRequiredClusters();
38
47
  }
39
48
  }
40
- export function createDefaultCameraAvStreamManagementClusterServer(endpoint, maxConcurrentEncoders, maxEncodedPixelRate, maxContentBufferSize, snapshotCapabilities, maxNetworkBandwidth, supportedStreamUsages, allocatedSnapshotStreams, streamUsagePriorities) {
41
- endpoint.behaviors.require(MatterbridgeCameraAvStreamManagementServer, {
42
- maxContentBufferSize,
43
- maxNetworkBandwidth,
44
- supportedStreamUsages,
45
- streamUsagePriorities,
46
- maxConcurrentEncoders,
47
- maxEncodedPixelRate,
48
- snapshotCapabilities,
49
- allocatedSnapshotStreams,
49
+ export function createDefaultSnapshotCameraAvStreamManagementClusterServer(endpoint, options) {
50
+ endpoint.behaviors.require(MatterbridgeCameraAvStreamManagementServer.with(CameraAvStreamManagement.Feature.Snapshot, CameraAvStreamManagement.Feature.ImageControl), {
51
+ maxContentBufferSize: options.maxContentBufferSize,
52
+ maxNetworkBandwidth: options.maxNetworkBandwidth,
53
+ supportedStreamUsages: options.supportedStreamUsages,
54
+ streamUsagePriorities: options.streamUsagePriorities,
55
+ maxConcurrentEncoders: options.maxConcurrentEncoders,
56
+ maxEncodedPixelRate: options.maxEncodedPixelRate,
57
+ snapshotCapabilities: options.snapshotCapabilities,
58
+ allocatedSnapshotStreams: options.allocatedSnapshotStreams,
50
59
  imageRotation: 0,
51
60
  imageFlipVertical: false,
52
61
  imageFlipHorizontal: false,
package/dist/module.js CHANGED
@@ -1,6 +1,9 @@
1
+ import './patches/objectSchemaInjectFieldFix.js';
1
2
  import { MatterbridgeDynamicPlatform } from 'matterbridge';
2
3
  import { Identify, Chime as ChimeCluster, PowerSource } from 'matterbridge/matter/clusters';
4
+ import { Camera } from './devices/camera.js';
3
5
  import { Chime } from './devices/chime.js';
6
+ import { Doorbell } from './devices/doorbell.js';
4
7
  import { SnapshotCamera } from './devices/snapshotCamera.js';
5
8
  export default function initializePlugin(matterbridge, log, config) {
6
9
  return new ExampleMatterbridgeCameraPlatform(matterbridge, log, config);
@@ -29,12 +32,20 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
29
32
  enabled: true,
30
33
  });
31
34
  await this.registerDevice(exampleChime);
32
- const exampleSnapshotCamera = new SnapshotCamera('Snapshot Camera', 'CAMERA-001', {
35
+ const exampleDoorbell = new Doorbell('Doorbell', 'DOORBELL-001', {
36
+ identifyTime: 5,
37
+ identifyType: Identify.IdentifyType.VisibleIndicator,
38
+ powerSourceType: 'Replaceable',
39
+ });
40
+ await this.registerDevice(exampleDoorbell);
41
+ const exampleSnapshotCamera = new SnapshotCamera('Snapshot Camera', 'SNAPSHOT-001', {
33
42
  identifyTime: 5,
34
43
  identifyType: Identify.IdentifyType.VisibleIndicator,
35
44
  powerSourceType: 'Wired',
36
45
  });
37
46
  await this.registerDevice(exampleSnapshotCamera);
47
+ const exampleCamera = new Camera('Camera', 'CAMERA-001');
48
+ await this.registerDevice(exampleCamera);
38
49
  this.log.info(`Platform ${this.config.name} started successfully`);
39
50
  }
40
51
  async onConfigure() {
@@ -45,7 +56,10 @@ export class ExampleMatterbridgeCameraPlatform extends MatterbridgeDynamicPlatfo
45
56
  throw new Error(`Chime device not found. Please ensure the device is registered before configuration.`);
46
57
  await exampleChime.setCluster(PowerSource, { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 150, batQuantity: 2, batReplacementDescription: 'AA' }, exampleChime.log);
47
58
  await exampleChime.setAttribute(ChimeCluster, 'enabled', true, exampleChime.log);
48
- const exampleSnapshotCamera = this.getDeviceById('SnapshotCamera-CAMERA-001');
59
+ const exampleDoorbell = this.getDeviceById('Doorbell-DOORBELL-001');
60
+ if (!exampleDoorbell)
61
+ throw new Error(`Doorbell device not found. Please ensure the device is registered before configuration.`);
62
+ const exampleSnapshotCamera = this.getDeviceById('SnapshotCamera-SNAPSHOT-001');
49
63
  if (!exampleSnapshotCamera)
50
64
  throw new Error(`Snapshot camera device not found. Please ensure the device is registered before configuration.`);
51
65
  this.log.info(`Platform ${this.config.name} configured successfully`);
@@ -0,0 +1,17 @@
1
+ import { ObjectSchema } from 'matterbridge/matter/types';
2
+ function patchedInjectField(value, fieldId, fieldValue, injectChecker) {
3
+ for (const k in this.fieldDefinitions) {
4
+ const field = this.fieldDefinitions[k];
5
+ if (field.id === fieldId) {
6
+ if (injectChecker(value[k])) {
7
+ field.schema.validate(fieldValue);
8
+ value[k] = fieldValue;
9
+ }
10
+ }
11
+ else if (value[k] !== undefined && value[k] !== null) {
12
+ value[k] = field.schema.injectField(value[k], fieldId, fieldValue, injectChecker);
13
+ }
14
+ }
15
+ return value;
16
+ }
17
+ ObjectSchema.prototype.injectField = patchedInjectField;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "matterbridge-example-camera",
3
- "version": "0.0.2-dev-20260714-b39fe14",
3
+ "version": "0.0.2-dev-20260714-3c75ee7",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "matterbridge-example-camera",
9
- "version": "0.0.2-dev-20260714-b39fe14",
9
+ "version": "0.0.2-dev-20260714-3c75ee7",
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.2-dev-20260714-b39fe14",
3
+ "version": "0.0.2-dev-20260714-3c75ee7",
4
4
  "description": "Matterbridge camera example plugin",
5
5
  "author": "https://github.com/Luligu",
6
6
  "license": "Apache-2.0",