Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
Bridge buffers: drop oldest, keep the newest state
liliapkc395c83cf10c
diff --git a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/bridge/Bridge.kt b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/bridge/Bridge.ktindex 3f742e2e..4ba8d2b1 100644--- a/base/api-spotify/src/main/kotlin/app/myspoti/spotify/bridge/Bridge.kt+++ b/base/api-spotify/src/main/kotlin/app/myspoti/spotify/bridge/Bridge.kt@@ -1,5 +1,6 @@package app.myspoti.spotify.bridge+import kotlinx.coroutines.channels.BufferOverflowimport kotlinx.coroutines.CompletableDeferredimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.flow.MutableSharedFlow@@ -32,8 +33,9 @@ class Bridge(private val host: BridgeHost, scope: CoroutineScope) {private val _ready = MutableStateFlow(false)val ready: StateFlow<Boolean> = _ready- /** `state` and `queue` messages, raw payload of each. */- private val _events = MutableSharedFlow<Pair<String, JsonElement>>(extraBufferCapacity = 64)+ /** `state` and `queue` messages, raw payload of each. DROP_OLDEST: under a stall the+ * newest state is the only one that matters; SUSPEND would drop exactly that one. */+ private val _events = MutableSharedFlow<Pair<String, JsonElement>>(extraBufferCapacity = 64, onBufferOverflow = BufferOverflow.DROP_OLDEST)val events: SharedFlow<Pair<String, JsonElement>> = _eventsinit {diff --git a/base/host-android/src/main/kotlin/app/myspoti/host/android/WebPlayerHost.kt b/base/host-android/src/main/kotlin/app/myspoti/host/android/WebPlayerHost.ktindex 5e6003d0..9d27c824 100644--- a/base/host-android/src/main/kotlin/app/myspoti/host/android/WebPlayerHost.kt+++ b/base/host-android/src/main/kotlin/app/myspoti/host/android/WebPlayerHost.kt@@ -18,6 +18,7 @@ import android.webkit.WebViewClientimport app.myspoti.spotify.bridge.AdBlockimport app.myspoti.spotify.bridge.BridgeHostimport kotlinx.coroutines.CompletableDeferred+import kotlinx.coroutines.channels.BufferOverflowimport kotlinx.coroutines.flow.MutableSharedFlowimport kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.SharedFlow@@ -36,7 +37,9 @@ import java.io.ByteArrayInputStreamclass WebPlayerHost(context: Context) : BridgeHost {private val main = Handler(Looper.getMainLooper())- private val _messages = MutableSharedFlow<String>(extraBufferCapacity = 256)+ // DROP_OLDEST: tryEmit under a main-thread stall must not drop the newest+ // state/result (the default SUSPEND overflow drops exactly the new value).+ private val _messages = MutableSharedFlow<String>(extraBufferCapacity = 256, onBufferOverflow = BufferOverflow.DROP_OLDEST)override val messages: SharedFlow<String> = _messagesprivate val _url = MutableStateFlow("")