From 7b4427e7853f9d50eaa117a02c47ef4c727fbb8d Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Fri, 17 Apr 2020 09:32:19 +0200 Subject: [PATCH] fix end call --- Classes/CallManager.swift | 4 ++-- Classes/ProviderDelegate.swift | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Classes/CallManager.swift b/Classes/CallManager.swift index 48f3d2c3d..bdc25119d 100644 --- a/Classes/CallManager.swift +++ b/Classes/CallManager.swift @@ -176,7 +176,7 @@ import AVFoundation if (uuid != nil) { // This call was declined. providerDelegate.reportIncomingCall(call:nil, uuid: uuid!, handle: "Calling", hasVideo: false) - providerDelegate.endCallNotExist(uuid: uuid!, timeout: .now()) + providerDelegate.endCall(uuid: uuid!) return } @@ -378,7 +378,7 @@ import AVFoundation providerDelegate.uuids.updateValue(uuid, forKey: callId) } else { // end call - providerDelegate.endCallNotExist(uuid: uuid!, timeout: .now()) + providerDelegate.endCall(uuid: uuid!) } } } diff --git a/Classes/ProviderDelegate.swift b/Classes/ProviderDelegate.swift index 0cf8b52dc..c95481691 100644 --- a/Classes/ProviderDelegate.swift +++ b/Classes/ProviderDelegate.swift @@ -121,12 +121,18 @@ class ProviderDelegate: NSObject { func reportOutgoingCallConnected(uuid:UUID) { provider.reportOutgoingCall(with: uuid, connectedAt: nil) } + + func endCall(uuid: UUID) { + provider.reportCall(with: uuid, endedAt: .init(), reason: .declinedElsewhere) + } func endCallNotExist(uuid: UUID, timeout: DispatchTime) { DispatchQueue.main.asyncAfter(deadline: timeout) { - if (CallManager.instance().lc?.callsNb == 0) { - Log.directLog(BCTBX_LOG_MESSAGE, text: "CallKit: terminate call \(uuid) which does not exist.") - CallManager.instance().providerDelegate.provider.reportCall(with: uuid, endedAt: .init(), reason: .declinedElsewhere) + let callId = CallManager.instance().providerDelegate.callInfos[uuid]?.callId + let call = CallManager.instance().callByCallId(callId: callId) + if (call == nil) { + Log.directLog(BCTBX_LOG_MESSAGE, text: "CallKit: terminate call with call-id: \(String(describing: callId)) and UUID: \(uuid) which does not exist.") + CallManager.instance().providerDelegate.endCall(uuid: uuid) } } }