diff --git a/Classes/CallManager.swift b/Classes/CallManager.swift index bc898bb90..f1a6bab97 100644 --- a/Classes/CallManager.swift +++ b/Classes/CallManager.swift @@ -445,10 +445,19 @@ import AVFoundation func onRegistrationStateChanged(core: Core, proxyConfig: ProxyConfig, state: RegistrationState, message: String) { if core.proxyConfigList.count == 1 && (state == .Failed || state == .Cleared){ // terminate callkit immediately when registration failed or cleared, supporting single proxy configuration - CallManager.instance().endCallkit = true for call in CallManager.instance().providerDelegate.uuids { + let callId = CallManager.instance().providerDelegate.callInfos[call.value]?.callId + if (callId != nil) { + let call = CallManager.instance().lc?.getCallByCallid(callId: callId!) + if (call != nil) { + // sometimes (for example) due to network, registration failed, in this case, keep the call + continue + } + } + CallManager.instance().providerDelegate.endCall(uuid: call.value) } + CallManager.instance().endCallkit = true } else { CallManager.instance().endCallkit = false } diff --git a/Classes/ProviderDelegate.swift b/Classes/ProviderDelegate.swift index 6d5d06a07..61c59c6cf 100644 --- a/Classes/ProviderDelegate.swift +++ b/Classes/ProviderDelegate.swift @@ -134,6 +134,11 @@ class ProviderDelegate: NSObject { func endCall(uuid: UUID) { provider.reportCall(with: uuid, endedAt: .init(), reason: .failed) + let callId = callInfos[uuid]?.callId + if (callId != nil) { + uuids.removeValue(forKey: callId!) + } + callInfos.removeValue(forKey: uuid) } func endCallNotExist(uuid: UUID, timeout: DispatchTime) {