Skip to content

Commit

Permalink
fix: Correctly detect configuration for the webrtc-card live provid…
Browse files Browse the repository at this point in the history
…er (#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>
```
  • Loading branch information
dermotduffy authored Jan 22, 2025
1 parent 0212840 commit 805a211
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
14 changes: 0 additions & 14 deletions src/camera-manager/frigate/engine-frigate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 go2rtc = getDefaultGo2RTCEndpoint(cameraConfig, {
url:
Expand All @@ -1010,14 +998,12 @@ export class FrigateCameraManagerEngine
stream: cameraConfig.go2rtc?.stream ?? cameraConfig.frigate.camera_name,
});
const jsmpeg = getJSMPEG();
const webrtcCard = getWebRTCCard();

return {
...super.getCameraEndpoints(cameraConfig, context),
...(ui && { ui: ui }),
...(go2rtc && { go2rtc: go2rtc }),
...(jsmpeg && { jsmpeg: jsmpeg }),
...(webrtcCard && { webrtcCard: webrtcCard }),
};
}

Expand Down
13 changes: 11 additions & 2 deletions src/camera-manager/generic/engine-generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,19 @@ export class GenericCameraManagerEngine implements CameraManagerEngine {
cameraConfig: CameraConfig,
_context?: CameraEndpointsContext,
): 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);
return go2rtc
const webrtcCard = getWebRTCCard();

return go2rtc || webrtcCard
? {
go2rtc: go2rtc,
...(go2rtc && { go2rtc: go2rtc }),
...(webrtcCard && { webrtcCard: webrtcCard }),
}
: null;
}
Expand Down
10 changes: 5 additions & 5 deletions src/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ class FrigateCard extends LitElement {
: undefined}
.deviceRegistryManager=${this._controller.getDeviceRegistryManager()}
></frigate-card-views>
${
// Keep message rendering to last to show messages that may have been
// generated during the render.
renderMessage(this._controller.getMessageManager().getMessage())
}
${this._controller.getMessageManager().hasMessage()
? // Keep message rendering to last to show messages that may have been
// generated during the render.
renderMessage(this._controller.getMessageManager().getMessage())
: ''}
</div>
${this._renderMenuStatusContainer('bottom')}
${this._config?.elements
Expand Down
4 changes: 1 addition & 3 deletions src/components/live/providers/webrtc-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ export class FrigateCardLiveWebRTCCard
...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;
config.entity = this.cameraEndpoints.webrtcCard.endpoint;
}
webrtc.setConfig(config);
webrtc.hass = this.hass;
Expand Down
3 changes: 2 additions & 1 deletion tests/camera-manager/frigate/engine-frigate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const createFrigateCameraConfig = (config?: RawFrigateCardConfig): CameraConfig
frigate: {
camera_name: 'camera-1',
},
camera_entity: 'camera.office',
...config,
});
};
Expand Down Expand Up @@ -149,7 +150,7 @@ describe('getCameraEndpoints', () => {
sign: true,
},
webrtcCard: {
endpoint: 'camera-1',
endpoint: 'camera.office',
},
});
});
Expand Down
14 changes: 14 additions & 0 deletions tests/camera-manager/generic/engine-generic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 805a211

Please sign in to comment.