terminate callkit when register failed or cleared

This commit is contained in:
Danmei Chen 2020-10-30 16:37:50 +01:00
parent dccab97503
commit 1ff46fe25f
2 changed files with 19 additions and 2 deletions

View file

@ -46,6 +46,7 @@ import AVFoundation
@objc var alreadyRegisteredForNotification: Bool = false
var referedFromCall: String?
var referedToCall: String?
var endCallkit: Bool = false
fileprivate override init() {
@ -400,6 +401,18 @@ import AVFoundation
class CoreManagerDelegate: CoreDelegate {
static var speaker_already_enabled : Bool = false
override func onRegistrationStateChanged(lc: Core, cfg: ProxyConfig, cstate: RegistrationState, message: String) {
if lc.proxyConfigList.count == 1 && (cstate == .Failed || cstate == .Cleared){
// terminate callkit immediately when registration failed or cleared, supporting single proxy configuration
CallManager.instance().endCallkit = true
for call in CallManager.instance().providerDelegate.uuids {
CallManager.instance().providerDelegate.endCall(uuid: call.value)
}
} else {
CallManager.instance().endCallkit = false
}
}
override func onCallStateChanged(lc: Core, call: Call, cstate: Call.State, message: String) {
let addr = call.remoteAddress;

View file

@ -89,7 +89,11 @@ class ProviderDelegate: NSObject {
Log.directLog(BCTBX_LOG_MESSAGE, text: "CallKit: report new incoming call with call-id: [\(String(describing: callId))] and UUID: [\(uuid.description)]")
provider.reportNewIncomingCall(with: uuid, update: update) { error in
if error == nil {
CallManager.instance().providerDelegate.endCallNotExist(uuid: uuid, timeout: .now() + 20)
if CallManager.instance().endCallkit {
CallManager.instance().providerDelegate.endCall(uuid: uuid)
} else {
CallManager.instance().providerDelegate.endCallNotExist(uuid: uuid, timeout: .now() + 20)
}
} else {
Log.directLog(BCTBX_LOG_ERROR, text: "CallKit: cannot complete incoming call with call-id: [\(String(describing: callId))] and UUID: [\(uuid.description)] from [\(handle)] caused by [\(error!.localizedDescription)]")
let code = (error as NSError?)?.code
@ -124,7 +128,7 @@ class ProviderDelegate: NSObject {
}
func endCall(uuid: UUID) {
provider.reportCall(with: uuid, endedAt: .init(), reason: .declinedElsewhere)
provider.reportCall(with: uuid, endedAt: .init(), reason: .failed)
}
func endCallNotExist(uuid: UUID, timeout: DispatchTime) {