Skip to content

Commit

Permalink
Allow more audio routes
Browse files Browse the repository at this point in the history
  • Loading branch information
nagyszili committed Mar 14, 2022
1 parent ab0ed51 commit 0939989
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions ios/RNCallKeep/RNCallKeep.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ + (NSMutableDictionary *) getAudioOutput {
NSArray<AVAudioSessionPortDescription *> *outputs = [AVAudioSession sharedInstance].currentRoute.outputs;
if (outputs.count > 0) {
NSMutableDictionary *output = [[NSMutableDictionary alloc]init];
NSString * type = [RNCallKeep getAudioOutputType: outputs[0].portType];
NSString * type = [RNCallKeep getAudioPortType: outputs[0].portType];
[output setObject:outputs[0].portName forKey:@"name"];
[output setObject:type forKey:@"type"];
return output;
Expand Down Expand Up @@ -504,7 +504,7 @@ + (NSMutableArray *) formatAudioInputs: (NSMutableArray *)inputs
NSLog(@"%@",str);
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:input.portName forKey:@"name"];
NSString * type = [RNCallKeep getAudioInputType: input.portType];
NSString * type = [RNCallKeep getAudioPortType: input.portType];
if(type)
{
[dict setObject:type forKey:@"type"];
Expand All @@ -521,7 +521,8 @@ + (NSArray *) getAudioInputs

AVAudioSession* myAudioSession = [AVAudioSession sharedInstance];

BOOL isCategorySetted = [myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:&err];
BOOL isCategorySetted = [myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth |
AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionAllowAirPlay error:&err];
if (!isCategorySetted)
{
NSLog(@"setCategory failed");
Expand All @@ -539,41 +540,22 @@ + (NSArray *) getAudioInputs
return inputs;
}

+ (NSString *) getAudioInputType: (NSString *) type
+ (NSString *) getAudioPortType: (NSString *) type
{
if ([type isEqualToString:AVAudioSessionPortBuiltInMic]){
return @"Phone";
}
else if ([type isEqualToString:AVAudioSessionPortHeadsetMic]){
return @"Headset";
}
else if ([type isEqualToString:AVAudioSessionPortHeadphones]){
return @"Headset";
}
else if ([type isEqualToString:AVAudioSessionPortBluetoothHFP]){
return @"Bluetooth";
}
else if ([type isEqualToString:AVAudioSessionPortBluetoothA2DP]){
return @"Bluetooth";
if ([type isEqualToString:AVAudioSessionPortAirPlay]){
return @"AirPlay";
}
else if ([type isEqualToString:AVAudioSessionPortBuiltInSpeaker]){
return @"Speaker";
}
else{
return nil;
}
}

+ (NSString *) getAudioOutputType: (NSString *) type
{
if ([type isEqualToString:AVAudioSessionPortBuiltInReceiver]){
return @"Phone";
}
if ([type isEqualToString:AVAudioSessionPortBuiltInMic]){
return @"Phone";
}
else if ([type isEqualToString:AVAudioSessionPortHeadsetMic]){
return @"Headset";
return @"Headphones";
}
else if ([type isEqualToString:AVAudioSessionPortHeadphones]){
return @"Headset";
return @"Headphones";
}
else if ([type isEqualToString:AVAudioSessionPortBluetoothHFP]){
return @"Bluetooth";
Expand All @@ -592,6 +574,7 @@ + (NSString *) getAudioOutputType: (NSString *) type
}
}


- (void)requestTransaction:(CXTransaction *)transaction
{
#ifdef DEBUG
Expand Down Expand Up @@ -829,7 +812,8 @@ - (void)configureAudioSession
#endif

AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth |
AVAudioSessionCategoryOptionAllowBluetoothA2DP | AVAudioSessionCategoryOptionAllowAirPlay error:nil];

[audioSession setMode:AVAudioSessionModeDefault error:nil];

Expand Down

0 comments on commit 0939989

Please sign in to comment.