Skip to main content
Subclass srtc.ChannelHandler, override the methods you need, and pass it in with Channel.join(token, handler=...). Events you don’t override are ignored.
  • All methods are called on the asyncio event loop thread, so no locking is needed
  • async methods are scheduled as Tasks and don’t block subsequent events
  • Exceptions raised in the methods are logged to the srtc logger and don’t interrupt the SDK

Event list

on_active_speakers, on_connection_quality, and on_layer_switched depend on the channel’s media streaming engine and don’t fire in some deployments. Don’t make your business logic rely on them always arriving.

Ordering and timing

User events and track events are called one at a time in the order the SDK receives the signaling (since 0.2.1; earlier versions don’t guarantee ordering, so on_track_added could arrive before on_user_join). Keep two things in mind:
  • When a handler method is async def, the coroutines start in order but interleave once they hit an await. Put logic that needs strict ordering before the first await, or queue the work yourself
  • Duplicate events can still arrive in cases such as network reconnection, so keep handling them idempotently by uid / track id
  • Users and tracks already in the channel before you joined don’t trigger on_user_join / on_track_added; read ch.users after joining
  • on_audio_frame / on_video_frame for the same track arrive strictly in order
  • on_audio_frame is a high-frequency event, so use a regular function and return as quickly as possible; for time-consuming processing, we recommend consuming with async for over ch.audio_frames() instead

Handling disconnects

Distinguish three cases: