@@ -542,10 +542,14 @@ + (void)setup:(NSDictionary *)options {
542542+ (NSMutableArray *) formatAudioInputs : (NSMutableArray *)inputs
543543{
544544 NSMutableArray *newInputs = [NSMutableArray new ];
545-
545+ NSString * selected = [RNCallKeep getSelectedAudioRoute ];
546+
546547 NSMutableDictionary *speakerDict = [[NSMutableDictionary alloc ]init];
547548 [speakerDict setObject: @" Speaker" forKey: @" name" ];
548549 [speakerDict setObject: AVAudioSessionPortBuiltInSpeaker forKey: @" type" ];
550+ if (selected && [selected isEqualToString: AVAudioSessionPortBuiltInSpeaker]){
551+ [speakerDict setObject: @YES forKey: @" selected" ];
552+ }
549553 [newInputs addObject: speakerDict];
550554
551555 for (AVAudioSessionPortDescription* input in inputs)
@@ -556,6 +560,9 @@ + (NSMutableArray *) formatAudioInputs: (NSMutableArray *)inputs
556560 NSString * type = [RNCallKeep getAudioInputType: input.portType];
557561 if (type)
558562 {
563+ if ([selected isEqualToString: type]){
564+ [dict setObject: @YES forKey: @" selected" ];
565+ }
559566 [dict setObject: type forKey: @" type" ];
560567 [newInputs addObject: dict];
561568 }
@@ -569,12 +576,18 @@ + (NSArray *) getAudioInputs
569576 NSString *str = nil ;
570577
571578 AVAudioSession* myAudioSession = [AVAudioSession sharedInstance ];
579+ NSString *category = [myAudioSession category ];
580+ NSUInteger options = [myAudioSession categoryOptions ];
572581
573- BOOL isCategorySetted = [myAudioSession setCategory: AVAudioSessionCategoryPlayAndRecord withOptions: AVAudioSessionCategoryOptionAllowBluetooth error: &err];
574- if (!isCategorySetted )
582+
583+ if (![category isEqualToString: AVAudioSessionCategoryPlayAndRecord] && (options != AVAudioSessionCategoryOptionAllowBluetooth) && (options !=AVAudioSessionCategoryOptionAllowBluetoothA2DP) )
575584 {
576- NSLog (@" [RNCallKeep][getAudioInputs] setCategory failed" );
577- [NSException raise: @" setCategory failed" format: @" error: %@ " , err];
585+ BOOL isCategorySetted = [myAudioSession setCategory: AVAudioSessionCategoryPlayAndRecord withOptions: AVAudioSessionCategoryOptionAllowBluetooth error: &err];
586+ if (!isCategorySetted)
587+ {
588+ NSLog (@" setCategory failed" );
589+ [NSException raise: @" setCategory failed" format: @" error: %@ " , err];
590+ }
578591 }
579592
580593 BOOL isCategoryActivated = [myAudioSession setActive: YES error: &err];
@@ -613,6 +626,21 @@ + (NSString *) getAudioInputType: (NSString *) type
613626 }
614627}
615628
629+ + (NSString *) getSelectedAudioRoute
630+ {
631+ AVAudioSession* myAudioSession = [AVAudioSession sharedInstance ];
632+ AVAudioSessionRouteDescription *currentRoute = [myAudioSession currentRoute ];
633+ NSArray *selectedOutputs = currentRoute.outputs ;
634+
635+ AVAudioSessionPortDescription *selectedOutput = selectedOutputs[0 ];
636+
637+ if (selectedOutput && [selectedOutput.portType isEqualToString: AVAudioSessionPortBuiltInReceiver]) {
638+ return @" Phone" ;
639+ }
640+
641+ return [RNCallKeep getAudioInputType: selectedOutput.portType];
642+ }
643+
616644- (void )requestTransaction : (CXTransaction *)transaction
617645{
618646#ifdef DEBUG
0 commit comments