Repository navigation
fix(camera): attach the WebRTC provider once the stream source is known - #38
Merged
Merged
Conversation
v0.8.0 registered the go2rtc streams correctly but nothing ever consumed them: Companion played H.265 directly and Chrome fell back to the still-image proxy at ~1 fps, both after a few seconds of buffering — the HLS path, not WebRTC. Camera.async_refresh_providers() only runs from async_internal_added_to_hass, when a provider registers/unregisters, or when the STREAM feature bit flips. At entity-add time XMEyeCoordinator.async_setup() has only scheduled _connection_loop() as a background task, so coordinator.connected is still False — and stream_source() returned None on exactly that condition. async_get_supported_provider() therefore got None, no provider was attached, and camera_capabilities stayed HLS-only for the life of the entity. The after_dependencies on go2rtc added in v0.8.0 made this worse by removing the second chance the provider's own registration used to give. - Drop the `connected` guard from stream_source(); RTSP does not go through the DVRIP alarm socket. - Refresh providers at the end of _probe_urls(), once the real URL and codec are known. - Refresh providers when privacy is toggled, since privacy nulls the stream source and HA does not re-evaluate that on its own. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011UpaDKeLbpQB7EapQBpKoJ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #37. The go2rtc registration in v0.8.0 works — confirmed in the field, all three H.265 channels present with both producers:
But nothing consumed them. Companion played H.265 directly, Chrome fell back to the still-image proxy at ~1 fps, and both took a few seconds to start — the signature of the HLS path, not WebRTC.
Cause
Camera.async_refresh_providers()only runs fromasync_internal_added_to_hass(), when a provider registers/unregisters, or when theCameraEntityFeature.STREAMbit flips. At that first moment:XMEyeCoordinator.async_setup()schedules_connection_loop()as a background task and returns immediately, socoordinator.connectedis stillFalse;stream_source()hadif not self._coordinator.connected: return None;async_get_supported_provider()getsNoneand returnsNone→_webrtc_providerstaysNone→camera_capabilitiesis{HLS}for the life of the entity.The
after_dependencies: ["go2rtc"]added in #37 made it worse: previously, if thego2rtcintegration set up after the cameras, itsasync_register_webrtc_provider()fired_async_refresh_providers(hass)and gave a second chance to attach.Fix
connectedguard fromstream_source()— RTSP does not go through the DVRIP alarm socket. This was already listed as an open item indocs/STREAM_INVESTIGATION.md§7.await self.async_refresh_providers()at the end of_probe_urls(), once the real URL and codec are known.stream_source(), and HA does not re-check that on its own.Verifying
With the HA frontend open, in the browser console:
Before:
{frontend_stream_types: ["hls"]}. After:["hls", "webrtc"].Then the live view should start near-instantly in Chrome, and
/api/streamsshould show a consumer onxmeye_…_cameraplus the ffmpeg producer dialled.🤖 Generated with Claude Code
https://claude.ai/code/session_011UpaDKeLbpQB7EapQBpKoJ