Load Reverb config from mobile bootstrap

This commit is contained in:
admin
2026-07-02 15:33:42 +02:00
parent 64d6f5a41d
commit ca512f5993
4 changed files with 22 additions and 9 deletions
@@ -15,8 +15,8 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.WebSocket
import okhttp3.WebSocketListener
import pl.firmatpp.kierowca.BuildConfig
import pl.firmatpp.kierowca.data.DriverRepository
import pl.firmatpp.kierowca.data.model.RealtimeConfigDto
class DriverLiveSyncClient(
private val repository: DriverRepository,
@@ -29,16 +29,21 @@ class DriverLiveSyncClient(
private val started = AtomicBoolean(false)
private var webSocket: WebSocket? = null
private var driverId: String? = null
private var realtimeConfig: RealtimeConfigDto? = null
private var socketId: String? = null
private var heartbeatJob: Job? = null
fun start(driverId: String) {
if (BuildConfig.REVERB_APP_KEY.isBlank()) return
fun start(driverId: String, config: RealtimeConfigDto?) {
val appKey = config?.reverbAppKey?.takeIf { it.isNotBlank() } ?: return
val wsBaseUrl = config.reverbWsBaseUrl?.takeIf { it.isNotBlank() } ?: return
if (!config.reverbEnabled) return
realtimeConfig = config
this.driverId = driverId
if (!started.compareAndSet(false, true)) return
val wsUrl = BuildConfig.REVERB_WS_BASE_URL.trimEnd('/') +
"/" + BuildConfig.REVERB_APP_KEY +
val wsUrl = wsBaseUrl.trimEnd('/') +
"/" + appKey +
"?protocol=7&client=android&version=1.0&flash=false"
webSocket = client.newWebSocket(
@@ -72,6 +77,7 @@ class DriverLiveSyncClient(
webSocket?.close(1000, "logout")
webSocket = null
driverId = null
realtimeConfig = null
socketId = null
}
@@ -146,7 +152,7 @@ class DriverLiveSyncClient(
scope.launch {
delay(5_000)
if (!started.get() && driverId == id) {
start(id)
start(id, realtimeConfig)
}
}
}