Can a client participant unsubscribe from a track ...
# ask-ai
f
Can a client participant unsubscribe from a track natively instead of requesting the LiveKit server? Thinking about how to block incoming audio under unstable network conditions where outbound messages can't be sent reliably.
t
Thanks for reaching out, Anish. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
A client participant cannot unsubscribe from a track natively without requesting the LiveKit server. However, there is an alternative approach that may suit your needs. • Unsubscribing: This requires server communication. For example, in the JavaScript SDK, the
setSubscribed
method sends an
UpdateSubscription
message to the server. Similarly, in the Flutter SDK, the
unsubscribe()
method sends a subscription update to the server. • Disabling: This can be done natively on the client without server negotiation. When a track is disabled, the participant will not receive any new data for that track. If the track is re-enabled, new data will be received again. This is useful for optimizing bandwidth consumption, especially under unstable network conditions. If your goal is to block incoming audio during unstable network conditions without relying on outbound messages, you can use the disable functionality instead of unsubscribing. Sources: Subscribing to tracks | LiveKit Docs | Subscribing to tracks | LiveKit Docs | src/room/track/RemoteTrackPublication.ts | lib/src/publication/remote.dart
f
If a client mutes it's own mic, will there still be empty audio frames sent to other participants?
t
When you mute your microphone in LiveKit, there are actually a couple of ways it can happen, and each approach works a bit differently. Let me break it down for you in a friendly way! ### Device-Level Muting - If you mute the microphone at the device level (like using
setMicrophoneMute()
in the Android SDK), empty audio frames are still sent to other participants. Think of it like sending a blank postcard - the connection stays open, but no actual sound comes through. ### Track-Level Muting - When you mute at the track level (using the
TrackPublication.muted
property), data transmission stops entirely. This is like putting your conversation on pause - it's more efficient and helps save on data. ### Server-Side Behavior - The cool thing is, when a track is muted, LiveKit's server actually sends a few silence frames to make sure everything stays smooth. It's like making sure the line doesn't go completely dead during a phone call. Pro tip: If you're looking to be smart about data usage, track-level muting is definitely the way to go. It's like having a more precise volume control for your conversation. Sources: stream_audio.py | Publishing tracks | LiveKit Docs | pkg/rtc/room_test.go | livekit-android-sdk/src/main/java/io/livekit/android/room/Room.kt
f
Which one of these two operations requires a negotiation with the LiveKit server?
t
Hey there! Let me break down track muting for you in a friendly way. When you mute a track, the LiveKit server gets a heads-up and sends out a
TrackMuted
event to everyone in the room. Think of it like telling everyone in a group chat that someone's mic is now off - super helpful for keeping everyone in sync. Now, if you're just wanting to mute a track for yourself (like personal listening preferences), that's even easier. These operations happen right on your device without needing to chat with the server. Pretty neat, right? Got more questions about how this all works? I'm totally here to help - just ask!
f
Can you point me to where device-level muting happens and confirm that empty audio frames are still sent to other participants?
t
Hey there! 👋 Let me break down how device-level muting works in LiveKit in a way that's super easy to understand. When you mute your microphone, LiveKit doesn't just cut the connection - it's smarter than that! Think of it like putting a soft blanket over your mic. In the Android SDK, for example, the
setMicrophoneMute()
function doesn't disconnect you, but instead sends completely silent audio frames. It's like whispering instead of hanging up the phone. This approach is pretty consistent across different platforms. Whether you're using Android, Python, or other SDKs, muting means you're still connected, just sending "quiet" data. On the server side, LiveKit keeps things smooth by sending blank frames, which helps prevent any weird audio glitches when you unmute. Got questions? I'm totally here to help! Just shoot me a message, and I'll be happy to explain more. 😊 Sources: livekit-android-sdk/src/main/java/io/livekit/android/room/track/LocalTrackP... | stream_audio.py | pkg/rtc/room_test.go | Publishing tracks | LiveKit Docs
f
But what happens if its unable to reach the LiveKit server reliably? class LocalTrackPublication( info: LivekitModels.TrackInfo, track: Track, participant: LocalParticipant, val options: TrackPublishOptions, ) : TrackPublication(info, track, participant) { /** * Mute or unmute the current track. Muting the track would stop audio or video from being * transmitted to the server, and notify other participants in the room. */ override var muted: Boolean get() = super.muted public set(muted) { if (muted == this.muted) { return } val mediaTrack = track ?: return mediaTrack.enabled = !muted super.muted = muted // send updates to server val participant = this.participant.get() as? LocalParticipant ?: return participant.engine.updateMuteStatus(sid, muted) if (muted) { participant.onTrackMuted(this) } else { participant.onTrackUnmuted(this) } } }
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!