react-native-callkeep icon indicating copy to clipboard operation
react-native-callkeep copied to clipboard

fix(ios): The getAudioRoutes changes the selected audio route

Open rcidt opened this issue 3 years ago • 2 comments

Fixes #540

rcidt avatar Mar 31 '22 17:03 rcidt

@rcidt First of all, thank you for PR!

I found your sumbission when I faced with another issue - #getAudioRoutes seems not working when an incoming call is ringing but not answered yet. The flow is following (iOS only!):

  1. displayIncomingCall (i.e. it plays the system ringtone)
  2. getAudioRoutes (to output all available audio routes before)
  3. answerCall / endCall

Without your fix, I catch the exception at setActive step in getAudioInputs (see here -> https://github.com/react-native-webrtc/react-native-callkeep/blob/8de84e3e139bedf4cc9a949b786e4fb287c7dc6a/ios/RNCallKeep/RNCallKeep.m#L593-L598):

Log:

2022-06-16 20:30:11.550015+0300 App[82985:4088420] [RNCallKeep][getAudioRoutes]
2022-06-16 20:30:11.560937+0300 App[82985:4088420] [RNCallKeep][getAudioInputs] setActive failed
2022-06-16 20:30:11.564230+0300 App[82985:4088420] [RNCallKeep][getAudioRoutes] exception: error: Error Domain=NSOSStatusErrorDomain Code=561017449 "(null)"
2022-06-16 20:30:11.711591+0300 App[82985:4088421] [javascript] [Error: null]

With your fix, the flow works great!

Several things to mention:

  1. please resolve the conflicts because your branch is outdated (I could port your changes on the master in the same manner)
  2. your suggested code set category and set the audio session active after getting the audioInputs:
        NSArray *ports = [RNCallKeep getAudioInputs];

        BOOL isCategorySetted = [myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&err];
        if (!isCategorySetted)
        {
            NSLog(@"[RNCallKeep][setAudioRoute] setCategory failed");
            [NSException raise:@"setCategory failed" format:@"error: %@", err];
        }

        BOOL isCategoryActivated = [myAudioSession setActive:YES error:&err];
        if (!isCategoryActivated)
        {
            NSLog(@"[RNCallKeep][setAudioRoute] setActive failed");
            [NSException raise:@"setActive failed" format:@"error: %@", err];
        }

        // => may be invoke getAudioInputs here after setting stuff ?
        for (AVAudioSessionPortDescription *port in ports) {

what about get the audio inputs after setting stuff ?

Hesowcharov avatar Jun 16 '22 17:06 Hesowcharov