improve callkit

This commit is contained in:
Danmei Chen 2020-11-25 22:50:00 +01:00
parent 4cc09f5428
commit 537cda59aa
2 changed files with 21 additions and 12 deletions

View file

@ -248,6 +248,7 @@ import AVFoundation
providerDelegate.callInfos.updateValue(callInfo, forKey: uuid)
providerDelegate.uuids.updateValue(uuid, forKey: "")
setHeldOtherCalls(exceptCallid: "")
requestTransaction(transaction, action: "startCall")
}else {
try? doCall(addr: sAddr, isSas: isSas)
@ -319,11 +320,6 @@ import AVFoundation
let groupAction = CXSetGroupCallAction(call: currentUuid!, callUUIDToGroupWith: newUuid)
let transcation = CXTransaction(action: groupAction)
requestTransaction(transcation, action: "groupCall")
// To simulate the real group call action
let heldAction = CXSetHeldCallAction(call: currentUuid!, onHold: false)
let otherTransacation = CXTransaction(action: heldAction)
requestTransaction(otherTransacation, action: "heldCall")
} else {
try? lc?.addAllToConference()
}
@ -385,18 +381,31 @@ import AVFoundation
@objc func setHeld(call: OpaquePointer, hold: Bool) {
let sCall = Call.getSwiftObject(cObject: call)
let callid = sCall.callLog?.callId ?? ""
if (!hold) {
setHeldOtherCalls(exceptCallid: sCall.callLog?.callId ?? "")
}
setHeld(call: sCall, hold: hold)
}
func setHeld(call: Call, hold: Bool) {
let callid = call.callLog?.callId ?? ""
let uuid = providerDelegate.uuids["\(callid)"]
if (uuid == nil) {
Log.directLog(BCTBX_LOG_ERROR, text: "Can not find correspondant call to group.")
Log.directLog(BCTBX_LOG_ERROR, text: "Can not find correspondant call to set held.")
return
}
let setHeldAction = CXSetHeldCallAction(call: uuid!, onHold: hold)
let transaction = CXTransaction(action: setHeldAction)
requestTransaction(transaction, action: "setHeld")
}
@objc func setHeldOtherCalls(exceptCallid: String) {
for call in CallManager.instance().lc!.calls {
if (call.callLog?.callId != exceptCallid && call.state != .Paused && call.state != .Pausing && call.state != .PausedByRemote) {
setHeld(call: call, hold: true)
}
}
}
}
class CoreManagerDelegate: CoreDelegate {

View file

@ -192,9 +192,9 @@ extension ProviderDelegate: CXProviderDelegate {
}
do {
if (CallManager.instance().lc?.isInConference ?? false && action.isOnHold) {
if (call?.conference != nil && action.isOnHold) {
try CallManager.instance().lc?.leaveConference()
Log.directLog(BCTBX_LOG_DEBUG, text: "CallKit: Leaving conference")
Log.directLog(BCTBX_LOG_DEBUG, text: "CallKit: call-id: [\(String(describing: callId))] leaving conference")
NotificationCenter.default.post(name: Notification.Name("LinphoneCallUpdate"), object: self)
return
}
@ -208,7 +208,7 @@ extension ProviderDelegate: CXProviderDelegate {
CallManager.instance().speakerBeforePause = CallManager.instance().speakerEnabled
try call!.pause()
} else {
if (CallManager.instance().lc?.conference != nil && CallManager.instance().lc?.callsNb ?? 0 > 1) {
if (call?.conference != nil && CallManager.instance().lc?.callsNb ?? 0 > 1) {
try CallManager.instance().lc?.enterConference()
NotificationCenter.default.post(name: Notification.Name("LinphoneCallUpdate"), object: self)
} else {