Fix outgoing conference call initiation

This commit is contained in:
benoit.martins 2025-03-14 11:33:17 +01:00
parent 5cadd63d1e
commit f2615b89e0
4 changed files with 52 additions and 18 deletions

View file

@ -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")

View file

@ -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() {

View file

@ -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 {

View file

@ -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
}