sparse-teacher-281
02/22/2026, 7:46 AMaudio programmaticaly/manually?
Instead of doing this?
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)tall-airline-16756
02/22/2026, 7:46 AMtall-airline-16756
02/22/2026, 7:46 AMctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)). You can do that by disabling auto-subscribe at connect time and then subscribing to audio publications yourself when they appear. Below is a concise pattern that gives you full control.
1. Disable auto-subscribe when connecting
await ctx.connect(auto_subscribe=False)
1. Subscribe when a track is published
@ctx.room.on("track_published")
def on_track_published(publication: RemoteTrackPublication, participant: RemoteParticipant):
if publication.kind == TrackKind.AUDIO:
# subscribe asynchronously so you don't block the event handler
asyncio.create_task(publication.set_subscribed(True))
1. Subscribe to already-published tracks when a participant joins
@ctx.room.on("participant_connected")
def on_participant_connected(participant: RemoteParticipant):
for publication in participant.track_publications.values():
if publication.kind == TrackKind.AUDIO:
asyncio.create_task(publication.set_subscribed(True))
Notes and tips
• Use publication.set_subscribed(True) to toggle subscription on a given RemoteTrackPublication.
• Run the subscription call in a background task (e.g., asyncio.create_task) inside event handlers to avoid blocking the event loop.
• You can add custom logic (participant identity, roles, or other conditions) before calling set_subscribed(True) to control who you subscribe to.
If you’d like, tell me:
• which SDK/language you’re using if it’s not Python, and
• any selection rules (e.g., subscribe only to hosts or specific participant IDs),
and I’ll give a tailored example.
Sources: Live Conversations with AI using ChatGPT and WebRTC