fix(ios) avoid reapplying config when audio category doesn't change

This commit is contained in:
Saúl Ibarra Corretgé 2022-04-08 10:47:10 +02:00 committed by Saúl Ibarra Corretgé
parent 3097ac8cc4
commit cc5f65f58f
1 changed files with 8 additions and 3 deletions

View File

@ -259,10 +259,16 @@ RCT_EXPORT_METHOD(updateDeviceList) {
self->forceSpeaker = NO; self->forceSpeaker = NO;
self->forceEarpiece = NO; self->forceEarpiece = NO;
break; break;
case AVAudioSessionRouteChangeReasonCategoryChange: case AVAudioSessionRouteChangeReasonCategoryChange: {
// The category has changed. Check if it's the one we want and adjust as // The category has changed. Check if it's the one we want and adjust as
// needed. // needed.
RTCAudioSessionConfiguration *currentConfig = [self configForMode:self->activeMode];
if ([session.category isEqualToString:currentConfig.category]) {
// We are in the desired category, nothing to do here.
return;
}
break; break;
}
default: default:
return; return;
} }
@ -275,7 +281,6 @@ RCT_EXPORT_METHOD(updateDeviceList) {
RTCAudioSessionConfiguration *config = [self configForMode:self->activeMode]; RTCAudioSessionConfiguration *config = [self configForMode:self->activeMode];
[self setConfig:config error:nil]; [self setConfig:config error:nil];
if (self->forceSpeaker && !self->isSpeakerOn) { if (self->forceSpeaker && !self->isSpeakerOn) {
RTCAudioSession *session = JitsiAudioSession.rtcAudioSession;
[session lockForConfiguration]; [session lockForConfiguration];
[session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil]; [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];
[session unlockForConfiguration]; [session unlockForConfiguration];
@ -358,7 +363,7 @@ RCT_EXPORT_METHOD(updateDeviceList) {
break; break;
} }
} }
for (AVAudioSessionPortDescription *portDesc in session.availableInputs) { for (AVAudioSessionPortDescription *portDesc in session.availableInputs) {
// Skip "Phone" if headphones are present. // Skip "Phone" if headphones are present.
if (headphonesAvailable && [portDesc.portType isEqualToString:AVAudioSessionPortBuiltInMic]) { if (headphonesAvailable && [portDesc.portType isEqualToString:AVAudioSessionPortBuiltInMic]) {