fix: Correctly detect configuration for the webrtc-card live provider (#1850)

- Closes #1843

If this breaks something for you, please let me know. As a workaround,
you should manually be able to set it back to what it was with something
like:

```yaml
cameras:
 - camera_entity: camera.office
   webrtc_card:
      url: <frigate camera name>
```
This commit is contained in:
Dermot Duffy
2025-01-21 19:42:47 -08:00
committed by GitHub
parent 0212840688
commit 805a21107d
6 changed files with 33 additions and 25 deletions
@@ -987,18 +987,6 @@ export class FrigateCameraManagerEngine
}; };
}; };
const getWebRTCCard = (): CameraEndpoint | null => {
// By default 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 ui = getUIEndpoint();
const go2rtc = getDefaultGo2RTCEndpoint(cameraConfig, { const go2rtc = getDefaultGo2RTCEndpoint(cameraConfig, {
url: url:
@@ -1010,14 +998,12 @@ export class FrigateCameraManagerEngine
stream: cameraConfig.go2rtc?.stream ?? cameraConfig.frigate.camera_name, stream: cameraConfig.go2rtc?.stream ?? cameraConfig.frigate.camera_name,
}); });
const jsmpeg = getJSMPEG(); const jsmpeg = getJSMPEG();
const webrtcCard = getWebRTCCard();
return { return {
...super.getCameraEndpoints(cameraConfig, context), ...super.getCameraEndpoints(cameraConfig, context),
...(ui && { ui: ui }), ...(ui && { ui: ui }),
...(go2rtc && { go2rtc: go2rtc }), ...(go2rtc && { go2rtc: go2rtc }),
...(jsmpeg && { jsmpeg: jsmpeg }), ...(jsmpeg && { jsmpeg: jsmpeg }),
...(webrtcCard && { webrtcCard: webrtcCard }),
}; };
} }
+11 -2
View File
@@ -219,10 +219,19 @@ export class GenericCameraManagerEngine implements CameraManagerEngine {
cameraConfig: CameraConfig, cameraConfig: CameraConfig,
_context?: CameraEndpointsContext, _context?: CameraEndpointsContext,
): CameraEndpoints | null { ): CameraEndpoints | null {
const getWebRTCCard = (): CameraEndpoint | null => {
// The user may override this in their webrtc_card configuration.
const endpoint = cameraConfig.camera_entity ? cameraConfig.camera_entity : null;
return endpoint ? { endpoint: endpoint } : null;
};
const go2rtc = getDefaultGo2RTCEndpoint(cameraConfig); const go2rtc = getDefaultGo2RTCEndpoint(cameraConfig);
return go2rtc const webrtcCard = getWebRTCCard();
return go2rtc || webrtcCard
? { ? {
go2rtc: go2rtc, ...(go2rtc && { go2rtc: go2rtc }),
...(webrtcCard && { webrtcCard: webrtcCard }),
} }
: null; : null;
} }
+5 -5
View File
@@ -411,11 +411,11 @@ class FrigateCard extends LitElement {
: undefined} : undefined}
.deviceRegistryManager=${this._controller.getDeviceRegistryManager()} .deviceRegistryManager=${this._controller.getDeviceRegistryManager()}
></frigate-card-views> ></frigate-card-views>
${ ${this._controller.getMessageManager().hasMessage()
// Keep message rendering to last to show messages that may have been ? // Keep message rendering to last to show messages that may have been
// generated during the render. // generated during the render.
renderMessage(this._controller.getMessageManager().getMessage()) renderMessage(this._controller.getMessageManager().getMessage())
} : ''}
</div> </div>
${this._renderMenuStatusContainer('bottom')} ${this._renderMenuStatusContainer('bottom')}
${this._config?.elements ${this._config?.elements
+1 -3
View File
@@ -178,9 +178,7 @@ export class FrigateCardLiveWebRTCCard
...this.cameraConfig.webrtc_card, ...this.cameraConfig.webrtc_card,
}; };
if (!config.url && !config.entity && this.cameraEndpoints?.webrtcCard) { if (!config.url && !config.entity && this.cameraEndpoints?.webrtcCard) {
// This will never need to be signed, it is just used internally by the config.entity = this.cameraEndpoints.webrtcCard.endpoint;
// card as a stream name lookup.
config.url = this.cameraEndpoints.webrtcCard.endpoint;
} }
webrtc.setConfig(config); webrtc.setConfig(config);
webrtc.hass = this.hass; webrtc.hass = this.hass;
@@ -80,6 +80,7 @@ const createFrigateCameraConfig = (config?: RawFrigateCardConfig): CameraConfig
frigate: { frigate: {
camera_name: 'camera-1', camera_name: 'camera-1',
}, },
camera_entity: 'camera.office',
...config, ...config,
}); });
}; };
@@ -149,7 +150,7 @@ describe('getCameraEndpoints', () => {
sign: true, sign: true,
}, },
webrtcCard: { webrtcCard: {
endpoint: 'camera-1', endpoint: 'camera.office',
}, },
}); });
}); });
@@ -313,6 +313,20 @@ describe('GenericCameraManagerEngine', () => {
}, },
}); });
}); });
it('for webrtc-card', () => {
expect(
createEngine().getCameraEndpoints(
createGenericCameraConfig({
camera_entity: 'camera.office',
}),
),
).toEqual({
webrtcCard: {
endpoint: 'camera.office',
},
});
});
}); });
it('should execute PTZ action', () => { it('should execute PTZ action', () => {