Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public abstract class io/getstream/video/android/ui/common/StreamCallActivity :
public fun onIntentAction (Lio/getstream/video/android/core/Call;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;)V
public static synthetic fun onIntentAction$default (Lio/getstream/video/android/ui/common/StreamCallActivity;Lio/getstream/video/android/core/Call;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V
public fun onLastParticipant (Lio/getstream/video/android/core/Call;)V
protected fun onNewIntent (Landroid/content/Intent;)V
public fun onPause ()V
public fun onPause (Lio/getstream/video/android/core/Call;)V
public fun onPictureInPicture (Lio/getstream/video/android/core/Call;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import io.getstream.video.android.model.streamCallId
import io.getstream.video.android.ui.common.util.StreamCallActivityDelicateApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -128,6 +129,9 @@ public abstract class StreamCallActivity : ComponentActivity() {
private var callSocketConnectionMonitor: Job? = null
private lateinit var cachedCall: Call
private lateinit var config: StreamCallActivityConfiguration
private var cachedCallEventJob: Job? = null
private val supervisorJob = SupervisorJob()

protected val onSuccessFinish: suspend (Call) -> Unit = { call ->
logger.w { "The call was successfully finished! Closing activity" }
onEnded(call)
Expand Down Expand Up @@ -188,6 +192,7 @@ public abstract class StreamCallActivity : ComponentActivity() {
initializeCallOrFail(
savedInstanceState,
null,
intent,
onSuccess = { instanceState, persistentState, call, action ->
logger.d { "Calling [onCreate(Call)], because call is initialized $call" }
onIntentAction(call, action, onError = onErrorFinish) { successCall ->
Expand All @@ -214,6 +219,7 @@ public abstract class StreamCallActivity : ComponentActivity() {
initializeCallOrFail(
savedInstanceState,
persistentState,
intent,
onSuccess = { instanceState, persistedState, call, action ->
logger.d { "Calling [onCreate(Call)], because call is initialized $call" }
onIntentAction(call, action, onError = onErrorFinish) { successCall ->
Expand All @@ -230,6 +236,42 @@ public abstract class StreamCallActivity : ComponentActivity() {
)
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
/**
* Necessary because the intent is read during the activity's lifecycle methods.
*/
setIntent(intent)
when (intent.action) {
NotificationHandler.ACTION_ACCEPT_CALL -> {
// Exit case
// TODO Later

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exit the current call and join the new one. If they are different. If we are accepting the same call, do nothing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be customisable behaviour so an open function as hook should be added.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

// If already in call, then should we do nothing or allow to connect with new call
val activeCall = StreamVideo.instance().state.activeCall.value
if (activeCall != null) return

initializeCallOrFail(
null,
null,
intent,
onSuccess = { _, _, call, action ->
logger.d { "Calling [onNewIntent(intent)], because call is initialized $call, action=$action" }
onIntentAction(call, action, onError = onErrorFinish) { successCall ->
applyDashboardSettings(successCall)
}
},
onError = {
// We are not calling onErrorFinish here on purpose
// we want to crash if we cannot initialize the call
logger.e(it) { "Failed to initialize call." }
throw it
},
)
}
else -> {}
}
}

public override fun onResume() {
super.onResume()
withCachedCall {
Expand Down Expand Up @@ -816,6 +858,7 @@ public abstract class StreamCallActivity : ComponentActivity() {
private fun initializeCallOrFail(
savedInstanceState: Bundle?,
persistentState: PersistableBundle?,
intent: Intent,
onSuccess: ((Bundle?, PersistableBundle?, Call, action: String?) -> Unit)? = null,
onError: ((Exception) -> Unit)? = null,
) {
Expand All @@ -839,16 +882,20 @@ public abstract class StreamCallActivity : ComponentActivity() {
cid,
onSuccess = { call ->
cachedCall = call
lifecycleScope.launch {
cachedCallEventJob?.cancel()
cachedCallEventJob = lifecycleScope.launch(supervisorJob) {
cachedCall.events.collect { event ->
onCallEvent(cachedCall, event)
}
}
callSocketConnectionMonitor = lifecycleScope.launch(Dispatchers.IO) {
cachedCall.state.connection.collectLatest {
onConnectionEvent(call, it)

callSocketConnectionMonitor?.cancel()
callSocketConnectionMonitor =
lifecycleScope.launch(Dispatchers.IO + supervisorJob) {
cachedCall.state.connection.collectLatest {
onConnectionEvent(call, it)
}
}
}
onSuccess?.invoke(
savedInstanceState,
persistentState,
Expand All @@ -862,7 +909,7 @@ public abstract class StreamCallActivity : ComponentActivity() {

private fun withCachedCall(action: (Call) -> Unit) {
if (!::cachedCall.isInitialized) {
initializeCallOrFail(null, null, onSuccess = { _, _, call, _ ->
initializeCallOrFail(null, null, intent, onSuccess = { _, _, call, _ ->
action(call)
}, onError = {
// Call is missing, we need to crash, no other way
Expand Down