From 987ea21e057b80caf3dc1db8cca7454b74705592 Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Fri, 18 Nov 2022 17:38:17 +0100 Subject: [PATCH] Multi call various fixes --- Classes/PhoneMainView.m | 1 - Classes/Swift/CallManager.swift | 2 +- .../LinphoneCore/CallExtensions.swift | 5 +-- .../Voip/ViewModels/CallsViewModel.swift | 42 +++++++++++++------ .../ActiveCallOrConferenceView.swift | 27 +++++++----- .../OutgoingCallView.swift | 3 ++ 6 files changed, 52 insertions(+), 28 deletions(-) diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index e146e01b0..ce35f4432 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -374,7 +374,6 @@ static RootViewManager *rootViewManagerInstance = nil; } break; } - case LinphoneCallOutgoingInit: case LinphoneCallOutgoingEarlyMedia: case LinphoneCallOutgoingProgress: case LinphoneCallOutgoingRinging: { diff --git a/Classes/Swift/CallManager.swift b/Classes/Swift/CallManager.swift index c85e86ca5..efcadf96e 100644 --- a/Classes/Swift/CallManager.swift +++ b/Classes/Swift/CallManager.swift @@ -27,7 +27,7 @@ import AVFoundation @objc class CallAppData: NSObject { @objc var batteryWarningShown = false @objc var videoRequested = false /*set when user has requested for video*/ - @objc var isConference = true + @objc var isConference = false } diff --git a/Classes/Swift/Extensions/LinphoneCore/CallExtensions.swift b/Classes/Swift/Extensions/LinphoneCore/CallExtensions.swift index 197f48fbc..ed0fcdecf 100644 --- a/Classes/Swift/Extensions/LinphoneCore/CallExtensions.swift +++ b/Classes/Swift/Extensions/LinphoneCore/CallExtensions.swift @@ -39,10 +39,7 @@ extension Call { extension Call : CustomStringConvertible { public var description: String { - if let callId = callLog?.callId { - return "" - } - return "" + return "" } } diff --git a/Classes/Swift/Voip/ViewModels/CallsViewModel.swift b/Classes/Swift/Voip/ViewModels/CallsViewModel.swift index 284868eb0..734b4fd93 100644 --- a/Classes/Swift/Voip/ViewModels/CallsViewModel.swift +++ b/Classes/Swift/Voip/ViewModels/CallsViewModel.swift @@ -33,9 +33,9 @@ class CallsViewModel { let callConnectedEvent = MutableLiveData() let callUpdateEvent = MutableLiveData() let noMoreCallEvent = MutableLiveData(false) - + var core : Core { get { Core.get() } } - + static let shared = CallsViewModel() private var coreDelegate : CoreDelegateStub? @@ -44,7 +44,11 @@ class CallsViewModel { coreDelegate = CoreDelegateStub( onCallStateChanged : { (core: Core, call: Call, state: Call.State, message:String) -> Void in Log.i("[Calls] Call state changed: \(call) : \(state)") + if (state == .IncomingEarlyMedia || state == .IncomingReceived || state == .OutgoingInit) { + self.addCallToList(call:call) + } let currentCall = core.currentCall + Log.i("[Calls] Current call is \(currentCall)") if (currentCall != nil && self.currentCallData.value??.call.getCobject != currentCall?.getCobject) { self.updateCurrentCallData(currentCall: currentCall) } else if (currentCall == nil && core.callsNb > 0) { @@ -120,13 +124,17 @@ class CallsViewModel { if let removeCandidate = callsData.value?.filter{$0.call.getCobject == call.getCobject}.first { removeCandidate.destroy() } - + callsData.value = callsData.value?.filter(){$0.call.getCobject != call.getCobject} callsData.notifyValue() } private func addCallToList(call: Call) { Log.i("[Calls] Adding call \(call) to calls list") + guard self.callsData.value?.filter({$0.call.getCobject == call.getCobject}).first == nil else { + Log.i("[Calls] \(call) already present in the list") + return + } callsData.value?.append(CallData(call: call)) callsData.notifyValue() } @@ -162,29 +170,39 @@ class CallsViewModel { var callToUse = currentCall if (currentCall == nil) { Log.w("[Calls] Current call is now null") + + if (Core.get().callsNb == 1) { + let firstData = callsData.value?.first + if (firstData != nil && currentCallData.value??.call.getCobject != firstData?.call.getCobject) { + Log.i("[Calls] Only one call in Core and the current call data doesn't match it, updating it") + currentCallData.value = firstData + } + return + } - let firstCall = core.calls.first + let firstCall = core.calls.filter {$0.state != .Error && $0.state != .End && $0.state != .Released}.first if (firstCall != nil && currentCallData.value??.call.getCobject != firstCall?.getCobject) { - Log.i("[Calls] Using first call as \"current\" call") + Log.i("[Calls] Using \(firstCall?.callLog?.callId) as \"current\" call") callToUse = firstCall } } - + guard let callToUse = callToUse else { Log.w("[Calls] No call found to be used as \"current\"") return } - - let firstToUse = callsData.value?.filter{$0.call.getCobject != callToUse.getCobject}.first + + let firstToUse = callsData.value?.filter{$0.call.getCobject == callToUse.getCobject}.first if (firstToUse != nil) { + Log.i("[Calls] Updating current call to : \(firstToUse?.call)") currentCallData.value = firstToUse } else { - Log.w("[Calls] Call not found in calls data list, shouldn't happen!") + Log.w("[Calls] Call not found in calls data list, shouldn't happen! currentCallData is \(callToUse)") currentCallData.value = CallData(call: callToUse) } - - updateUnreadChatCount() + ControlsViewModel.shared.updateMicState() + //updateUnreadChatCount() } - + } diff --git a/Classes/Swift/Voip/Views/CompositeViewControllers/ActiveCallOrConferenceView.swift b/Classes/Swift/Voip/Views/CompositeViewControllers/ActiveCallOrConferenceView.swift index c68d6b705..cd37da76e 100644 --- a/Classes/Swift/Voip/Views/CompositeViewControllers/ActiveCallOrConferenceView.swift +++ b/Classes/Swift/Voip/Views/CompositeViewControllers/ActiveCallOrConferenceView.swift @@ -86,13 +86,16 @@ import linphonesw fullScreenMutableContainerView.addSubview(currentCallView!) CallsViewModel.shared.currentCallData.readCurrentAndObserve { (currentCallData) in self.updateNavigation() - self.currentCallView!.isHidden = currentCallData == nil || ConferenceViewModel.shared.conferenceExists.value == true - self.currentCallView!.callData = currentCallData != nil ? currentCallData! : nil + let isConferenceCall = currentCallData??.call.conference != nil + self.currentCallView!.isHidden = isConferenceCall + if (!isConferenceCall) { + self.currentCallView!.callData = currentCallData != nil ? currentCallData! : nil + } currentCallData??.isRemotelyPaused.readCurrentAndObserve { remotelyPaused in - self.callPausedByRemoteView?.isHidden = remotelyPaused != true || ConferenceViewModel.shared.conferenceExists.value == true + self.callPausedByRemoteView?.isHidden = remotelyPaused != true || isConferenceCall } currentCallData??.isPaused.readCurrentAndObserve { locallyPaused in - self.callPausedByLocalView?.isHidden = locallyPaused != true || ConferenceViewModel.shared.conferenceExists.value == true + self.callPausedByLocalView?.isHidden = locallyPaused != true || isConferenceCall } if (currentCallData == nil) { self.callPausedByRemoteView?.isHidden = true @@ -103,8 +106,9 @@ import linphonesw currentCallData??.isOutgoing.readCurrentAndObserve { _ in self.updateNavigation() } } self.extraButtonsView.isHidden = true - self.conferencePausedView?.isHidden = true - if (ConferenceViewModel.shared.conferenceExists.value != true) { + self.conferencePausedView?.isHidden = currentCallData??.call.conference == nil || ConferenceViewModel.shared.isConferenceLocallyPaused.value != true + + if (isConferenceCall) { self.conferenceGridView?.isHidden = true self.conferenceActiveSpeakerView?.isHidden = true self.conferenceAudioOnlyView?.isHidden = true @@ -144,20 +148,22 @@ import linphonesw conferenceGridView?.isHidden = true ConferenceViewModel.shared.conferenceExists.readCurrentAndObserve { (exists) in self.updateNavigation() - if (exists == true) { + let activeCallIsConference = CallsViewModel.shared.currentCallData.value??.call.conference != nil + if (activeCallIsConference) { self.currentCallView!.isHidden = true self.extraButtonsView.isHidden = true - self.conferencePausedView?.isHidden = true + self.conferencePausedView?.isHidden = ConferenceViewModel.shared.isConferenceLocallyPaused.value != true self.displaySelectedConferenceLayout() } else { self.conferenceGridView?.isHidden = true self.conferenceActiveSpeakerView?.isHidden = true self.conferenceActiveSpeakerView?.isHidden = true + self.conferencePausedView?.isHidden = true } } ConferenceViewModel.shared.conferenceCreationPending.readCurrentAndObserve { isCreationPending in - if (ConferenceViewModel.shared.conferenceExists.value == true && isCreationPending == true) { + if (isCreationPending == true) { self.fullScreenMutableContainerView.addSubview(self.conferenceJoinSpinner) self.conferenceJoinSpinner.square(IncomingOutgoingCommonView.spinner_size).center().done() self.conferenceJoinSpinner.startRotation() @@ -186,7 +192,7 @@ import linphonesw } } ConferenceViewModel.shared.isConferenceLocallyPaused.readCurrentAndObserve { (paused) in - self.conferencePausedView?.isHidden = paused != true || ConferenceViewModel.shared.conferenceExists.value != true + self.conferencePausedView?.isHidden = paused != true } @@ -340,6 +346,7 @@ import linphonesw extraButtonsView.refresh() ControlsViewModel.shared.callStatsVisible.notifyValue() CallsViewModel.shared.currentCallData.notifyValue() + ConferenceViewModel.shared.conferenceExists.notifyValue() ControlsViewModel.shared.audioRoutesSelected.value = false ControlsViewModel.shared.fullScreenMode.value = true } diff --git a/Classes/Swift/Voip/Views/CompositeViewControllers/OutgoingCallView.swift b/Classes/Swift/Voip/Views/CompositeViewControllers/OutgoingCallView.swift index 9692d692a..7823d6643 100644 --- a/Classes/Swift/Voip/Views/CompositeViewControllers/OutgoingCallView.swift +++ b/Classes/Swift/Voip/Views/CompositeViewControllers/OutgoingCallView.swift @@ -84,6 +84,9 @@ import linphonesw override func viewWillAppear(_ animated: Bool) { ControlsViewModel.shared.audioRoutesSelected.value = false super.viewWillAppear(animated) + if (Core.get().callsNb == 0) { + PhoneMainView.instance().popView(self.compositeViewDescription()) + } } @objc override func setCall(call:OpaquePointer) {