Update go2rtc stream if stream_source is not matching (#129804)
This commit is contained in:
parent
57eeaf1f75
commit
df35c8e707
3 changed files with 24 additions and 9 deletions
|
@ -203,15 +203,17 @@ class WebRTCProvider(CameraWebRTCProvider):
|
|||
self._session, self._url, source=camera.entity_id
|
||||
)
|
||||
|
||||
if not (stream_source := await camera.stream_source()):
|
||||
send_message(
|
||||
WebRTCError("go2rtc_webrtc_offer_failed", "Camera has no stream source")
|
||||
)
|
||||
return
|
||||
|
||||
streams = await self._rest_client.streams.list()
|
||||
if camera.entity_id not in streams:
|
||||
if not (stream_source := await camera.stream_source()):
|
||||
send_message(
|
||||
WebRTCError(
|
||||
"go2rtc_webrtc_offer_failed", "Camera has no stream source"
|
||||
)
|
||||
)
|
||||
return
|
||||
|
||||
if (stream := streams.get(camera.entity_id)) is None or not any(
|
||||
stream_source == producer.url for producer in stream.producers
|
||||
):
|
||||
await self._rest_client.streams.add(camera.entity_id, stream_source)
|
||||
|
||||
@callback
|
||||
|
|
|
@ -21,7 +21,8 @@ def rest_client() -> Generator[AsyncMock]:
|
|||
patch("homeassistant.components.go2rtc.server.Go2RtcRestClient", mock_client),
|
||||
):
|
||||
client = mock_client.return_value
|
||||
client.streams = Mock(spec_set=_StreamClient)
|
||||
client.streams = streams = Mock(spec_set=_StreamClient)
|
||||
streams.list.return_value = {}
|
||||
client.webrtc = Mock(spec_set=_WebRTCClient)
|
||||
yield client
|
||||
|
||||
|
|
|
@ -239,6 +239,18 @@ async def _test_setup_and_signaling(
|
|||
|
||||
rest_client.streams.add.assert_called_once_with(entity_id, "rtsp://stream")
|
||||
|
||||
# Stream exists but the source is different
|
||||
rest_client.streams.add.reset_mock()
|
||||
rest_client.streams.list.return_value = {
|
||||
entity_id: Stream([Producer("rtsp://different")])
|
||||
}
|
||||
|
||||
receive_message_callback.reset_mock()
|
||||
ws_client.reset_mock()
|
||||
await test()
|
||||
|
||||
rest_client.streams.add.assert_called_once_with(entity_id, "rtsp://stream")
|
||||
|
||||
# If the stream is already added, the stream should not be added again.
|
||||
rest_client.streams.add.reset_mock()
|
||||
rest_client.streams.list.return_value = {
|
||||
|
|
Loading…
Add table
Reference in a new issue