Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

rcidt
Copy link

@rcidt rcidt commented Mar 31, 2022

Fixes #540

@@ -570,20 +585,6 @@ + (NSArray *) getAudioInputs

AVAudioSession* myAudioSession = [AVAudioSession sharedInstance];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and I noticed if we remove the setCategory from the getAudioInputs, the availableInputs are not up-to-date, I mean if in the meantime you remove a connected bluetooth device, the availableInputs are not updated

Copy link
Author

@rcidt rcidt Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nagyszili I am not seeing that issue. Are you relying on the RNCallKeepDidChangeAudioRoute event or are you using the getAudioRoutes method?

Copy link

@nagyszili nagyszili Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using the getAudioRoutes , please try it when a call is connected, my suggestion is to set the category in the getAudioInputs when there is no call connected

@Hesowcharov
Copy link

Hesowcharov commented Jun 16, 2022

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

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

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The getAudioRoutes changes the selected audio route
4 participants