Skip to content
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

fix: camera on/off button when in fullscreen [WPB-9815] 🍒 #3122

Merged
Merged
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 @@ -58,6 +58,7 @@ import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import com.wire.android.R
import com.wire.android.ui.LocalActivity
import com.wire.android.ui.calling.CallState
import com.wire.android.ui.calling.ConversationName
import com.wire.android.ui.calling.SharedCallingViewModel
import com.wire.android.ui.calling.controlbuttons.CameraButton
Expand Down Expand Up @@ -137,14 +138,8 @@ fun OngoingCallScreen(
hangUpCall = { sharedCallingViewModel.hangUpCall { activity.finishAndRemoveTask() } },
toggleVideo = sharedCallingViewModel::toggleVideo,
flipCamera = sharedCallingViewModel::flipCamera,
setVideoPreview = {
sharedCallingViewModel.setVideoPreview(it)
ongoingCallViewModel.startSendingVideoFeed()
},
clearVideoPreview = {
sharedCallingViewModel.clearVideoPreview()
ongoingCallViewModel.stopSendingVideoFeed()
},
setVideoPreview = sharedCallingViewModel::setVideoPreview,
clearVideoPreview = sharedCallingViewModel::clearVideoPreview,
onCollapse = { activity.moveTaskToBack(true) },
requestVideoStreams = ongoingCallViewModel::requestVideoStreams,
hideDoubleTapToast = ongoingCallViewModel::hideDoubleTapToast,
Expand All @@ -169,25 +164,36 @@ fun OngoingCallScreen(
hideDialog = permissionPermanentlyDeniedDialogState::dismiss
)

HandleSendingVideoFeed(
callState = sharedCallingViewModel.callState,
pauseSendingVideoFeed = ongoingCallViewModel::pauseSendingVideoFeed,
startSendingVideoFeed = ongoingCallViewModel::startSendingVideoFeed,
stopSendingVideoFeed = ongoingCallViewModel::stopSendingVideoFeed,
clearVideoPreview = sharedCallingViewModel::clearVideoPreview,
)
}

@Composable
private fun HandleSendingVideoFeed(
callState: CallState,
pauseSendingVideoFeed: () -> Unit,
startSendingVideoFeed: () -> Unit,
stopSendingVideoFeed: () -> Unit,
clearVideoPreview: () -> 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) {

val observer = LifecycleEventObserver { _, event ->
if (event == Lifecycle.Event.ON_PAUSE &&
sharedCallingViewModel.callState.callStatus == CallStatus.ESTABLISHED &&
sharedCallingViewModel.callState.isCameraOn
) {
ongoingCallViewModel.pauseSendingVideoFeed()
if (event == Lifecycle.Event.ON_PAUSE && callState.callStatus == CallStatus.ESTABLISHED && callState.isCameraOn) {
pauseSendingVideoFeed()
}
if (event == Lifecycle.Event.ON_RESUME &&
sharedCallingViewModel.callState.callStatus == CallStatus.ESTABLISHED &&
sharedCallingViewModel.callState.isCameraOn
) {
ongoingCallViewModel.startSendingVideoFeed()
if (event == Lifecycle.Event.ON_RESUME && callState.callStatus == CallStatus.ESTABLISHED && callState.isCameraOn) {
startSendingVideoFeed()
}
if (event == Lifecycle.Event.ON_DESTROY) {
sharedCallingViewModel.clearVideoPreview()
clearVideoPreview()
}
}

Expand All @@ -197,6 +203,16 @@ fun OngoingCallScreen(
lifecycleOwner.lifecycle.removeObserver(observer)
}
}

// Start/stop sending video feed based on the camera state when the call is established.
LaunchedEffect(callState.callStatus, callState.isCameraOn) {
if (callState.callStatus == CallStatus.ESTABLISHED) {
when (callState.isCameraOn) {
true -> startSendingVideoFeed()
false -> stopSendingVideoFeed()
}
}
}
}

@OptIn(ExperimentalMaterial3Api::class)
Expand Down
Loading