From 377f60062f228a6c70f115ea450ea7293e49fad8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 13:04:50 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20call=20dropped=20when=20turning=20camera?= =?UTF-8?q?=20on=20(WPB-9013)=20=F0=9F=8D=92=20(#2976)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Oussama Hassine --- .../ui/calling/ongoing/OngoingCallScreen.kt | 40 ++++++------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallScreen.kt b/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallScreen.kt index 78be3bf519a..6cff25ed4b1 100644 --- a/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallScreen.kt @@ -169,39 +169,25 @@ fun OngoingCallScreen( hideDialog = permissionPermanentlyDeniedDialogState::dismiss ) - handleVideoPreviewOnLifecycleChange( - isCameraOn = sharedCallingViewModel.callState.isCameraOn, - callStatus = sharedCallingViewModel.callState.callStatus, - startSendingVideoFeed = ongoingCallViewModel::startSendingVideoFeed, - pauseSendingVideoFeed = ongoingCallViewModel::pauseSendingVideoFeed, - onClearVideoPreview = sharedCallingViewModel::clearVideoPreview - ) -} - -/** - * This function is responsible for handling the lifecycle changes of the video preview. - * It will pause the video feed when the lifecycle is paused and resume it when the lifecycle is resumed. - */ -@Composable -private fun handleVideoPreviewOnLifecycleChange( - isCameraOn: Boolean, - callStatus: CallStatus, - startSendingVideoFeed: () -> Unit, - pauseSendingVideoFeed: () -> Unit, - onClearVideoPreview: () -> Unit -) { + // Pause the video feed when the lifecycle is paused and resume it when the lifecycle is resumed. val lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current - DisposableEffect(lifecycleOwner, isCameraOn, callStatus) { + DisposableEffect(lifecycleOwner) { val observer = LifecycleEventObserver { _, event -> - if (event == Lifecycle.Event.ON_PAUSE && callStatus == CallStatus.ESTABLISHED && isCameraOn) { - pauseSendingVideoFeed() + if (event == Lifecycle.Event.ON_PAUSE && + sharedCallingViewModel.callState.callStatus == CallStatus.ESTABLISHED && + sharedCallingViewModel.callState.isCameraOn + ) { + ongoingCallViewModel.pauseSendingVideoFeed() } - if (event == Lifecycle.Event.ON_RESUME && callStatus == CallStatus.ESTABLISHED && isCameraOn) { - startSendingVideoFeed() + if (event == Lifecycle.Event.ON_RESUME && + sharedCallingViewModel.callState.callStatus == CallStatus.ESTABLISHED && + sharedCallingViewModel.callState.isCameraOn + ) { + ongoingCallViewModel.startSendingVideoFeed() } if (event == Lifecycle.Event.ON_DESTROY) { - onClearVideoPreview() + sharedCallingViewModel.clearVideoPreview() } }