From f2615b89e0b1ad9e0c3b30d26abd509d30039725 Mon Sep 17 00:00:00 2001 From: "benoit.martins" Date: Fri, 14 Mar 2025 11:33:17 +0100 Subject: [PATCH] Fix outgoing conference call initiation --- Linphone/TelecomManager/TelecomManager.swift | 39 ++++++++++--------- .../UI/Call/ViewModel/CallViewModel.swift | 3 ++ .../Model/ConversationModel.swift | 23 +++++++++++ .../ViewModel/StartCallViewModel.swift | 5 +++ 4 files changed, 52 insertions(+), 18 deletions(-) diff --git a/Linphone/TelecomManager/TelecomManager.swift b/Linphone/TelecomManager/TelecomManager.swift index e4a7cf0e9..055113831 100644 --- a/Linphone/TelecomManager/TelecomManager.swift +++ b/Linphone/TelecomManager/TelecomManager.swift @@ -56,6 +56,7 @@ class TelecomManager: ObservableObject { @Published var meetingWaitingRoomDisplayed: Bool = false @Published var meetingWaitingRoomSelected: Address? @Published var meetingWaitingRoomName: String = "" + @Published var participantsInvited: Bool = false var actionToFulFill: CXCallAction? var callkitAudioSessionActivated: Bool? @@ -430,27 +431,29 @@ class TelecomManager: ObservableObject { func onCallStateChanged(core: Core, call: Call, state cstate: Call.State, message: String) { let callLog = call.callLog let callId = callLog?.callId ?? "" - if cstate == .OutgoingInit && !callInProgress { - if let remoteAddress = call.remoteAddress { - let uuid = UUID() - let name = remoteAddress.asStringUriOnly() - let handle = CXHandle(type: .generic, value: remoteAddress.asStringUriOnly()) - let startCallAction = CXStartCallAction(call: uuid, handle: handle) - let transaction = CXTransaction(action: startCallAction) - - let callInfo = CallInfo.newOutgoingCallInfo(addr: remoteAddress, isSas: false, displayName: name, isVideo: true, isConference: true) - providerDelegate.callInfos.updateValue(callInfo, forKey: uuid) - providerDelegate.uuids.updateValue(uuid, forKey: callId) - - setHeldOtherCalls(core: core, exceptCallid: callId) - requestTransaction(transaction, action: "startCall") - DispatchQueue.main.async { - withAnimation { - self.callDisplayed = true - } + if !callInProgress && participantsInvited { + if let remoteAddress = call.remoteAddress { + let uuid = UUID() + let name = remoteAddress.asStringUriOnly() + let handle = CXHandle(type: .generic, value: remoteAddress.asStringUriOnly()) + let startCallAction = CXStartCallAction(call: uuid, handle: handle) + let transaction = CXTransaction(action: startCallAction) + + let callInfo = CallInfo.newOutgoingCallInfo(addr: remoteAddress, isSas: false, displayName: name, isVideo: true, isConference: true) + providerDelegate.callInfos.updateValue(callInfo, forKey: uuid) + providerDelegate.uuids.updateValue(uuid, forKey: callId) + + setHeldOtherCalls(core: core, exceptCallid: callId) + requestTransaction(transaction, action: "startCall") + DispatchQueue.main.async { + self.participantsInvited = false + withAnimation { + self.callDisplayed = true } } + } } + if cstate == .PushIncomingReceived { Log.info("PushIncomingReceived in core delegate, display callkit call") TelecomManager.shared.displayIncomingCall(call: call, handle: "Calling", hasVideo: false, callId: callId, displayName: "Calling") diff --git a/Linphone/UI/Call/ViewModel/CallViewModel.swift b/Linphone/UI/Call/ViewModel/CallViewModel.swift index 203918c13..2d7d591e2 100644 --- a/Linphone/UI/Call/ViewModel/CallViewModel.swift +++ b/Linphone/UI/Call/ViewModel/CallViewModel.swift @@ -95,6 +95,9 @@ class CallViewModel: ObservableObject { } catch _ { } + NotificationCenter.default.addObserver(forName: Notification.Name("CallViewModelReset"), object: nil, queue: nil) { notification in + self.resetCallView() + } } func resetCallView() { diff --git a/Linphone/UI/Main/Conversations/Model/ConversationModel.swift b/Linphone/UI/Main/Conversations/Model/ConversationModel.swift index be16dcdba..837a5328b 100644 --- a/Linphone/UI/Main/Conversations/Model/ConversationModel.swift +++ b/Linphone/UI/Main/Conversations/Model/ConversationModel.swift @@ -150,6 +150,10 @@ class ConversationModel: ObservableObject, Identifiable { Log.info("\(ConversationModel.TAG) Inviting \(participantsList.count) participant(s) into newly created conference") try conference.inviteParticipants(addresses: participantsList, params: callParams) + + DispatchQueue.main.async { + TelecomManager.shared.participantsInvited = true + } } } } catch let error { @@ -160,6 +164,25 @@ class ConversationModel: ObservableObject, Identifiable { } } + func conferenceAddDelegate(core: Core, conference: Conference) { + self.conferenceDelegate = ConferenceDelegateStub(onStateChanged: { (conference: Conference, state: Conference.State) in + Log.info("\(ConversationModel.TAG) Conference state is \(state)") + if state == .Created { + NotificationCenter.default.post(name: Notification.Name("CallViewModelReset"), object: self) + } else if state == .CreationFailed { + Log.error("\(ConversationModel.TAG) Failed to create group call!") + DispatchQueue.main.async { + ToastViewModel.shared.toastMessage = "Failed_to_create_group_call_error" + ToastViewModel.shared.displayToast = true + } + } + }) + + if self.conferenceDelegate != nil { + conference.addDelegate(delegate: self.conferenceDelegate!) + } + } + func getContentTextMessage() { let lastMessage = self.chatRoom.lastMessageInHistory if lastMessage != nil { diff --git a/Linphone/UI/Main/History/ViewModel/StartCallViewModel.swift b/Linphone/UI/Main/History/ViewModel/StartCallViewModel.swift index 0902352fa..2d920b253 100644 --- a/Linphone/UI/Main/History/ViewModel/StartCallViewModel.swift +++ b/Linphone/UI/Main/History/ViewModel/StartCallViewModel.swift @@ -99,6 +99,10 @@ class StartCallViewModel: ObservableObject { Log.info("\(ConversationModel.TAG) Inviting \(participantsList.count) participant(s) into newly created conference") try conference.inviteParticipants(addresses: participantsList, params: callParams) + + DispatchQueue.main.async { + TelecomManager.shared.participantsInvited = true + } } } } catch let error { @@ -113,6 +117,7 @@ class StartCallViewModel: ObservableObject { self.conferenceDelegate = ConferenceDelegateStub(onStateChanged: { (conference: Conference, state: Conference.State) in Log.info("\(StartCallViewModel.TAG) Conference state is \(state)") if state == .Created { + NotificationCenter.default.post(name: Notification.Name("CallViewModelReset"), object: self) DispatchQueue.main.async { self.operationInProgress = false }