From 91c6f7a311304f078addc9ef54a57fdb6ff91d6e Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Mon, 15 Sep 2025 14:25:27 +0200 Subject: [PATCH] Fix call video display --- Linphone/UI/Call/CallView.swift | 4 +- .../UI/Call/ViewModel/CallViewModel.swift | 67 ++++++++++--------- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/Linphone/UI/Call/CallView.swift b/Linphone/UI/Call/CallView.swift index b6f4e83e8..b4d0e890c 100644 --- a/Linphone/UI/Call/CallView.swift +++ b/Linphone/UI/Call/CallView.swift @@ -1938,9 +1938,9 @@ struct CallView: View { .frame(width: buttonSize, height: buttonSize) .background(Color.gray500) .cornerRadius(40) - .disabled(callViewModel.isPaused || telecomManager.isPausedByRemote) + .disabled(callViewModel.isPaused || telecomManager.isPausedByRemote || telecomManager.outgoingCallStarted) - if callViewModel.isPaused || telecomManager.isPausedByRemote { + if callViewModel.isPaused || telecomManager.isPausedByRemote || telecomManager.outgoingCallStarted { Color.gray600.opacity(0.8) .cornerRadius(40) .allowsHitTesting(false) diff --git a/Linphone/UI/Call/ViewModel/CallViewModel.swift b/Linphone/UI/Call/ViewModel/CallViewModel.swift index 02da3cea9..0dd86b01f 100644 --- a/Linphone/UI/Call/ViewModel/CallViewModel.swift +++ b/Linphone/UI/Call/ViewModel/CallViewModel.swift @@ -713,44 +713,47 @@ class CallViewModel: ObservableObject { func displayMyVideo() { coreContext.doOnCoreQueue { core in - if self.currentCall != nil { - do { - let params = try core.createCallParams(call: self.currentCall) - - if (params.videoEnabled == false) { - Log.info("\(CallViewModel.TAG) Conference found and video disabled in params, enabling it") - params.videoEnabled = true - params.videoDirection = MediaDirection.SendRecv + guard let call = self.currentCall else { return } + + let invalidStates: [Call.State] = [.Released, .End, .Error, .Idle] + + guard !invalidStates.contains(call.state) else { + Log.warn("\(CallViewModel.TAG) displayMyVideo called in invalid state: \(call.state), skipping update") + return + } + + do { + let params = try core.createCallParams(call: call) + + if !params.videoEnabled { + Log.info("\(CallViewModel.TAG) Video disabled in params, enabling it") + params.videoEnabled = true + params.videoDirection = .SendRecv + } else { + if params.videoDirection == .SendRecv || params.videoDirection == .SendOnly { + Log.info("\(CallViewModel.TAG) Video already enabled, switching to recv only") + params.videoDirection = .RecvOnly } else { - if (params.videoDirection == MediaDirection.SendRecv || params.videoDirection == MediaDirection.SendOnly) { - Log.info( - "\(CallViewModel.TAG) Conference found with video already enabled, changing video media direction to receive only" - ) - params.videoDirection = MediaDirection.RecvOnly - } else { - Log.info( - "\(CallViewModel.TAG) Conference found with video already enabled, changing video media direction to send & receive" - ) - params.videoDirection = MediaDirection.SendRecv - } + Log.info("\(CallViewModel.TAG) Video already enabled, switching to send & recv") + params.videoDirection = .SendRecv } - - try self.currentCall!.update(params: params) - - let video = params.videoDirection == .SendRecv || params.videoDirection == .SendOnly - - DispatchQueue.main.asyncAfter(deadline: .now() + (video ? 1 : 0)) { - if video { - self.videoDisplayed = false - } - self.videoDisplayed = video - } - } catch { - } + + try call.update(params: params) + + let video = params.videoDirection == .SendRecv || params.videoDirection == .SendOnly + DispatchQueue.main.asyncAfter(deadline: .now() + (video ? 1 : 0)) { + if video { + self.videoDisplayed = false + } + self.videoDisplayed = video + } + } catch { + Log.error("\(CallViewModel.TAG) Failed to update video params: \(error)") } } } + func toggleVideoMode(isAudioOnlyMode: Bool) { coreContext.doOnCoreQueue { core in