react-native-incall-manager icon indicating copy to clipboard operation
react-native-incall-manager copied to clipboard

Disconnecting Bluetooth device (airpods), fallback to "small speaker" instead of the "loud speaker"

Open Pandazaur opened this issue 3 years ago • 2 comments

Hello,

I encounter a problem when I'm testing my app. When I'm starting a audio + video conversation with the Airpods, the sound is correctly broadcast in my ears but if I disconnect my airpods, the audio is redirected to the "small speaker" (the speaker used when you're in a phone call) instead of the "loud speaker" (the big one usually used in video calls)

First test (Working):

  • Starting video conversation WITHOUT airpods -> audio broadcast through the loud speaker ✅
  • Connecting the airpods -> audio is redirected to the airpods ✅
  • Disconnecting the airpods -> audio is redirect to the loud speaker ✅

Failing test:

  • Starting video conversation WITH airpods -> audio broadcast through the airpods ✅
  • Disconnecting the airpods -> audio is redirect to the "small speaker" ❌ The audio should be redirected to the "loud speaker"

My code which manage InCallManager:

private async initIncallManager() {
        await InCallManager.checkRecordPermission()
        InCallManager.start({ media: 'video' })
        InCallManager.setKeepScreenOn(true)

        if (Platform.OS === 'ios') {
            InCallManager.setForceSpeakerphoneOn(!InCallManager.getIsWiredHeadsetPluggedIn())
        }

        DeviceEventEmitter.addListener('WiredHeadset', ({ isPlugged, hasMic }: WiredHeadsetEventData) => {
            if (isPlugged && hasMic) {
                InCallManager.setForceSpeakerphoneOn(false)
            } else if (Platform.OS === 'ios') {
                InCallManager.setForceSpeakerphoneOn(!isPlugged) // Afin de forcer l'utilisation du speaker si on déconnecte des Airpods
            } else if (Platform.OS === 'android') {
                InCallManager.setSpeakerphoneOn(!isPlugged) // Afin de forcer l'utilisation du speaker si on déconnecte des Airpods
            }
        })
    }

The audio is not redirected correctly. I don't think my code changes anything to the audio redirection behavior. Is there a fix, workaround or any information about this case ?

Thank you

Pandazaur avatar May 17 '22 09:05 Pandazaur

hey @Pandazaur i have the same problem now as you, did you find a solution for this?

wilmxre avatar Nov 02 '23 10:11 wilmxre

@wilmxre If I remember well, I added this custom code in my AppDelegate.m

#import <WebRTC/RTCAudioSessionConfiguration.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // ....
    
    RTCAudioSessionConfiguration *webRTCConfiguration = [RTCAudioSessionConfiguration webRTCConfiguration];

      webRTCConfiguration.categoryOptions = (
         AVAudioSessionCategoryOptionAllowBluetooth | 
         AVAudioSessionCategoryOptionDefaultToSpeaker
      );
      
      return YES;
}

Pandazaur avatar Nov 02 '23 10:11 Pandazaur