From d53bf09702ef439d2c0c6515ed07a1ee08c7d210 Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Mon, 3 Jan 2022 10:09:01 +0100 Subject: [PATCH] =?UTF-8?q?After=20the=20SDK=20changes=20to=20IOS=20audio?= =?UTF-8?q?=20routes,=20we=20now=20update=20bluetooth=20availability=20fla?= =?UTF-8?q?g=20in=20=E2=80=9ConAudioDevicesListUpdated=E2=80=9D=20callback?= =?UTF-8?q?,=20and=20we=20manually=20set=20the=20route=20to=20bluetooth=20?= =?UTF-8?q?when=20starting=20calls=20with=20an=20available=20bluetooth=20d?= =?UTF-8?q?evice=20(this=20allows=20the=20overriding,=20from=20the=20App,?= =?UTF-8?q?=20of=20the=20core.defaultOutputDevice=20settings=20for=20the?= =?UTF-8?q?=20SDK)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/CallManager.swift | 30 +++++++++++++++--------------- Classes/CallOutgoingView.m | 2 +- Classes/CallView.m | 2 +- Classes/LinphoneManager.h | 1 - Classes/LinphoneManager.m | 19 +------------------ Podfile | 2 +- 6 files changed, 19 insertions(+), 37 deletions(-) diff --git a/Classes/CallManager.swift b/Classes/CallManager.swift index e535f7ba2..8987d6e9e 100644 --- a/Classes/CallManager.swift +++ b/Classes/CallManager.swift @@ -46,7 +46,6 @@ import AVFoundation var globalState : GlobalState = .Off var actionsToPerformOnceWhenCoreIsOn : [(()->Void)] = [] var conference: Conference? - var backgroundContextCall : Call? @@ -140,27 +139,17 @@ import AVFoundation } @objc func changeRouteToSpeaker() { - for device in lc!.audioDevices { - if (device.type == AudioDeviceType.Speaker) { - lc!.outputAudioDevice = device - break - } - } + lc?.outputAudioDevice = lc?.audioDevices.first { $0.type == AudioDeviceType.Speaker } UIDevice.current.isProximityMonitoringEnabled = false } @objc func changeRouteToBluetooth() { - for device in lc!.audioDevices { - if (device.type == AudioDeviceType.Bluetooth || device.type == AudioDeviceType.BluetoothA2DP) { - lc!.outputAudioDevice = device - break - } - } + lc?.outputAudioDevice = lc?.audioDevices.first { $0.type == AudioDeviceType.BluetoothA2DP || $0.type == AudioDeviceType.Bluetooth } UIDevice.current.isProximityMonitoringEnabled = (lc!.callsNb > 0) } @objc func changeRouteToDefault() { - lc!.outputAudioDevice = lc!.defaultOutputAudioDevice + lc?.outputAudioDevice = lc?.defaultOutputAudioDevice } @objc func isBluetoothAvailable() -> Bool { @@ -484,6 +473,15 @@ import AVFoundation CallManager.instance().conference = nil } } + + func onAudioDevicesListUpdated(core: Core) { + let bluetoothAvailable = isBluetoothAvailable(); + + var dict = Dictionary() + dict["available"] = bluetoothAvailable + NotificationCenter.default.post(name: Notification.Name("LinphoneBluetoothAvailabilityUpdate"), object: self, userInfo: dict) + + } func onCallStateChanged(core: Core, call: Call, state cstate: Call.State, message: String) { let callLog = call.callLog @@ -635,9 +633,11 @@ import AVFoundation } if (cstate == .IncomingReceived || cstate == .OutgoingInit || cstate == .Connected || cstate == .StreamsRunning) { - let check = call.currentParams?.videoEnabled if ((call.currentParams?.videoEnabled ?? false) && CallManager.instance().isReceiverEnabled()) { CallManager.instance().changeRouteToSpeaker() + } else if (isBluetoothAvailable()) { + // Use bluetooth device by default if one is available + CallManager.instance().changeRouteToBluetooth() } } } diff --git a/Classes/CallOutgoingView.m b/Classes/CallOutgoingView.m index c5057377d..1a2a42352 100644 --- a/Classes/CallOutgoingView.m +++ b/Classes/CallOutgoingView.m @@ -99,7 +99,7 @@ static UICompositeViewDescription *compositeDescription = nil; ms_free(uri); [_avatarImage setImage:[FastAddressBook imageForAddress:addr] bordered:NO withRoundedRadius:YES]; - [self hideSpeaker:LinphoneManager.instance.bluetoothAvailable]; + [self hideSpeaker: [CallManager.instance isBluetoothAvailable]]; [_speakerButton update]; [_microButton update]; diff --git a/Classes/CallView.m b/Classes/CallView.m index 712ebffc6..e4788ad0d 100644 --- a/Classes/CallView.m +++ b/Classes/CallView.m @@ -148,7 +148,7 @@ static UICompositeViewDescription *compositeDescription = nil; [self hideRoutes:TRUE animated:FALSE]; [self hideOptions:TRUE animated:FALSE]; [self hidePad:TRUE animated:FALSE]; - [self hideSpeaker:LinphoneManager.instance.bluetoothAvailable]; + [self hideSpeaker: [CallManager.instance isBluetoothAvailable]]; [self callDurationUpdate]; [self onCurrentCallChange]; // Set windows (warn memory leaks) diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 632675f92..bde233e52 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -200,7 +200,6 @@ typedef struct _LinphoneManagerSounds { @property (readonly) sqlite3* database; @property (readonly) LinphoneManagerSounds sounds; @property (readonly) NSMutableArray *logs; -@property (nonatomic, assign) BOOL bluetoothAvailable; @property (readonly) NSString* contactSipField; @property (readonly,copy) NSString* contactFilter; @property (copy) void (^silentPushCompletion)(UIBackgroundFetchResult); diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 2c86c0b62..86ac9c392 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -231,10 +231,6 @@ struct codec_name_pref_table codec_pref_table[] = {{"speex", 8000, "speex_8k_pre - (id)init { if ((self = [super init])) { - [NSNotificationCenter.defaultCenter addObserver:self - selector:@selector(audioRouteChangeListenerCallback:) - name:AVAudioSessionRouteChangeNotification - object:nil]; NSString *path = [[NSBundle mainBundle] pathForResource:@"msg" ofType:@"wav"]; self.messagePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:path] error:nil]; @@ -1742,21 +1738,8 @@ static int comp_call_state_paused(const LinphoneCall *call, const void *param) { } #pragma mark - Audio route Functions -- (void)audioRouteChangeListenerCallback:(NSNotification *)notif { - if (IPAD) - return; - - _bluetoothAvailable = [CallManager.instance isBluetoothAvailable]; - - NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:_bluetoothAvailable], @"available", nil]; - [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneBluetoothAvailabilityUpdate - object:self - userInfo:dict]; - -} - #pragma mark - Call Functions -- (void)send:(NSString *)replyText toChatRoom:(LinphoneChatRoom *)room { +- (void)send:(NSString *)replyText toChatRoom:(LinphoneChatRoom *)room { LinphoneChatMessage *msg = linphone_chat_room_create_message(room, replyText.UTF8String); linphone_chat_message_send(msg); diff --git a/Podfile b/Podfile index 18c1cc72e..6ce628744 100644 --- a/Podfile +++ b/Podfile @@ -5,7 +5,7 @@ source "https://github.com/CocoaPods/Specs.git" def all_pods if ENV['PODFILE_PATH'].nil? - pod 'linphone-sdk', '~> 5.0.16' + pod 'linphone-sdk', '~> 5.0.63' else pod 'linphone-sdk', :path => ENV['PODFILE_PATH'] # local sdk end