Skip to content

Media WebSocket blocking in connect_to_signaling_websocket example #1

@yew011

Description

@yew011

Summary

In the manual_start_stop_using_python/rtms.py example, the connect_to_signaling_websocket coroutine awaits the call to connect_to_media_websocket inside the signaling message loop (see around line 156). This effectively blocks the signaling loop on the media WebSocket. As a result, the signaling socket cannot respond to keep‑alive messages while the media socket is open.

Details

  • At line 156, schedule_rtms_stop is invoked to stop the RTMS after 10 seconds.
  • Within connect_to_signaling_websocket, the async for‑loop awaits connect_to_media_websocket when a successful handshake is received. This call does not return until the media WebSocket closes, which prevents the signaling loop from handling keep‑alive messages (msg_type == 12) in a timely manner.
  • In a production implementation, establishing the media WebSocket should run concurrently (e.g., via asyncio.create_task or launching a new thread) so that the signaling socket can continue processing messages.

Request

Could we update the example to reflect this behaviour? Perhaps either:

  • Add a comment explaining that developers should spawn connect_to_media_websocket as a task or thread rather than awaiting it directly; or
  • Modify the sample code to use asyncio.create_task(connect_to_media_websocket(...)) to avoid blocking the signaling socket.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions