Skip to content

Add WebRTC live view to intercoms and fix self-await on server-initiated close - #563

Open
cmos486 wants to merge 1 commit into
python-ring-doorbell:masterfrom
cmos486:webrtc-intercom
Open

cmos486 wants to merge 1 commit into
python-ring-doorbell:masterfrom
cmos486:webrtc-intercom

Conversation

@cmos486

@cmos486 cmos486 commented Nov 8, 2026

Copy link
Copy Markdown

Two related changes to WebRTC streams.

1. WebRTC live view for RingOther (intercoms)

Ring Intercoms use the same live_view signalling as cameras, but the WebRTC methods lived only on RingDoorBell, so RingOther couldn't start a stream. This moves them, unchanged, into a RingWebRtcMixin (ring_doorbell/webrtcdevice.py) used by both RingDoorBell and RingOther. The public API of RingDoorBell doesn't change.

Tested in the field via ring-intercom-video, which has been monkey-patching these methods onto RingOther:

  • intercom_handset_video: live video plus two-way audio.
  • intercom_handset_audio: two-way audio confirmed at the door station by two users (traces). The stock stream_options (video_enabled: true) works with an audio-only offer, so no per-kind change is needed.

2. RuntimeError: Task cannot await on itself when Ring ends a session

When Ring sends a close message, handle_close_message() runs inside the reader task and calls _close(), which ends with await read_task. That's the current task, so it raises, the exception is never retrieved, and on_message_callback never gets the close reason. In Home Assistant, the frontend then never learns that the session ended. The device-level _close_callback also re-entered close_webrtc_stream() → stream.close() and hit the same path (report with traceback).

  • _close() skips awaiting read_task when it is the current task. The reader exits on its own once the websocket is closed.
  • The _close_callback only removes the stream from _webrtc_streams, because the stream is already closing itself.

Tests

tests/test_webrtc.py: checks that both classes expose the WebRTC methods, and simulates a server close inside a reader task. That test fails on master with the RuntimeError and passes here. Full suite, ruff on the changed files and mypy all pass. (ruff check reports two existing errors in __init__.py/auth.py that this PR doesn't touch.)

🤖 Generated with Claude Code

- Move the WebRTC stream methods from RingDoorBell into RingWebRtcMixin and
  use it on RingOther too. Ring Intercoms (intercom_handset_video and
  intercom_handset_audio) use the same live_view signalling as cameras;
  verified two-way audio on both kinds.
- When Ring ends a session, RingWebRtcStream._close() runs inside the reader
  task and awaited read_task, i.e. itself, raising 'Task cannot await on
  itself' and never delivering the close reason to on_message_callback.
  Skip the await when read_task is the current task, and make the
  device-level close callback only forget the stream instead of re-entering
  close().

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants