From 462a79b22a7bf1f0edb35048cb5625cbbfb0fc79 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 +------------------ 5 files changed, 18 insertions(+), 36 deletions(-) diff --git a/Classes/CallManager.swift b/Classes/CallManager.swift index 6ea0686fb..19e27093b 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? @@ -141,27 +140,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 { @@ -485,6 +474,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 @@ -636,9 +634,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 2ae10de87..5702d6e54 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 53be84967..63af59110 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -204,7 +204,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 c980e5644..1f9d285b3 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -233,10 +233,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]; @@ -1769,21 +1765,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);