Skip to content

Commit

Permalink
Init StreamVideo in onPreCreate if needed (#1121)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleksandar Apostolov <[email protected]>
  • Loading branch information
liviu-timar and aleksandar-apostolov authored Jun 27, 2024
1 parent 0f8c78c commit 869b2cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package io.getstream.video.android

import android.content.Intent
import android.os.Bundle
import android.os.PersistableBundle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
Expand All @@ -28,12 +30,16 @@ import io.getstream.result.onSuccessSuspend
import io.getstream.video.android.compose.ui.ComposeStreamCallActivity
import io.getstream.video.android.compose.ui.StreamCallActivityComposeDelegate
import io.getstream.video.android.core.Call
import io.getstream.video.android.core.StreamVideo
import io.getstream.video.android.datastore.delegate.StreamUserDataStore
import io.getstream.video.android.ui.call.CallScreen
import io.getstream.video.android.ui.common.StreamActivityUiDelegate
import io.getstream.video.android.ui.common.StreamCallActivity
import io.getstream.video.android.ui.common.StreamCallActivityConfiguration
import io.getstream.video.android.ui.common.util.StreamCallActivityDelicateApi
import io.getstream.video.android.util.FullScreenCircleProgressBar
import io.getstream.video.android.util.StreamVideoInitHelper
import kotlinx.coroutines.runBlocking

@OptIn(StreamCallActivityDelicateApi::class)
class CallActivity : ComposeStreamCallActivity() {
Expand All @@ -42,6 +48,16 @@ class CallActivity : ComposeStreamCallActivity() {
override val configuration: StreamCallActivityConfiguration =
StreamCallActivityConfiguration(closeScreenOnCallEnded = false)

@StreamCallActivityDelicateApi
override fun onPreCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
runBlocking {
if (!StreamVideo.isInstalled) {
runBlocking { StreamVideoInitHelper.reloadSdk(StreamUserDataStore.instance()) }
}
}
super.onPreCreate(savedInstanceState, persistentState)
}

private class StreamDemoUiDelegate : StreamCallActivityComposeDelegate() {

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch

/**
* Main entry point for remote / local configuration
Expand Down Expand Up @@ -88,7 +87,7 @@ object AppConfig {
* @param coroutineScope the scope used to run [onLoaded]
*/
@OptIn(DelicateCoroutinesApi::class)
fun load(
suspend fun load(
context: Context,
coroutineScope: CoroutineScope = GlobalScope,
onLoaded: suspend () -> Unit = {},
Expand All @@ -103,10 +102,7 @@ object AppConfig {
}
val which = selectedEnvironment ?: availableEnvironments[0]
selectEnv(which)
currentEnvironment.value = which
coroutineScope.launch {
onLoaded()
}
onLoaded()
} catch (e: Exception) {
logger.e(e) { "Failed to parse remote config. Deeplinks not working!" }
}
Expand Down

0 comments on commit 869b2cc

Please sign in to comment.