From 93abf64da60e9bf300164535d8e1079f224a3514 Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Mon, 13 Jan 2025 17:09:34 +0100 Subject: [PATCH] Hide/show PIP window on active speaker call view appear/disappear --- Linphone/UI/Call/CallView.swift | 11 +++++++++++ Linphone/UI/Call/ViewModel/PIPViewModel.swift | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Linphone/UI/Call/CallView.swift b/Linphone/UI/Call/CallView.swift index 4ed752a38..eacddcc40 100644 --- a/Linphone/UI/Call/CallView.swift +++ b/Linphone/UI/Call/CallView.swift @@ -908,6 +908,17 @@ struct CallView: View { } } } + .onAppear { + if coreContext.pipViewModel.pipController?.isPictureInPictureActive ?? false { + coreContext.pipViewModel.pipController?.stopPictureInPicture() + } + } + .onDisappear { + if !callViewModel.isPaused && TelecomManager.shared.callInProgress + && !(coreContext.pipViewModel.pipController?.isPictureInPictureActive ?? false) { + coreContext.pipViewModel.pipController?.startPictureInPicture() + } + } } .frame( width: fullscreenVideo && !telecomManager.isPausedByRemote ? geometry.size.width - (isLandscapeMode ? 160 : 0) : geometry.size.width - 8 - (isLandscapeMode ? 160 : 0), diff --git a/Linphone/UI/Call/ViewModel/PIPViewModel.swift b/Linphone/UI/Call/ViewModel/PIPViewModel.swift index c5f5263fd..2dab99b3b 100644 --- a/Linphone/UI/Call/ViewModel/PIPViewModel.swift +++ b/Linphone/UI/Call/ViewModel/PIPViewModel.swift @@ -45,11 +45,11 @@ class PIPViewModel: NSObject, AVPictureInPictureControllerDelegate { CoreContext.shared.doOnCoreQueue { core in if let call = core.currentCall { - self.callStateChangedDelegate = CallDelegateStub(onStateChanged: { (_: Call, cstate: Call.State, _: String) in - if cstate != .StreamsRunning && CoreContext.shared.pipViewModel.pipController?.isPictureInPictureActive ?? false { - Log.info("\(PIPViewModel.TAG) onCallStateChanged detected, stop picture in picture") - CoreContext.shared.pipViewModel.pipController?.stopPictureInPicture() + self.callStateChangedDelegate = CallDelegateStub(onStateChanged: { (call: Call, cstate: Call.State, _: String) in + if CoreContext.shared.pipViewModel.pipController?.isPictureInPictureActive ?? false { if cstate == .End || cstate == .Error { + Log.info("\(PIPViewModel.TAG) call state 'End' or 'Error' detected, stopping picture in picture") + CoreContext.shared.pipViewModel.pipController?.stopPictureInPicture() self.callStateChangedDelegate = nil } }