After the SDK changes to IOS audio routes, we now update bluetooth availability flag in “onAudioDevicesListUpdated” callback, and we manually set the route to bluetooth when starting calls with an available bluetooth device (this allows the overriding, from the App, of the core.defaultOutputDevice settings for the SDK)

This commit is contained in:
QuentinArguillere 2022-01-03 10:09:01 +01:00
parent eb6cf542fb
commit d53bf09702
6 changed files with 19 additions and 37 deletions

View file

@ -48,7 +48,6 @@ import AVFoundation
var conference: Conference?
var backgroundContextCall : Call?
@objc var backgroundContextCameraIsEnabled : Bool = false
@ -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 {
@ -485,6 +474,15 @@ import AVFoundation
}
}
func onAudioDevicesListUpdated(core: Core) {
let bluetoothAvailable = isBluetoothAvailable();
var dict = Dictionary<String, Bool>()
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
let callId = callLog?.callId
@ -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()
}
}
}

View file

@ -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];

View file

@ -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)

View file

@ -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);

View file

@ -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,19 +1738,6 @@ 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 {
LinphoneChatMessage *msg = linphone_chat_room_create_message(room, replyText.UTF8String);

View file

@ -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