Load Reverb config from mobile bootstrap

This commit is contained in:
admin
2026-07-02 15:33:42 +02:00
parent 64d6f5a41d
commit b6fcd990b9
4 changed files with 22 additions and 9 deletions
+2 -2
View File
@@ -33,8 +33,8 @@ android {
applicationId = "pl.firmatpp.kierowca" applicationId = "pl.firmatpp.kierowca"
minSdk = 26 minSdk = 26
targetSdk = 35 targetSdk = 35
versionCode = 33 versionCode = 34
versionName = "1.0.32" versionName = "1.0.33"
setProperty("archivesBaseName", "pl.firmatpp.kierowca") setProperty("archivesBaseName", "pl.firmatpp.kierowca")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
@@ -47,6 +47,7 @@ data class BootstrapResponse(
val routes: RoutesBucketDto, val routes: RoutesBucketDto,
val driverAppSettings: DriverAppSettingsDto?, val driverAppSettings: DriverAppSettingsDto?,
val notificationPreferences: NotificationPreferencesDto? = null, val notificationPreferences: NotificationPreferencesDto? = null,
val realtime: RealtimeConfigDto? = null,
val syncState: SyncStateResponse? = null, val syncState: SyncStateResponse? = null,
) )
@@ -71,6 +72,12 @@ data class NotificationPreferencesDto(
val notifyNewRoutes: Boolean = false, val notifyNewRoutes: Boolean = false,
) )
data class RealtimeConfigDto(
val reverbEnabled: Boolean = false,
val reverbAppKey: String? = null,
val reverbWsBaseUrl: String? = null,
)
data class RoutesBucketDto( data class RoutesBucketDto(
val today: List<DriverRouteDto> = emptyList(), val today: List<DriverRouteDto> = emptyList(),
) )
@@ -15,8 +15,8 @@ import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import okhttp3.WebSocket import okhttp3.WebSocket
import okhttp3.WebSocketListener import okhttp3.WebSocketListener
import pl.firmatpp.kierowca.BuildConfig
import pl.firmatpp.kierowca.data.DriverRepository import pl.firmatpp.kierowca.data.DriverRepository
import pl.firmatpp.kierowca.data.model.RealtimeConfigDto
class DriverLiveSyncClient( class DriverLiveSyncClient(
private val repository: DriverRepository, private val repository: DriverRepository,
@@ -29,16 +29,21 @@ class DriverLiveSyncClient(
private val started = AtomicBoolean(false) private val started = AtomicBoolean(false)
private var webSocket: WebSocket? = null private var webSocket: WebSocket? = null
private var driverId: String? = null private var driverId: String? = null
private var realtimeConfig: RealtimeConfigDto? = null
private var socketId: String? = null private var socketId: String? = null
private var heartbeatJob: Job? = null private var heartbeatJob: Job? = null
fun start(driverId: String) { fun start(driverId: String, config: RealtimeConfigDto?) {
if (BuildConfig.REVERB_APP_KEY.isBlank()) return 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 this.driverId = driverId
if (!started.compareAndSet(false, true)) return if (!started.compareAndSet(false, true)) return
val wsUrl = BuildConfig.REVERB_WS_BASE_URL.trimEnd('/') + val wsUrl = wsBaseUrl.trimEnd('/') +
"/" + BuildConfig.REVERB_APP_KEY + "/" + appKey +
"?protocol=7&client=android&version=1.0&flash=false" "?protocol=7&client=android&version=1.0&flash=false"
webSocket = client.newWebSocket( webSocket = client.newWebSocket(
@@ -72,6 +77,7 @@ class DriverLiveSyncClient(
webSocket?.close(1000, "logout") webSocket?.close(1000, "logout")
webSocket = null webSocket = null
driverId = null driverId = null
realtimeConfig = null
socketId = null socketId = null
} }
@@ -146,7 +152,7 @@ class DriverLiveSyncClient(
scope.launch { scope.launch {
delay(5_000) delay(5_000)
if (!started.get() && driverId == id) { if (!started.get() && driverId == id) {
start(id) start(id, realtimeConfig)
} }
} }
} }
@@ -168,7 +168,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
) )
} }
response.session.driver.id.let { driverId -> response.session.driver.id.let { driverId ->
liveSyncClient.start(driverId) liveSyncClient.start(driverId, response.realtime)
registerPushTokenIfAvailable(driverId) registerPushTokenIfAvailable(driverId)
} }
}.onFailure { throwable -> }.onFailure { throwable ->