Skip to main content
srtc.Channel represents a joined channel connection. It’s created with await Channel.join(...), supports async with, and leaves the channel automatically on exit. One process can hold multiple Channel objects at the same time, independent of each other. Call every method within the asyncio event loop. On failure, it raises srtc.SdkError.

Lifecycle

Channel.join

Joins a channel and returns once the connection is established. Raises: SdkError. Common ones include an invalid token (1021 / 1032), the concurrency limit being reached (1033), and no available node (1034 / 1035); see Error codes.

leave

Leaves the channel and releases resources. Safe to call more than once; with async with, it’s called automatically on exit.

wait_closed

Waits until the channel is fully disconnected (leaving voluntarily, being removed from the channel, being replaced by another session with the same uid, the channel being destroyed, and so on), and returns the disconnect reason. Suitable for services that “keep running until the channel ends”:
Brief disconnects caused by network jitter are reconnected automatically by the SDK; on_connection_state(RECONNECTING) fires during that time, and wait_closed doesn’t end. It returns only when reconnection is abandoned and the channel is fully left.

closed

Whether the channel is fully disconnected.

disconnect_reason

The disconnect reason; None when not disconnected.

Querying info

The following properties read the local cache without going over the network, so you can call them at any time.

Subscribing

When auto_subscribe_audio / auto_subscribe_video is enabled, you don’t need to subscribe manually.

subscribe_audio / subscribe_video

Subscribes to one remote audio / video track and returns after server negotiation completes. uid and track_id come from the on_track_added event or UserInfo.stream_tracks. To subscribe to the channel’s composite stream, pass srtc.MCU_PUBLISHER_UID as uid, and srtc.TRACK_AMCU_ID (audio) or srtc.TRACK_MCU_ID (video) as track_id.
To “hear the whole channel”, use auto_subscribe_audio=True to receive each user’s audio separately; don’t subscribe to the audio composite stream: it contains the agent’s own voice and causes echo.

unsubscribe

Unsubscribes.

request_key_frame

Asks the remote video to send a key frame immediately; the SDK internally limits this to at most once per second. When decode_video is on, the SDK requests one automatically on decoding errors, so you usually don’t need to call it manually.

switch_layer

When the remote side publishes multi-layer (simulcast) video, switches the subscribed layer manually; the result is notified through on_layer_switched.

Publishing

publish_audio

Publishes one audio track and returns an AudioTrack; then push data with await track.write(pcm). Raises: SdkError, such as publishing negotiation failure (180300) or timeout (180302).

unpublish

Unpublishes. Audio not yet sent is discarded.

Consuming media data

Choose either approach: implement on_audio_frame / on_video_frame in ChannelHandler, or use the async for below. The latter fits linear AI processing flows better.

audio_frames

Yields remote audio from all subscribed tracks frame by frame (use frame.uid to tell speakers apart), in the audio_format given when joining. Iteration ends naturally after the channel disconnects.

video_frames

Yields remote video from all subscribed tracks frame by frame.
When consumption can’t keep up, the SDK drops the oldest frames (the audio buffer holds about 10 seconds, video 60 frames), so latency doesn’t grow without bound. You can run multiple async for loops at the same time, and each one gets all frames.