From a9e96eb65c8307470a2317ba0111d1e3401529b1 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Sun, 26 Feb 2023 20:49:58 -0800 Subject: [PATCH] Use Frigate camera name as webrtc_card default URL. --- README.md | 18 ++++++++++++------ src/camera-manager/frigate/engine-frigate.ts | 19 ++++++++++++++++++- src/camera-manager/types.ts | 1 + src/components/live/live-webrtc-card.ts | 14 ++++++++++++-- src/components/live/live.ts | 1 + 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fab53825..622fb085 100644 --- a/README.md +++ b/README.md @@ -187,8 +187,8 @@ cameras: | Option | Default | Overridable | Description | | - | - | - | - | -| `entity` | | :heavy_multiplication_x: | The RTSP entity to pass to the WebRTC Card for this camera. Specify this OR `url`. | -| `url` | | :heavy_multiplication_x: | The RTSP url to pass to the WebRTC Card. Specify this OR `entity`. | +| `entity` | | :heavy_multiplication_x: | The RTSP entity to pass to the WebRTC Card for this camera. | +| `url` | Depends on the camera engine (e.g. Frigate will use the camera name by default since this is the [recommended setup](https://deploy-preview-4055--frigate-docs.netlify.app/guides/configuring_go2rtc/))| :heavy_multiplication_x: | The RTSP url to pass to the WebRTC Card. | | `*`| | :heavy_multiplication_x: | Any options specified in the `webrtc_card:` YAML dictionary are silently passed through to the AlexxIT's WebRTC Card. See [WebRTC Configuration](https://github.com/AlexxIT/WebRTC#configuration) for full details this external card provides. | @@ -873,6 +873,12 @@ events/snapshots/UI. A perfect combination! #### Specifying The WebRTC Card Camera +##### Frigate v0.12 and onwards + +If you have used the [recommended go2rtc setup](https://deploy-preview-4055--frigate-docs.netlify.app/guides/configuring_go2rtc/) for Frigate, no additional `webrtc_card` configuration is necessary. + +##### Frigate v0.11 and earlier + The WebRTC Card live provider does **not** support use of Frigate-provided camera entities, as it requires an RTSP stream which Frigate does not currently provide. There are two ways to specify the WebRTC Card source camera: @@ -899,12 +905,12 @@ cameras: url: 'rtsp://USERNAME:PASSWORD@CAMERA:554/RTSP_PATH' ``` -Other WebRTC Card options may be specified under the `live` section, like so: +Other WebRTC Card options may be specified under the `webrtc_card` section, like so: ```yaml -live: - webrtc_card: - ui: true +cameras: + - webrtc_card: + ui: true ``` See [the WebRTC Card live configuration](#webrtc-live-configuration) above, and the diff --git a/src/camera-manager/frigate/engine-frigate.ts b/src/camera-manager/frigate/engine-frigate.ts index 67f6ae62..c5675902 100644 --- a/src/camera-manager/frigate/engine-frigate.ts +++ b/src/camera-manager/frigate/engine-frigate.ts @@ -1093,7 +1093,9 @@ export class FrigateCameraManagerEngine // go2rtc is exposed by the integration under the (slightly // misleading) 'mse' path, even though that path can serve all go2rtc // modes. - `/mse/api/ws?src=${cameraConfig.go2rtc?.stream ?? cameraConfig.frigate.camera_name}`, + `/mse/api/ws?src=${ + cameraConfig.go2rtc?.stream ?? cameraConfig.frigate.camera_name + }`, sign: true, }; }; @@ -1107,15 +1109,30 @@ export class FrigateCameraManagerEngine }; }; + const getWebRTCCard = (): CameraEndpoint | null => { + // By defaykt use the frigate camera name which is the default recommended + // setup as per: + // https://deploy-preview-4055--frigate-docs.netlify.app/guides/configuring_go2rtc/ + // + // The user may override this in their webrtc_card configuration. + const endpoint = cameraConfig.frigate.camera_name + ? cameraConfig.frigate.camera_name + : null; + return endpoint ? { endpoint: endpoint } : null; + }; + const ui = getUIEndpoint(); const go2rtc = getGo2RTC(); const jsmpeg = getJSMPEG(); + const webrtcCard = getWebRTCCard(); return ui || go2rtc || jsmpeg ? { ...(ui && { ui: ui }), ...(go2rtc && { go2rtc: go2rtc }), ...(jsmpeg && { jsmpeg: jsmpeg }), + ...(jsmpeg && { jsmpeg: jsmpeg }), + ...(webrtcCard && { webrtcCard: webrtcCard }), } : null; } diff --git a/src/camera-manager/types.ts b/src/camera-manager/types.ts index 8f1ab6b5..56c643e7 100644 --- a/src/camera-manager/types.ts +++ b/src/camera-manager/types.ts @@ -124,6 +124,7 @@ export interface CameraEndpoints { ui?: CameraEndpoint; go2rtc?: CameraEndpoint; jsmpeg?: CameraEndpoint; + webrtcCard?: CameraEndpoint; } export type CameraConfigs = Map; diff --git a/src/components/live/live-webrtc-card.ts b/src/components/live/live-webrtc-card.ts index 1189972e..67c4fbb3 100644 --- a/src/components/live/live-webrtc-card.ts +++ b/src/components/live/live-webrtc-card.ts @@ -17,6 +17,7 @@ import { hideMediaControlsTemporarily, MEDIA_LOAD_CONTROLS_HIDE_SECONDS, } from '../../utils/media.js'; +import { CameraEndpoints } from '../../camera-manager/types.js'; // Create a wrapper for AlexxIT's WebRTC card // - https://github.com/AlexxIT/WebRTC @@ -28,6 +29,9 @@ export class FrigateCardLiveWebRTCCard @property({ attribute: false }) public cameraConfig?: CameraConfig; + @property({ attribute: false }) + public cameraEndpoints?: CameraEndpoints; + @property({ attribute: false }) public cardWideConfig?: CardWideConfig; @@ -90,12 +94,18 @@ export class FrigateCardLiveWebRTCCard protected _createWebRTC(): HTMLElement | null { // eslint-disable-next-line @typescript-eslint/no-explicit-any const webrtcElement = this._webrtcTask.value; - if (webrtcElement && this.hass && this.cameraConfig?.webrtc_card) { + if (webrtcElement && this.hass && this.cameraConfig) { const webrtc = new webrtcElement() as HTMLElement & { hass: HomeAssistant; setConfig: (config: Record) => void; }; - webrtc.setConfig(this.cameraConfig.webrtc_card); + const config = {...this.cameraConfig.webrtc_card}; + if (!config.url && !config.entity && this.cameraEndpoints?.webrtcCard) { + // This will never need to be signed, it is just used internally by the + // card as a stream name lookup. + config.url = this.cameraEndpoints.webrtcCard.endpoint; + } + webrtc.setConfig(config); webrtc.hass = this.hass; return webrtc; } diff --git a/src/components/live/live.ts b/src/components/live/live.ts index 947f3a13..02491c46 100644 --- a/src/components/live/live.ts +++ b/src/components/live/live.ts @@ -899,6 +899,7 @@ export class FrigateCardLiveProvider class=${classMap(providerClasses)} .hass=${this.hass} .cameraConfig=${this.cameraConfig} + .cameraEndpoints=${this.cameraEndpoints} .cardWideConfig=${this.cardWideConfig} @frigate-card:media:loaded=${this._videoMediaShowHandler.bind(this)} >