From 44354f4f5ecaeb32da6d5f275f00fbb7fb3f8379 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Wed, 15 Apr 2020 15:09:32 +0200 Subject: [PATCH] fix calls --- Classes/CallManager.swift | 3 +-- Classes/CoreManager.swift | 7 +++++++ Classes/LinphoneAppDelegate.m | 9 ++------- Classes/LinphoneManager.h | 1 - Classes/LinphoneManager.m | 5 ----- Classes/PhoneMainView.m | 2 +- Classes/ProviderDelegate.swift | 17 ++++++++--------- 7 files changed, 19 insertions(+), 25 deletions(-) diff --git a/Classes/CallManager.swift b/Classes/CallManager.swift index 1ce4e1d52..f1b9dda5e 100644 --- a/Classes/CallManager.swift +++ b/Classes/CallManager.swift @@ -354,8 +354,7 @@ import AVFoundation Log.directLog(BCTBX_LOG_ERROR, text: "Failed to terminate call failed because \(error)") } if (UIApplication.shared.applicationState == .background) { - CoreManager.instance().stopIterateTimer() - lc!.stop() + CoreManager.instance().stopLinphoneCore() } } } diff --git a/Classes/CoreManager.swift b/Classes/CoreManager.swift index 7eb83bc83..5b365f991 100644 --- a/Classes/CoreManager.swift +++ b/Classes/CoreManager.swift @@ -56,4 +56,11 @@ import linphonesw timer.invalidate() } } + + @objc func stopLinphoneCore() { + if (lc?.callsNb == 0) { + stopIterateTimer() + lc?.stop() + } + } } diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 7c6afaeb3..4123470c6 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -58,13 +58,8 @@ - (void)applicationDidEnterBackground:(UIApplication *)application { LOGI(@"%@", NSStringFromSelector(_cmd)); [LinphoneManager.instance enterBackgroundMode]; - LinphoneCall *call = linphone_core_get_current_call(LC); - - if (!call) { - dispatch_async(dispatch_get_main_queue(), ^{ - [LinphoneManager.instance stopLinphoneCore]; - }); - } + + [CoreManager.instance stopLinphoneCore]; } - (void)applicationWillEnterForeground:(UIApplication *)application { diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index ec370e1ae..05f78f5bf 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -120,7 +120,6 @@ typedef struct _LinphoneManagerSounds { - (void)launchLinphoneCore; - (void)destroyLinphoneCore; - (void)startLinphoneCore; -- (void)stopLinphoneCore; - (BOOL)resignActive; - (void)becomeActive; - (BOOL)enterBackgroundMode; diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index d2585c538..b2b6552f8 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1274,11 +1274,6 @@ void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreat [CoreManager.instance startIterateTimer]; } -- (void)stopLinphoneCore { - [CoreManager.instance stopIterateTimer]; - linphone_core_stop([LinphoneManager getLc]); -} - - (void)createLinphoneCore { [self migrationAllPre]; if (theLinphoneCore != nil) { diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index b54b9a3f7..ce9366763 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -441,7 +441,7 @@ static RootViewManager *rootViewManagerInstance = nil; case LinphoneCallReleased: if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { dispatch_async(dispatch_get_main_queue(), ^{ - [LinphoneManager.instance stopLinphoneCore]; + [CoreManager.instance stopLinphoneCore]; }); } break; diff --git a/Classes/ProviderDelegate.swift b/Classes/ProviderDelegate.swift index 656dd10bc..4e439239d 100644 --- a/Classes/ProviderDelegate.swift +++ b/Classes/ProviderDelegate.swift @@ -89,6 +89,14 @@ 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 { + DispatchQueue.main.asyncAfter(deadline: .now() + 60) {// in 30 second + if (CallManager.instance().lc?.callsNb == 0 && !CallManager.instance().providerDelegate.callInfos.isEmpty ) { + Log.directLog(BCTBX_LOG_MESSAGE, text: "CallKit: end call which does not exist.") + for suuid in CallManager.instance().providerDelegate.uuids.values { + CallManager.instance().providerDelegate.endCallForError(uuid: suuid, endedAt: .init(), endedReason: .declinedElsewhere) + } + } + } } 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)]") if (call == nil) { @@ -104,15 +112,6 @@ class ProviderDelegate: NSObject { } } } - - DispatchQueue.main.asyncAfter(deadline: .now() + 30) {// in 30 second - if (CallManager.instance().lc?.callsNb == 0 && !CallManager.instance().providerDelegate.callInfos.isEmpty ) { - Log.directLog(BCTBX_LOG_MESSAGE, text: "CallKit: end call which does not exist.") - for suuid in CallManager.instance().providerDelegate.uuids.values { - CallManager.instance().providerDelegate.endCallForError(uuid: suuid, endedAt: .init(), endedReason: .declinedElsewhere) - } - } - } } func updateCall(uuid: UUID, handle: String, hasVideo: Bool = false) {