From a0b7dd0dda7ba13110586ad194128328acb1a4b7 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Thu, 16 Apr 2020 19:29:20 +0200 Subject: [PATCH] terminate early failed calls --- Classes/CallManager.swift | 24 ++++++++++++++++++++++++ Classes/LinphoneManager.m | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/Classes/CallManager.swift b/Classes/CallManager.swift index f1b9dda5e..48f3d2c3d 100644 --- a/Classes/CallManager.swift +++ b/Classes/CallManager.swift @@ -172,6 +172,14 @@ import AVFoundation // From ios13, display the callkit view when the notification is received. @objc func displayIncomingCall(callId: String) { + let uuid = CallManager.instance().providerDelegate.uuids["\(callId)"] + if (uuid != nil) { + // This call was declined. + providerDelegate.reportIncomingCall(call:nil, uuid: uuid!, handle: "Calling", hasVideo: false) + providerDelegate.endCallNotExist(uuid: uuid!, timeout: .now()) + return + } + let call = CallManager.instance().callByCallId(callId: callId) if (call != nil) { let addr = FastAddressBook.displayName(for: call?.remoteAddress?.getCobject) ?? "Unknow" @@ -357,6 +365,22 @@ import AVFoundation CoreManager.instance().stopLinphoneCore() } } + + @objc func markCallAsDeclined(callId: String) { + if !CallManager.callKitEnabled() { + return + } + + let uuid = providerDelegate.uuids["\(callId)"] + if (uuid == nil) { + Log.directLog(BCTBX_LOG_MESSAGE, text: "Mark call \(callId) as declined.") + let uuid = UUID() + providerDelegate.uuids.updateValue(uuid, forKey: callId) + } else { + // end call + providerDelegate.endCallNotExist(uuid: uuid!, timeout: .now()) + } + } } class CoreManagerDelegate: CoreDelegate { diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index b2b6552f8..35faa01ea 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1034,6 +1034,15 @@ void linphone_iphone_qr_code_found(LinphoneCore *lc, const char *result) { [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneQRCodeFound object:nil userInfo:eventDic]; } +static void linphone_iphone_call_log_updated(LinphoneCore *lc, LinphoneCallLog *newcl) { + if (linphone_call_log_get_status(newcl) == LinphoneCallEarlyAborted) { + const char *cid = linphone_call_log_get_call_id(newcl); + if (cid) { + [CallManager.instance markCallAsDeclinedWithCallId:[NSString stringWithUTF8String:cid]]; + } + } +} + #pragma mark - Message composition start - (void)onMessageComposeReceived:(LinphoneCore *)core forRoom:(LinphoneChatRoom *)room { [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneTextComposeEvent @@ -1314,6 +1323,7 @@ void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreat linphone_core_cbs_set_chat_room_state_changed(cbs, linphone_iphone_chatroom_state_changed); linphone_core_cbs_set_version_update_check_result_received(cbs, linphone_iphone_version_update_check_result_received); linphone_core_cbs_set_qrcode_found(cbs, linphone_iphone_qr_code_found); + linphone_core_cbs_set_call_log_updated(cbs, linphone_iphone_call_log_updated); linphone_core_cbs_set_user_data(cbs, (__bridge void *)(self)); theLinphoneCore = linphone_factory_create_shared_core_with_config(factory, _configDb, NULL, [kLinphoneMsgNotificationAppGroupId UTF8String], true);