Skip to content

Commit a2aa7e8

Browse files
[AND-549] Improve call rejection/decline/timeout flow by fixing coroutines scope usage (#1420)
* fix: Run the timeout timer in user scope instead of call scope. As Calls are cleaned up when they are left * fix: defer supervisorJob.cancel() until all child jobs complete Replaces direct supervisorJob.cancel() with graceful shutdown using join() inside UserScope(ClientScope()). Prevents abrupt termination of active coroutines * fix: defer supervisorJob.cancel() until all child jobs complete Replaces direct supervisorJob.cancel() with graceful shutdown using join() inside UserScope(ClientScope()). Prevents abrupt termination of active coroutines * chore: refactor --------- Co-authored-by: Aleksandar Apostolov <[email protected]>
1 parent d438842 commit a2aa7e8

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/Call.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ import io.getstream.video.android.core.model.SortField
7777
import io.getstream.video.android.core.model.UpdateUserPermissionsData
7878
import io.getstream.video.android.core.model.VideoTrack
7979
import io.getstream.video.android.core.model.toIceServer
80+
import io.getstream.video.android.core.socket.common.scope.ClientScope
81+
import io.getstream.video.android.core.socket.common.scope.UserScope
8082
import io.getstream.video.android.core.utils.AtomicUnitCall
8183
import io.getstream.video.android.core.utils.RampValueUpAndDownHelper
8284
import io.getstream.video.android.core.utils.safeCallWithDefault
@@ -1223,12 +1225,20 @@ public class Call(
12231225
fun cleanup() {
12241226
// monitor.stop()
12251227
session?.cleanup()
1226-
supervisorJob.cancel()
1228+
shutDownJobsGracefully()
12271229
callStatsReportingJob?.cancel()
12281230
mediaManager.cleanup()
12291231
session = null
12301232
}
12311233

1234+
// This will allow the Rest APIs to be executed which are in queue before leave
1235+
private fun shutDownJobsGracefully() {
1236+
UserScope(ClientScope()).launch {
1237+
supervisorJob.children.forEach { it.join() }
1238+
supervisorJob.cancel()
1239+
}
1240+
}
1241+
12321242
suspend fun ring(): Result<GetCallResponse> {
12331243
logger.d { "[ring] #ringing; no args" }
12341244
return clientImpl.ring(type, id)

stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/CallState.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ import io.getstream.video.android.core.model.VisibilityOnScreenState
103103
import io.getstream.video.android.core.permission.PermissionRequest
104104
import io.getstream.video.android.core.pinning.PinType
105105
import io.getstream.video.android.core.pinning.PinUpdateAtTime
106+
import io.getstream.video.android.core.socket.common.scope.ClientScope
107+
import io.getstream.video.android.core.socket.common.scope.UserScope
106108
import io.getstream.video.android.core.sorting.SortedParticipantsState
107109
import io.getstream.video.android.core.utils.mapState
108110
import io.getstream.video.android.core.utils.toUser
@@ -1138,7 +1140,7 @@ public class CallState(
11381140

11391141
private fun startRingingTimer() {
11401142
ringingTimerJob?.cancel()
1141-
ringingTimerJob = scope.launch {
1143+
ringingTimerJob = UserScope(ClientScope()).launch {
11421144
val autoCancelTimeout = settings.value?.ring?.autoCancelTimeoutMs
11431145

11441146
if (autoCancelTimeout != null && autoCancelTimeout > 0) {

0 commit comments

Comments
 (0)