mirror of
https://github.com/KRTirtho/spotube.git
synced 2026-11-04 10:13:59 +00:00
fix(broker): update default broker settings and improve connection error handling
This commit is contained in:
parent
14bc279653
commit
2aaa0db81e
@ -553,6 +553,7 @@
|
||||
<string name="jam_error_broker_host_empty">Broker host is empty</string>
|
||||
<string name="jam_error_connection_failed">Connection failed</string>
|
||||
<string name="jam_error_connection_lost">Connection lost</string>
|
||||
<string name="jam_error_broker_unreachable">Couldn't reach %1$s:%2$d. Check your network or pick another broker in Settings → Jam.</string>
|
||||
|
||||
<!-- Settings: Group Jam broker -->
|
||||
<string name="settings_jam_broker_content_description">Broker</string>
|
||||
|
||||
@ -33,12 +33,14 @@ import org.spotube.spotube.modules.settings.JamBroker
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.TimeoutCancellationException
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
@ -47,6 +49,7 @@ import kotlinx.serialization.json.Json
|
||||
import org.jetbrains.compose.resources.getString
|
||||
import spotube.composeapp.generated.resources.Res
|
||||
import spotube.composeapp.generated.resources.jam_error_broker_host_empty
|
||||
import spotube.composeapp.generated.resources.jam_error_broker_unreachable
|
||||
import spotube.composeapp.generated.resources.jam_error_connection_failed
|
||||
import spotube.composeapp.generated.resources.jam_error_connection_lost
|
||||
import spotube.composeapp.generated.resources.jam_error_no_broker
|
||||
@ -135,8 +138,15 @@ class JamRoomClient : KoinComponent {
|
||||
|
||||
val mqtt = startClient(broker, clientId)
|
||||
client = mqtt
|
||||
withTimeout(broker.connectionTimeoutSeconds.seconds) {
|
||||
mqtt.awaitConnectivity()
|
||||
try {
|
||||
withTimeout(broker.connectionTimeoutSeconds.seconds) {
|
||||
// connectionState replays its current value, unlike awaitConnectivity's
|
||||
// broadcast flow, which loses a CONNACK that lands before it is collected.
|
||||
mqtt.connectionState.first { it is ConnectionState.Connected }
|
||||
}
|
||||
} catch (e: TimeoutCancellationException) {
|
||||
throw IllegalStateException(
|
||||
getString(Res.string.jam_error_broker_unreachable, broker.host, broker.port), e)
|
||||
}
|
||||
_connectionError.value = null
|
||||
log.i { "Connected to ${broker.host}:${broker.port} room=$code as $clientId" }
|
||||
|
||||
@ -98,9 +98,9 @@ data class UserSettings(
|
||||
@Serializable
|
||||
data class JamBroker(
|
||||
val name: String = "",
|
||||
val host: String = "test.mosquitto.org",
|
||||
val port: Int = 1883,
|
||||
val useTls: Boolean = false,
|
||||
val host: String = "broker.hivemq.com",
|
||||
val port: Int = 8883,
|
||||
val useTls: Boolean = true,
|
||||
val username: String? = null,
|
||||
val password: String? = null,
|
||||
val clientIdPrefix: String = "spotube",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user