Use Frigate camera name as webrtc_card default URL.

This commit is contained in:
Dermot Duffy
2023-02-26 20:49:58 -08:00
parent de07097141
commit a9e96eb65c
5 changed files with 44 additions and 9 deletions
+18 -1
View File
@@ -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;
}
+1
View File
@@ -124,6 +124,7 @@ export interface CameraEndpoints {
ui?: CameraEndpoint;
go2rtc?: CameraEndpoint;
jsmpeg?: CameraEndpoint;
webrtcCard?: CameraEndpoint;
}
export type CameraConfigs = Map<string, CameraConfig>;
+12 -2
View File
@@ -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<string, unknown>) => 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;
}
+1
View File
@@ -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)}
>