Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ca512f5993 |
@@ -33,8 +33,8 @@ android {
|
||||
applicationId = "pl.firmatpp.kierowca"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
versionCode = 33
|
||||
versionName = "1.0.32"
|
||||
versionCode = 34
|
||||
versionName = "1.0.33"
|
||||
setProperty("archivesBaseName", "pl.firmatpp.kierowca")
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ data class BootstrapResponse(
|
||||
val routes: RoutesBucketDto,
|
||||
val driverAppSettings: DriverAppSettingsDto?,
|
||||
val notificationPreferences: NotificationPreferencesDto? = null,
|
||||
val realtime: RealtimeConfigDto? = null,
|
||||
val syncState: SyncStateResponse? = null,
|
||||
)
|
||||
|
||||
@@ -71,6 +72,12 @@ data class NotificationPreferencesDto(
|
||||
val notifyNewRoutes: Boolean = false,
|
||||
)
|
||||
|
||||
data class RealtimeConfigDto(
|
||||
val reverbEnabled: Boolean = false,
|
||||
val reverbAppKey: String? = null,
|
||||
val reverbWsBaseUrl: String? = null,
|
||||
)
|
||||
|
||||
data class RoutesBucketDto(
|
||||
val today: List<DriverRouteDto> = emptyList(),
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ class DriverViewModel(application: Application) : AndroidViewModel(application)
|
||||
)
|
||||
}
|
||||
response.session.driver.id.let { driverId ->
|
||||
liveSyncClient.start(driverId)
|
||||
liveSyncClient.start(driverId, response.realtime)
|
||||
registerPushTokenIfAvailable(driverId)
|
||||
}
|
||||
}.onFailure { throwable ->
|
||||
|
||||
Reference in New Issue
Block a user