-
Notifications
You must be signed in to change notification settings - Fork 56
Leave an active call when Telecom puts it to inactive or hold #1622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,7 @@ import io.getstream.video.android.core.notifications.IncomingNotificationData | |
| import io.getstream.video.android.core.notifications.NotificationType | ||
| import io.getstream.video.android.core.notifications.internal.service.CallServiceConfig | ||
| import io.getstream.video.android.core.notifications.internal.telecom.jetpack.JetpackTelecomRepository | ||
| import io.getstream.video.android.core.notifications.internal.telecom.jetpack.TelecomCall | ||
| import io.getstream.video.android.core.permission.PermissionRequest | ||
| import io.getstream.video.android.core.pinning.PinType | ||
| import io.getstream.video.android.core.pinning.PinUpdateAtTime | ||
|
|
@@ -130,6 +131,7 @@ import io.getstream.video.android.core.utils.toUser | |
| import io.getstream.video.android.model.StreamCallId | ||
| import io.getstream.video.android.model.User | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.Dispatchers | ||
| import kotlinx.coroutines.Job | ||
| import kotlinx.coroutines.channels.awaitClose | ||
| import kotlinx.coroutines.currentCoroutineContext | ||
|
|
@@ -145,6 +147,7 @@ import kotlinx.coroutines.flow.combine | |
| import kotlinx.coroutines.flow.debounce | ||
| import kotlinx.coroutines.flow.distinctUntilChanged | ||
| import kotlinx.coroutines.flow.flow | ||
| import kotlinx.coroutines.flow.map | ||
| import kotlinx.coroutines.flow.stateIn | ||
| import kotlinx.coroutines.flow.transform | ||
| import kotlinx.coroutines.isActive | ||
|
|
@@ -720,8 +723,19 @@ public class CallState( | |
| @InternalStreamVideoApi | ||
| public val notificationIdFlow: StateFlow<Int?> = _notificationIdFlow | ||
|
|
||
| private var telecomHoldObserverJob: Job? = null | ||
|
|
||
| @InternalStreamVideoApi | ||
| internal var jetpackTelecomRepository: JetpackTelecomRepository? = null | ||
| set(value) { | ||
| field = value | ||
| if (value != null) { | ||
| observeTelecomHold(value) | ||
| } else { | ||
| telecomHoldObserverJob?.cancel() | ||
| telecomHoldObserverJob = null | ||
| } | ||
| } | ||
|
|
||
| internal var incomingNotificationData = IncomingNotificationData(emptyMap()) | ||
|
|
||
|
|
@@ -1749,6 +1763,28 @@ public class CallState( | |
| this._notificationIdFlow.value = notificationId | ||
| this.atomicNotification.set(notification) | ||
| } | ||
|
|
||
| /** | ||
| * [RingingState.Incoming] and [RingingState.Outgoing] are intentionally not observed. | ||
| * In Android Telecom, hold states are only applicable once a call is active (answered). | ||
| */ | ||
| private fun observeTelecomHold(repo: JetpackTelecomRepository) { | ||
| telecomHoldObserverJob?.cancel() | ||
|
|
||
| telecomHoldObserverJob = scope.launch(Dispatchers.Default) { | ||
| repo.currentCall | ||
| .map { (it as? TelecomCall.Registered)?.isOnHold == true } | ||
| .distinctUntilChanged() | ||
| .collect { telecomCall -> | ||
| when (ringingState.value) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
|
||
| is RingingState.Active -> { | ||
| call.leave("call-on-hold") | ||
| } | ||
| else -> {} | ||
| } | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| private fun MemberResponse.toMemberState(): MemberState { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.