@matter-server/dashboard 1.2.8 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/client/models/descriptions.d.ts +8 -0
- package/dist/esm/client/models/descriptions.d.ts.map +1 -1
- package/dist/esm/client/models/descriptions.js +2049 -81
- package/dist/esm/client/models/descriptions.js.map +1 -1
- package/dist/esm/components/webrtc-stream-view.d.ts +35 -1
- package/dist/esm/components/webrtc-stream-view.d.ts.map +1 -1
- package/dist/esm/components/webrtc-stream-view.js +154 -90
- package/dist/esm/components/webrtc-stream-view.js.map +1 -1
- package/dist/esm/pages/camera-overlay.d.ts +1 -0
- package/dist/esm/pages/camera-overlay.d.ts.map +1 -1
- package/dist/esm/pages/camera-overlay.js +12 -14
- package/dist/esm/pages/camera-overlay.js.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/closure-control-commands.d.ts +35 -0
- package/dist/esm/pages/cluster-commands/clusters/closure-control-commands.d.ts.map +1 -0
- package/dist/esm/pages/cluster-commands/clusters/closure-control-commands.js +352 -0
- package/dist/esm/pages/cluster-commands/clusters/closure-control-commands.js.map +6 -0
- package/dist/esm/pages/cluster-commands/index.d.ts +1 -0
- package/dist/esm/pages/cluster-commands/index.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/index.js +1 -0
- package/dist/esm/pages/cluster-commands/index.js.map +1 -1
- package/dist/esm/pages/components/node-details.d.ts.map +1 -1
- package/dist/esm/pages/components/node-details.js +17 -8
- package/dist/esm/pages/components/node-details.js.map +1 -1
- package/dist/esm/pages/matter-cluster-view.d.ts +1 -0
- package/dist/esm/pages/matter-cluster-view.d.ts.map +1 -1
- package/dist/esm/pages/matter-cluster-view.js +64 -0
- package/dist/esm/pages/matter-cluster-view.js.map +1 -1
- package/dist/esm/pages/matter-node-view.d.ts.map +1 -1
- package/dist/esm/pages/matter-node-view.js +10 -6
- package/dist/esm/pages/matter-node-view.js.map +1 -1
- package/dist/esm/util/camera.d.ts +22 -0
- package/dist/esm/util/camera.d.ts.map +1 -0
- package/dist/esm/util/camera.js +48 -0
- package/dist/esm/util/camera.js.map +6 -0
- package/dist/esm/util/closure-control.d.ts +57 -0
- package/dist/esm/util/closure-control.d.ts.map +1 -0
- package/dist/esm/util/closure-control.js +148 -0
- package/dist/esm/util/closure-control.js.map +6 -0
- package/dist/esm/util/cluster-features.d.ts +8 -0
- package/dist/esm/util/cluster-features.d.ts.map +1 -0
- package/dist/esm/util/cluster-features.js +14 -0
- package/dist/esm/util/cluster-features.js.map +6 -0
- package/dist/esm/util/device-icons.d.ts +0 -2
- package/dist/esm/util/device-icons.d.ts.map +1 -1
- package/dist/esm/util/device-icons.js +0 -6
- package/dist/esm/util/device-icons.js.map +1 -1
- package/dist/esm/util/endpoints.d.ts +11 -0
- package/dist/esm/util/endpoints.d.ts.map +1 -1
- package/dist/esm/util/endpoints.js +33 -1
- package/dist/esm/util/endpoints.js.map +1 -1
- package/dist/web/js/{attribute-write-dialog-CB7oucjt.js → attribute-write-dialog-UxEN5w8r.js} +1 -1
- package/dist/web/js/{command-invoke-dialog-C9rdQjTo.js → command-invoke-dialog-CVXU-ZoZ.js} +1 -1
- package/dist/web/js/{commission-node-dialog-BwkiZy8i.js → commission-node-dialog-D5HIBPy_.js} +5 -5
- package/dist/web/js/{commission-node-existing-BWTlMlwi.js → commission-node-existing-Bniw0yfY.js} +1 -1
- package/dist/web/js/{commission-node-thread-WDo3_tCy.js → commission-node-thread-D7w0p3f2.js} +1 -1
- package/dist/web/js/{commission-node-wifi-Drj7Z0rY.js → commission-node-wifi-DeTq4twp.js} +1 -1
- package/dist/web/js/{dialog-box-Dq6fTPQH.js → dialog-box-DkTPEszi.js} +1 -1
- package/dist/web/js/{fabric-label-dialog-FE4tGieS.js → fabric-label-dialog-8kIYOl4q.js} +1 -1
- package/dist/web/js/main.js +1 -1
- package/dist/web/js/{matter-dashboard-app-Ditf9BYC.js → matter-dashboard-app-BBGILOPg.js} +3303 -717
- package/dist/web/js/{node-acl-add-dialog-BA3u0qYj.js → node-acl-add-dialog-KiDTJk-M.js} +1 -1
- package/dist/web/js/{node-binding-dialog-BV_fMc0a.js → node-binding-dialog-DffAwr6H.js} +1 -1
- package/dist/web/js/{node-label-dialog-DG5CqG1e.js → node-label-dialog-DhRlTzGl.js} +1 -1
- package/dist/web/js/{settings-dialog-VafGbl7R.js → settings-dialog-BOy5I7JW.js} +1 -1
- package/package.json +4 -4
- package/src/client/models/descriptions.ts +2053 -78
- package/src/components/webrtc-stream-view.ts +216 -112
- package/src/pages/camera-overlay.ts +17 -18
- package/src/pages/cluster-commands/clusters/closure-control-commands.ts +393 -0
- package/src/pages/cluster-commands/index.ts +1 -0
- package/src/pages/components/node-details.ts +19 -9
- package/src/pages/matter-cluster-view.ts +73 -0
- package/src/pages/matter-node-view.ts +10 -6
- package/src/util/camera.ts +67 -0
- package/src/util/closure-control.ts +193 -0
- package/src/util/cluster-features.ts +17 -0
- package/src/util/device-icons.ts +0 -7
- package/src/util/endpoints.ts +50 -0
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { consume } from "@lit/context";
|
|
8
8
|
import type {
|
|
9
9
|
MatterClient,
|
|
10
|
+
MatterNode,
|
|
10
11
|
WebRtcAnswerData,
|
|
11
12
|
WebRtcCallbackData,
|
|
12
13
|
WebRtcIceCandidatesData,
|
|
@@ -36,9 +37,13 @@ const END_REASON_USER_HANGUP = 2;
|
|
|
36
37
|
export const CAMERA_AV_STREAM_MANAGEMENT_CLUSTER_ID = 0x551;
|
|
37
38
|
const WEBRTC_TRANSPORT_PROVIDER_CLUSTER_ID = 0x553;
|
|
38
39
|
|
|
39
|
-
// AVSM FeatureMap bits (spec §11.2.4):
|
|
40
|
-
//
|
|
41
|
-
//
|
|
40
|
+
// AVSM FeatureMap bits (spec §11.2.4): ADO=0 audio, VDO=1 gates VideoStreamAllocate —
|
|
41
|
+
// audio-only devices such as Audio Doorbell advertise ADO without VDO — SNP=2 enables
|
|
42
|
+
// snapshot streams, WMARK=6 enables watermark overlay, OSD=7 enables on-screen display.
|
|
43
|
+
// When advertised, VideoStreamAllocate and SnapshotStreamAllocate REQUIRE
|
|
44
|
+
// watermarkEnabled / osdEnabled fields.
|
|
45
|
+
export const AVSM_FEAT_ADO = 1 << 0;
|
|
46
|
+
export const AVSM_FEAT_VDO = 1 << 1;
|
|
42
47
|
export const AVSM_FEAT_SNP = 1 << 2;
|
|
43
48
|
export const AVSM_FEAT_WMARK = 1 << 6;
|
|
44
49
|
export const AVSM_FEAT_OSD = 1 << 7;
|
|
@@ -47,6 +52,44 @@ export const AVSM_FEATURE_MAP_ATTR_ID = 0xfffc;
|
|
|
47
52
|
// snapshot streams draw from.
|
|
48
53
|
const AVSM_MAX_ENCODED_PIXEL_RATE_ATTR_ID = 0x1;
|
|
49
54
|
|
|
55
|
+
export interface AvsmFeatures {
|
|
56
|
+
// false until the FeatureMap attribute is cached; callers must not read a missing FeatureMap
|
|
57
|
+
// as "no video" (that would skip VideoStreamAllocate on a real camera whose attribute is late).
|
|
58
|
+
known: boolean;
|
|
59
|
+
ado: boolean;
|
|
60
|
+
vdo: boolean;
|
|
61
|
+
snp: boolean;
|
|
62
|
+
wmark: boolean;
|
|
63
|
+
osd: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Reads the AVSM FeatureMap (spec §11.2.4) for a node/endpoint's CameraAvStreamManagement
|
|
68
|
+
* cluster. Audio-only devices (Intercom, Audio Doorbell) advertise Audio without Video (vdo).
|
|
69
|
+
*/
|
|
70
|
+
export function readAvsmFeatures(node: MatterNode | undefined, endpoint: number): AvsmFeatures {
|
|
71
|
+
const raw = node?.attributes[`${endpoint}/${CAMERA_AV_STREAM_MANAGEMENT_CLUSTER_ID}/${AVSM_FEATURE_MAP_ATTR_ID}`];
|
|
72
|
+
const known = typeof raw === "number";
|
|
73
|
+
const bits = known ? raw : 0;
|
|
74
|
+
return {
|
|
75
|
+
known,
|
|
76
|
+
ado: (bits & AVSM_FEAT_ADO) !== 0,
|
|
77
|
+
vdo: (bits & AVSM_FEAT_VDO) !== 0,
|
|
78
|
+
snp: (bits & AVSM_FEAT_SNP) !== 0,
|
|
79
|
+
wmark: (bits & AVSM_FEAT_WMARK) !== 0,
|
|
80
|
+
osd: (bits & AVSM_FEAT_OSD) !== 0,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Audio-only live view: the FeatureMap is known and does not advertise Video. When the FeatureMap
|
|
86
|
+
* hasn't arrived we assume video-capable, so a late attribute can't strand a real camera in an
|
|
87
|
+
* audio-only session (and VideoStreamAllocate is still attempted).
|
|
88
|
+
*/
|
|
89
|
+
export function isAudioOnlyAvsm(features: AvsmFeatures): boolean {
|
|
90
|
+
return features.known && !features.vdo;
|
|
91
|
+
}
|
|
92
|
+
|
|
50
93
|
const DEFAULT_MAX_RESOLUTION = { width: 1920, height: 1080 };
|
|
51
94
|
const DEFAULT_MIN_RESOLUTION = { width: 640, height: 480 };
|
|
52
95
|
|
|
@@ -201,6 +244,11 @@ export class WebRtcStreamView extends LitElement {
|
|
|
201
244
|
|
|
202
245
|
private _snapshotStreamId: number | null = null;
|
|
203
246
|
private _snapshotResolution: { width: number; height: number } | null = null;
|
|
247
|
+
private _snapshotImageCodec: number | null = null;
|
|
248
|
+
private _snapshotMaxFrameRate: number | null = null;
|
|
249
|
+
private _snapshotWatermarkEnabled: boolean | undefined = undefined;
|
|
250
|
+
private _snapshotOsdEnabled: boolean | undefined = undefined;
|
|
251
|
+
private _snapshotChain: Promise<unknown> = Promise.resolve();
|
|
204
252
|
/** True when we allocated this stream ourselves and must Deallocate it on stop. False when reusing an existing allocation. */
|
|
205
253
|
private _videoStreamOwned = false;
|
|
206
254
|
private _audioStreamOwned = false;
|
|
@@ -294,8 +342,10 @@ export class WebRtcStreamView extends LitElement {
|
|
|
294
342
|
try {
|
|
295
343
|
const pc = new RTCPeerConnection({ iceServers: [] });
|
|
296
344
|
this._pc = pc;
|
|
345
|
+
const avsmFeatures = this._readAvsmFeatures();
|
|
346
|
+
const audioOnly = isAudioOnlyAvsm(avsmFeatures);
|
|
297
347
|
|
|
298
|
-
pc.addTransceiver("video", { direction: "recvonly" });
|
|
348
|
+
if (!audioOnly) pc.addTransceiver("video", { direction: "recvonly" });
|
|
299
349
|
pc.addTransceiver("audio", { direction: "recvonly" });
|
|
300
350
|
|
|
301
351
|
pc.onicecandidate = ev => {
|
|
@@ -350,73 +400,61 @@ export class WebRtcStreamView extends LitElement {
|
|
|
350
400
|
|
|
351
401
|
const minResolution = this.resolution ?? DEFAULT_MIN_RESOLUTION;
|
|
352
402
|
const maxResolution = this.resolution ?? DEFAULT_MAX_RESOLUTION;
|
|
353
|
-
const avsmFeatures = this._readAvsmFeatures();
|
|
354
403
|
const maxEncodedPixelRate = this._readMaxEncodedPixelRate();
|
|
355
404
|
const snapshotReservation = this._snapshotBudgetReservation();
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
snapshotReservation,
|
|
363
|
-
});
|
|
364
|
-
const videoAllocPayload: Record<string, unknown> = {
|
|
365
|
-
streamUsage: STREAM_USAGE_LIVE_VIEW,
|
|
366
|
-
videoCodec: 0,
|
|
367
|
-
minFrameRate: Math.min(VIDEO_MIN_FRAME_RATE, videoMaxFrameRate),
|
|
368
|
-
maxFrameRate: videoMaxFrameRate,
|
|
369
|
-
minResolution,
|
|
370
|
-
maxResolution,
|
|
371
|
-
minBitRate: 10000,
|
|
372
|
-
maxBitRate: 10000,
|
|
373
|
-
keyFrameInterval: 4000,
|
|
374
|
-
};
|
|
375
|
-
if (avsmFeatures.wmark) videoAllocPayload.watermarkEnabled = this.watermarkEnabled;
|
|
376
|
-
if (avsmFeatures.osd) videoAllocPayload.osdEnabled = this.osdEnabled;
|
|
377
|
-
|
|
378
|
-
// Spec §11.2.1.2.1 — server SHALL reuse an existing stream that covers our
|
|
379
|
-
// request. Search AllocatedVideoStreams (attr 0x000F) first to avoid even
|
|
380
|
-
// sending VideoStreamAllocate when a usable stream is already in place. Skip
|
|
381
|
-
// candidates that over-reserve the encoder budget so reuse can't reintroduce
|
|
382
|
-
// the snapshot ResourceExhausted a fresh allocation avoids.
|
|
383
|
-
const videoWant = {
|
|
384
|
-
streamUsage: STREAM_USAGE_LIVE_VIEW,
|
|
385
|
-
videoCodec: 0,
|
|
386
|
-
minRes: minResolution,
|
|
387
|
-
maxRes: maxResolution,
|
|
388
|
-
watermarkEnabled: avsmFeatures.wmark ? this.watermarkEnabled : undefined,
|
|
389
|
-
osdEnabled: avsmFeatures.osd ? this.osdEnabled : undefined,
|
|
390
|
-
budget: { maxEncodedPixelRate, snapshotReservation },
|
|
391
|
-
};
|
|
392
|
-
const reusedVideoId = this._findMatchingVideoStream(videoWant);
|
|
393
|
-
let videoAlloc: unknown = null;
|
|
394
|
-
let usedFallbackReuse = false;
|
|
395
|
-
if (reusedVideoId !== null) {
|
|
396
|
-
console.info("[webrtc-stream-view] reusing existing video stream", reusedVideoId);
|
|
397
|
-
this._videoStreamId = reusedVideoId;
|
|
405
|
+
|
|
406
|
+
if (audioOnly) {
|
|
407
|
+
// Audio-only devices (e.g. Audio Doorbell) don't advertise VDO: VideoStreamAllocate
|
|
408
|
+
// isn't in their AcceptedCommandList and would fail with UnsupportedCommand
|
|
409
|
+
// (code 129). Skip video entirely and stream audio-only.
|
|
410
|
+
this._videoStreamId = null;
|
|
398
411
|
this._videoStreamOwned = false;
|
|
399
412
|
} else {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
413
|
+
// Reserving the whole MaxEncodedPixelRate (e.g. 1080p@120) starves a concurrent
|
|
414
|
+
// SnapshotStreamAllocate (ResourceExhausted); size the video rate to leave the
|
|
415
|
+
// snapshot stream room within the shared encoder budget.
|
|
416
|
+
const videoMaxFrameRate = planVideoMaxFrameRate({
|
|
417
|
+
maxEncodedPixelRate,
|
|
418
|
+
videoResolution: maxResolution,
|
|
419
|
+
snapshotReservation,
|
|
420
|
+
});
|
|
421
|
+
const videoAllocPayload: Record<string, unknown> = {
|
|
422
|
+
streamUsage: STREAM_USAGE_LIVE_VIEW,
|
|
423
|
+
videoCodec: 0,
|
|
424
|
+
minFrameRate: Math.min(VIDEO_MIN_FRAME_RATE, videoMaxFrameRate),
|
|
425
|
+
maxFrameRate: videoMaxFrameRate,
|
|
426
|
+
minResolution,
|
|
427
|
+
maxResolution,
|
|
428
|
+
minBitRate: 10000,
|
|
429
|
+
maxBitRate: 10000,
|
|
430
|
+
keyFrameInterval: 4000,
|
|
431
|
+
};
|
|
432
|
+
if (avsmFeatures.wmark) videoAllocPayload.watermarkEnabled = this.watermarkEnabled;
|
|
433
|
+
if (avsmFeatures.osd) videoAllocPayload.osdEnabled = this.osdEnabled;
|
|
434
|
+
|
|
435
|
+
// Spec §11.2.1.2.1 — server SHALL reuse an existing stream that covers our
|
|
436
|
+
// request. Search AllocatedVideoStreams (attr 0x000F) first to avoid even
|
|
437
|
+
// sending VideoStreamAllocate when a usable stream is already in place. Skip
|
|
438
|
+
// candidates that over-reserve the encoder budget so reuse can't reintroduce
|
|
439
|
+
// the snapshot ResourceExhausted a fresh allocation avoids.
|
|
440
|
+
const videoWant = {
|
|
441
|
+
streamUsage: STREAM_USAGE_LIVE_VIEW,
|
|
442
|
+
videoCodec: 0,
|
|
443
|
+
minRes: minResolution,
|
|
444
|
+
maxRes: maxResolution,
|
|
445
|
+
watermarkEnabled: avsmFeatures.wmark ? this.watermarkEnabled : undefined,
|
|
446
|
+
osdEnabled: avsmFeatures.osd ? this.osdEnabled : undefined,
|
|
447
|
+
budget: { maxEncodedPixelRate, snapshotReservation },
|
|
448
|
+
};
|
|
449
|
+
const reusedVideoId = this._findMatchingVideoStream(videoWant);
|
|
450
|
+
let videoAlloc: unknown = null;
|
|
451
|
+
let usedFallbackReuse = false;
|
|
452
|
+
if (reusedVideoId !== null) {
|
|
453
|
+
console.info("[webrtc-stream-view] reusing existing video stream", reusedVideoId);
|
|
454
|
+
this._videoStreamId = reusedVideoId;
|
|
455
|
+
this._videoStreamOwned = false;
|
|
456
|
+
} else {
|
|
457
|
+
try {
|
|
420
458
|
videoAlloc = await this.client.deviceCommand(
|
|
421
459
|
this.nodeId,
|
|
422
460
|
this.endpointId,
|
|
@@ -424,29 +462,49 @@ export class WebRtcStreamView extends LitElement {
|
|
|
424
462
|
"VideoStreamAllocate",
|
|
425
463
|
videoAllocPayload,
|
|
426
464
|
);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
465
|
+
} catch (err) {
|
|
466
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
467
|
+
const isResourceExhausted =
|
|
468
|
+
message.includes("Resource exhausted") || message.includes("(code 137)");
|
|
469
|
+
if (!isResourceExhausted) throw err;
|
|
470
|
+
// Cameras with a shared encoder pool refuse VideoStreamAllocate while a snapshot
|
|
471
|
+
// stream is held — free ours and retry once.
|
|
472
|
+
if (this._snapshotStreamId !== null) {
|
|
473
|
+
console.info(
|
|
474
|
+
"[webrtc-stream-view] VideoStreamAllocate ResourceExhausted; freeing snapshot stream and retrying",
|
|
475
|
+
);
|
|
476
|
+
await this._runSerialized(() => this.deallocateSnapshot());
|
|
477
|
+
videoAlloc = await this.client.deviceCommand(
|
|
478
|
+
this.nodeId,
|
|
479
|
+
this.endpointId,
|
|
480
|
+
CAMERA_AV_STREAM_MANAGEMENT_CLUSTER_ID,
|
|
481
|
+
"VideoStreamAllocate",
|
|
482
|
+
videoAllocPayload,
|
|
483
|
+
);
|
|
484
|
+
} else {
|
|
485
|
+
// The budget is held by a stream we didn't allocate (e.g. another
|
|
486
|
+
// controller's 120 fps stream). Fall back to reusing it so live view
|
|
487
|
+
// still works; a concurrent snapshot may then be refused.
|
|
488
|
+
const fallbackId = this._findMatchingVideoStream({ ...videoWant, budget: undefined });
|
|
489
|
+
if (fallbackId === null) throw err;
|
|
490
|
+
console.warn(
|
|
491
|
+
"[webrtc-stream-view] VideoStreamAllocate ResourceExhausted; reusing over-budget stream",
|
|
492
|
+
fallbackId,
|
|
493
|
+
"(concurrent snapshot may be unavailable)",
|
|
494
|
+
);
|
|
495
|
+
this._videoStreamId = fallbackId;
|
|
496
|
+
this._videoStreamOwned = false;
|
|
497
|
+
usedFallbackReuse = true;
|
|
498
|
+
}
|
|
441
499
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
500
|
+
if (!usedFallbackReuse) {
|
|
501
|
+
const videoStreamId = parseStreamAllocate(videoAlloc, "videoStreamId");
|
|
502
|
+
if (videoStreamId === null) {
|
|
503
|
+
throw new Error("VideoStreamAllocate did not return a videoStreamId");
|
|
504
|
+
}
|
|
505
|
+
this._videoStreamId = videoStreamId;
|
|
506
|
+
this._videoStreamOwned = true;
|
|
447
507
|
}
|
|
448
|
-
this._videoStreamId = videoStreamId;
|
|
449
|
-
this._videoStreamOwned = true;
|
|
450
508
|
}
|
|
451
509
|
}
|
|
452
510
|
|
|
@@ -479,11 +537,17 @@ export class WebRtcStreamView extends LitElement {
|
|
|
479
537
|
this._audioStreamId = parseStreamAllocate(audioAlloc, "audioStreamId");
|
|
480
538
|
this._audioStreamOwned = this._audioStreamId !== null;
|
|
481
539
|
} catch (err) {
|
|
482
|
-
console.info("AudioStreamAllocate failed; continuing
|
|
540
|
+
console.info("AudioStreamAllocate failed; continuing without audio", err);
|
|
483
541
|
this._audioStreamId = null;
|
|
484
542
|
}
|
|
485
543
|
}
|
|
486
544
|
|
|
545
|
+
if (this._videoStreamId === null && this._audioStreamId === null) {
|
|
546
|
+
// Without either stream ProvideOffer requests no media; fail loudly instead of
|
|
547
|
+
// negotiating an empty session (audio-only device whose AudioStreamAllocate failed).
|
|
548
|
+
throw new Error("No media stream allocated: device advertises neither video nor audio");
|
|
549
|
+
}
|
|
550
|
+
|
|
487
551
|
const offer = await pc.createOffer();
|
|
488
552
|
await pc.setLocalDescription(offer);
|
|
489
553
|
|
|
@@ -584,7 +648,7 @@ export class WebRtcStreamView extends LitElement {
|
|
|
584
648
|
this._videoStreamOwned = false;
|
|
585
649
|
this._audioStreamOwned = false;
|
|
586
650
|
|
|
587
|
-
await this.deallocateSnapshot();
|
|
651
|
+
await this._runSerialized(() => this.deallocateSnapshot());
|
|
588
652
|
|
|
589
653
|
const video = this._video;
|
|
590
654
|
if (video && video.srcObject) {
|
|
@@ -614,7 +678,26 @@ export class WebRtcStreamView extends LitElement {
|
|
|
614
678
|
this._stopping = false;
|
|
615
679
|
}
|
|
616
680
|
|
|
681
|
+
/**
|
|
682
|
+
* Runs a snapshot-stream lifecycle op (capture, or a deallocate triggered by the video path /
|
|
683
|
+
* teardown) after any in-flight one settles. Keeps re-negotiation and cross-path deallocation
|
|
684
|
+
* from tearing down a stream a concurrent capture is using, and first-time captures from each
|
|
685
|
+
* allocating (leak).
|
|
686
|
+
*/
|
|
687
|
+
private _runSerialized<T>(op: () => Promise<T>): Promise<T> {
|
|
688
|
+
const run = this._snapshotChain.then(op, op);
|
|
689
|
+
this._snapshotChain = run.then(
|
|
690
|
+
() => undefined,
|
|
691
|
+
() => undefined,
|
|
692
|
+
);
|
|
693
|
+
return run;
|
|
694
|
+
}
|
|
695
|
+
|
|
617
696
|
async takeSnapshot(): Promise<{ dataUri: string; resolution: { width: number; height: number } }> {
|
|
697
|
+
return this._runSerialized(() => this._takeSnapshot());
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
private async _takeSnapshot(): Promise<{ dataUri: string; resolution: { width: number; height: number } }> {
|
|
618
701
|
if (!this.client) throw new Error("Matter client not available");
|
|
619
702
|
const streamId = await this._ensureSnapshotStream();
|
|
620
703
|
const requestedResolution = this._snapshotResolution ?? SNAPSHOT_DEFAULTS.resolution;
|
|
@@ -633,18 +716,8 @@ export class WebRtcStreamView extends LitElement {
|
|
|
633
716
|
};
|
|
634
717
|
}
|
|
635
718
|
|
|
636
|
-
private _readAvsmFeatures():
|
|
637
|
-
|
|
638
|
-
const raw =
|
|
639
|
-
node?.attributes[
|
|
640
|
-
`${this.endpointId}/${CAMERA_AV_STREAM_MANAGEMENT_CLUSTER_ID}/${AVSM_FEATURE_MAP_ATTR_ID}`
|
|
641
|
-
];
|
|
642
|
-
const bits = typeof raw === "number" ? raw : 0;
|
|
643
|
-
return {
|
|
644
|
-
snp: (bits & AVSM_FEAT_SNP) !== 0,
|
|
645
|
-
wmark: (bits & AVSM_FEAT_WMARK) !== 0,
|
|
646
|
-
osd: (bits & AVSM_FEAT_OSD) !== 0,
|
|
647
|
-
};
|
|
719
|
+
private _readAvsmFeatures(): AvsmFeatures {
|
|
720
|
+
return readAvsmFeatures(this.client?.nodes[String(this.nodeId)], this.endpointId);
|
|
648
721
|
}
|
|
649
722
|
|
|
650
723
|
private _readMaxEncodedPixelRate(): number | null {
|
|
@@ -682,6 +755,10 @@ export class WebRtcStreamView extends LitElement {
|
|
|
682
755
|
const wasOwned = this._snapshotStreamOwned;
|
|
683
756
|
this._snapshotStreamId = null;
|
|
684
757
|
this._snapshotResolution = null;
|
|
758
|
+
this._snapshotImageCodec = null;
|
|
759
|
+
this._snapshotMaxFrameRate = null;
|
|
760
|
+
this._snapshotWatermarkEnabled = undefined;
|
|
761
|
+
this._snapshotOsdEnabled = undefined;
|
|
685
762
|
this._snapshotStreamOwned = false;
|
|
686
763
|
if (!wasOwned) return; // Reused an existing allocation — leave it for its owner.
|
|
687
764
|
try {
|
|
@@ -791,7 +868,7 @@ export class WebRtcStreamView extends LitElement {
|
|
|
791
868
|
resolution: { width: number; height: number };
|
|
792
869
|
watermarkEnabled?: boolean;
|
|
793
870
|
osdEnabled?: boolean;
|
|
794
|
-
}):
|
|
871
|
+
}): number | null {
|
|
795
872
|
const node = this.client?.nodes[String(this.nodeId)];
|
|
796
873
|
const list = node?.attributes[`${this.endpointId}/${CAMERA_AV_STREAM_MANAGEMENT_CLUSTER_ID}/17`];
|
|
797
874
|
if (!Array.isArray(list)) return null;
|
|
@@ -818,14 +895,12 @@ export class WebRtcStreamView extends LitElement {
|
|
|
818
895
|
if (v !== want.osdEnabled) continue;
|
|
819
896
|
}
|
|
820
897
|
const id = pickNumber(obj, "snapshotStreamId", "0");
|
|
821
|
-
|
|
822
|
-
if (id !== null) return { id, resolution };
|
|
898
|
+
if (id !== null) return id;
|
|
823
899
|
}
|
|
824
900
|
return null;
|
|
825
901
|
}
|
|
826
902
|
|
|
827
903
|
private async _ensureSnapshotStream(): Promise<number> {
|
|
828
|
-
if (this._snapshotStreamId !== null) return this._snapshotStreamId;
|
|
829
904
|
if (!this.client) throw new Error("Matter client not available");
|
|
830
905
|
|
|
831
906
|
const node = this.client.nodes[String(this.nodeId)];
|
|
@@ -847,21 +922,46 @@ export class WebRtcStreamView extends LitElement {
|
|
|
847
922
|
const targetResolution = clampToCapability(this.snapshotResolution ?? cap.resolution, cap.resolution);
|
|
848
923
|
|
|
849
924
|
const avsmFeatures = this._readAvsmFeatures();
|
|
925
|
+
const wantWatermark = avsmFeatures.wmark ? this.watermarkEnabled : undefined;
|
|
926
|
+
const wantOsd = avsmFeatures.osd ? this.osdEnabled : undefined;
|
|
927
|
+
|
|
928
|
+
// A cached stream only still covers the current call if its resolution, codec, frame rate,
|
|
929
|
+
// and watermark/OSD flags all still match: the caller may have changed `snapshotResolution`
|
|
930
|
+
// or toggled watermark/OSD, or the encoder may have freed up (which reselects the capability,
|
|
931
|
+
// changing maxFrameRate), since it was ensured. Otherwise release it before searching for
|
|
932
|
+
// (or allocating) one that actually covers the new target.
|
|
933
|
+
if (this._snapshotStreamId !== null) {
|
|
934
|
+
if (
|
|
935
|
+
this._snapshotResolution?.width === targetResolution.width &&
|
|
936
|
+
this._snapshotResolution?.height === targetResolution.height &&
|
|
937
|
+
this._snapshotImageCodec === cap.imageCodec &&
|
|
938
|
+
this._snapshotMaxFrameRate === cap.maxFrameRate &&
|
|
939
|
+
this._snapshotWatermarkEnabled === wantWatermark &&
|
|
940
|
+
this._snapshotOsdEnabled === wantOsd
|
|
941
|
+
) {
|
|
942
|
+
return this._snapshotStreamId;
|
|
943
|
+
}
|
|
944
|
+
await this.deallocateSnapshot();
|
|
945
|
+
}
|
|
850
946
|
|
|
851
947
|
// AllocatedSnapshotStreams (attr 0x0011) — reuse existing stream when its capability
|
|
852
948
|
// range covers our target resolution (spec §11.2.1.2.1 / §11.2.8.8.8).
|
|
853
949
|
const reused = this._findMatchingSnapshotStream({
|
|
854
950
|
imageCodec: cap.imageCodec,
|
|
855
951
|
resolution: targetResolution,
|
|
856
|
-
watermarkEnabled:
|
|
857
|
-
osdEnabled:
|
|
952
|
+
watermarkEnabled: wantWatermark,
|
|
953
|
+
osdEnabled: wantOsd,
|
|
858
954
|
});
|
|
859
955
|
if (reused !== null) {
|
|
860
|
-
console.info("[webrtc-stream-view] reusing existing snapshot stream", reused
|
|
861
|
-
this._snapshotStreamId = reused
|
|
862
|
-
this._snapshotResolution =
|
|
956
|
+
console.info("[webrtc-stream-view] reusing existing snapshot stream", reused);
|
|
957
|
+
this._snapshotStreamId = reused;
|
|
958
|
+
this._snapshotResolution = targetResolution;
|
|
959
|
+
this._snapshotImageCodec = cap.imageCodec;
|
|
960
|
+
this._snapshotMaxFrameRate = cap.maxFrameRate;
|
|
961
|
+
this._snapshotWatermarkEnabled = wantWatermark;
|
|
962
|
+
this._snapshotOsdEnabled = wantOsd;
|
|
863
963
|
this._snapshotStreamOwned = false;
|
|
864
|
-
return reused
|
|
964
|
+
return reused;
|
|
865
965
|
}
|
|
866
966
|
|
|
867
967
|
const snapshotAllocPayload: Record<string, unknown> = {
|
|
@@ -886,6 +986,10 @@ export class WebRtcStreamView extends LitElement {
|
|
|
886
986
|
}
|
|
887
987
|
this._snapshotStreamId = snapshotStreamId;
|
|
888
988
|
this._snapshotResolution = targetResolution;
|
|
989
|
+
this._snapshotImageCodec = cap.imageCodec;
|
|
990
|
+
this._snapshotMaxFrameRate = cap.maxFrameRate;
|
|
991
|
+
this._snapshotWatermarkEnabled = wantWatermark;
|
|
992
|
+
this._snapshotOsdEnabled = wantOsd;
|
|
889
993
|
this._snapshotStreamOwned = true;
|
|
890
994
|
return this._snapshotStreamId;
|
|
891
995
|
}
|
|
@@ -28,8 +28,7 @@ import "../components/webrtc-stream-view.js";
|
|
|
28
28
|
import type { WebRtcStreamView } from "../components/webrtc-stream-view.js";
|
|
29
29
|
import { asObject, pickNumber } from "../util/attribute-shapes.js";
|
|
30
30
|
import { hasAvsumOnEndpoint } from "../util/avsum.js";
|
|
31
|
-
import {
|
|
32
|
-
import { getEndpointDeviceTypes } from "../util/endpoints.js";
|
|
31
|
+
import { supportsAudioOnlyLiveView, supportsLiveView, supportsSnapshot } from "../util/camera.js";
|
|
33
32
|
|
|
34
33
|
type StreamState = "idle" | "connecting" | "streaming" | "error";
|
|
35
34
|
|
|
@@ -77,23 +76,12 @@ export class CameraOverlay extends LitElement {
|
|
|
77
76
|
|
|
78
77
|
private get _liveViewSupported(): boolean {
|
|
79
78
|
const node = this.client?.nodes[String(this.nodeId)];
|
|
80
|
-
|
|
81
|
-
const deviceTypeIds = getEndpointDeviceTypes(node, this.endpointId).map(d => d.id);
|
|
82
|
-
return LIVE_VIEW_DEVICE_TYPE_IDS.some(id => deviceTypeIds.includes(id));
|
|
79
|
+
return node ? supportsLiveView(node, this.endpointId) : false;
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
private get _snapshotSupported(): boolean {
|
|
86
83
|
const node = this.client?.nodes[String(this.nodeId)];
|
|
87
|
-
|
|
88
|
-
const accepted = node?.attributes[`${this.endpointId}/1361/65529`];
|
|
89
|
-
if (!Array.isArray(accepted) || !accepted.includes(12)) return false;
|
|
90
|
-
// FeatureMap (attr 0xfffc = 65532) bit 2 (SNP) advertises snapshot support — some cameras
|
|
91
|
-
// set the bit but leave SnapshotCapabilities empty, so the feature bit is the authoritative
|
|
92
|
-
// signal and SnapshotCapabilities a hint we fall back from.
|
|
93
|
-
const featureMap = node?.attributes[`${this.endpointId}/1361/65532`];
|
|
94
|
-
if (typeof featureMap === "number" && (featureMap & 0x04) !== 0) return true;
|
|
95
|
-
const caps = node?.attributes[`${this.endpointId}/1361/10`];
|
|
96
|
-
return Array.isArray(caps) && caps.length > 0;
|
|
84
|
+
return node ? supportsSnapshot(node, this.endpointId) : false;
|
|
97
85
|
}
|
|
98
86
|
|
|
99
87
|
private _streamViewRef = createRef<WebRtcStreamView>();
|
|
@@ -175,9 +163,8 @@ export class CameraOverlay extends LitElement {
|
|
|
175
163
|
}
|
|
176
164
|
|
|
177
165
|
private _getSensorSize(): { width: number; height: number } | null {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const raw = node.attributes[`${this.endpointId}/1361/7`];
|
|
166
|
+
// AVSM VideoSensorParams (attr 0x2): SensorWidth/SensorHeight.
|
|
167
|
+
const raw = this._readCachedAvsmAttribute(0x2);
|
|
181
168
|
const obj = asObject(raw);
|
|
182
169
|
if (!obj) return null;
|
|
183
170
|
const w = pickNumber(obj, "sensorWidth", "0");
|
|
@@ -227,6 +214,18 @@ export class CameraOverlay extends LitElement {
|
|
|
227
214
|
// stream is being torn down) or a not-yet-allocated null (during connecting).
|
|
228
215
|
this._activeVideoStreamId =
|
|
229
216
|
ev.detail.state === "streaming" ? (this._streamViewRef.value?.videoStreamId ?? null) : null;
|
|
217
|
+
|
|
218
|
+
// Audio-only "Listen" sessions have no video; starting muted would defeat the feature, so
|
|
219
|
+
// unmute on stream start. Started from the user's Start click, so autoplay policy allows it.
|
|
220
|
+
if (ev.detail.state === "streaming" && this._isAudioOnly()) {
|
|
221
|
+
this._streamViewRef.value?.setMuted(false);
|
|
222
|
+
this._muted = false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private _isAudioOnly(): boolean {
|
|
227
|
+
const node = this.client?.nodes[String(this.nodeId)];
|
|
228
|
+
return node ? supportsAudioOnlyLiveView(node, this.endpointId) : false;
|
|
230
229
|
}
|
|
231
230
|
|
|
232
231
|
private _start(): void {
|