From d89e616f377eaea4feaf85af265ef5da02b41647 Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Tue, 19 Dec 2023 17:34:59 +0100 Subject: [PATCH] Add startCall utilities to TelecomManager --- Linphone/TelecomManager/TelecomManager.swift | 39 ++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/Linphone/TelecomManager/TelecomManager.swift b/Linphone/TelecomManager/TelecomManager.swift index db1a80851..76c6d0c2b 100644 --- a/Linphone/TelecomManager/TelecomManager.swift +++ b/Linphone/TelecomManager/TelecomManager.swift @@ -82,13 +82,46 @@ class TelecomManager: ObservableObject { sCall.userData = UnsafeMutableRawPointer(Unmanaged.passRetained(appData!).toOpaque()) } } - + + func startCall(core: Core, addr: Address?, isSas: Bool, isVideo: Bool, isConference: Bool = false) throws { + if addr == nil { + Log.info("Can not start a call with null address!") + return + } + + if TelecomManager.callKitEnabled(core: core) && !nextCallIsTransfer != true { + let uuid = UUID() + let name = "outgoingTODO" // FastAddressBook.displayName(for: addr) ?? "unknow" + let handle = CXHandle(type: .generic, value: addr?.asStringUriOnly() ?? "") + let startCallAction = CXStartCallAction(call: uuid, handle: handle) + let transaction = CXTransaction(action: startCallAction) + + let callInfo = CallInfo.newOutgoingCallInfo(addr: addr!, isSas: isSas, displayName: name, isVideo: isVideo, isConference: isConference) + providerDelegate.callInfos.updateValue(callInfo, forKey: uuid) + providerDelegate.uuids.updateValue(uuid, forKey: "") + + // setHeldOtherCalls(core: core, exceptCallid: "") + requestTransaction(transaction, action: "startCall") + } else { + try doCall(core: core, addr: addr!, isSas: isSas, isVideo: isVideo, isConference: isConference) + } + } + + func startCall(core: Core, addr: String, isSas: Bool = false, isVideo: Bool, isConference: Bool = false) { + do { + let address = try Factory.Instance.createAddress(addr: addr) + try startCall(core: core, addr: address, isSas: isSas, isVideo: isVideo, isConference: isConference) + } catch { + Log.error("[TelecomManager] unable to create address for a new outgoing call : \(addr) \(error) ") + } + } + func doCallWithCore(addr: Address) { CoreContext.shared.doOnCoreQueue { core in do { - try self.doCall(core: core, addr: addr, isSas: false, isVideo: false) + try self.startCall(core: core, addr: addr, isSas: false, isVideo: false) } catch { - + Log.error("[TelecomManager] unable to create address for a new outgoing call : \(addr.asStringUriOnly()) \(error) ") } } }