diff --git a/nestsClient/src/commonMain/kotlin/com/vitorpamplona/nestsclient/ReconnectingNestsListener.kt b/nestsClient/src/commonMain/kotlin/com/vitorpamplona/nestsclient/ReconnectingNestsListener.kt index 3403c4d69..e3686e4ec 100644 --- a/nestsClient/src/commonMain/kotlin/com/vitorpamplona/nestsclient/ReconnectingNestsListener.kt +++ b/nestsClient/src/commonMain/kotlin/com/vitorpamplona/nestsclient/ReconnectingNestsListener.kt @@ -27,6 +27,7 @@ import com.vitorpamplona.nestsclient.transport.WebTransportFactory import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job +import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.delay import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow @@ -250,7 +251,16 @@ private class ReconnectingHandle( activeListener.value ?: error("no live session — wait for state == Connected before subscribing") - val frames = MutableSharedFlow(extraBufferCapacity = SUBSCRIBE_BUFFER) + // DROP_OLDEST so a stalled consumer doesn't back-pressure the + // pump → underlying handle → relay. For Opus audio the user + // wants playback to stay "live" rather than catch up on + // minutes-stale buffered frames after a UI hiccup or + // foreground/background transition. + val frames = + MutableSharedFlow( + extraBufferCapacity = SUBSCRIBE_BUFFER, + onBufferOverflow = BufferOverflow.DROP_OLDEST, + ) val liveHandleRef = AtomicReference(null) // Re-subscribe pump: every time activeListener changes, drop