@@ -542,10 +542,14 @@ + (void)setup:(NSDictionary *)options {
542
542
+ (NSMutableArray *) formatAudioInputs : (NSMutableArray *)inputs
543
543
{
544
544
NSMutableArray *newInputs = [NSMutableArray new ];
545
-
545
+ NSString * selected = [RNCallKeep getSelectedAudioRoute ];
546
+
546
547
NSMutableDictionary *speakerDict = [[NSMutableDictionary alloc ]init];
547
548
[speakerDict setObject: @" Speaker" forKey: @" name" ];
548
549
[speakerDict setObject: AVAudioSessionPortBuiltInSpeaker forKey: @" type" ];
550
+ if (selected && [selected isEqualToString: AVAudioSessionPortBuiltInSpeaker]){
551
+ [speakerDict setObject: @YES forKey: @" selected" ];
552
+ }
549
553
[newInputs addObject: speakerDict];
550
554
551
555
for (AVAudioSessionPortDescription* input in inputs)
@@ -556,6 +560,9 @@ + (NSMutableArray *) formatAudioInputs: (NSMutableArray *)inputs
556
560
NSString * type = [RNCallKeep getAudioInputType: input.portType];
557
561
if (type)
558
562
{
563
+ if ([selected isEqualToString: type]){
564
+ [dict setObject: @YES forKey: @" selected" ];
565
+ }
559
566
[dict setObject: type forKey: @" type" ];
560
567
[newInputs addObject: dict];
561
568
}
@@ -569,12 +576,18 @@ + (NSArray *) getAudioInputs
569
576
NSString *str = nil ;
570
577
571
578
AVAudioSession* myAudioSession = [AVAudioSession sharedInstance ];
579
+ NSString *category = [myAudioSession category ];
580
+ NSUInteger options = [myAudioSession categoryOptions ];
572
581
573
- BOOL isCategorySetted = [myAudioSession setCategory: AVAudioSessionCategoryPlayAndRecord withOptions: AVAudioSessionCategoryOptionAllowBluetooth error: &err];
574
- if (!isCategorySetted )
582
+
583
+ if (![category isEqualToString: AVAudioSessionCategoryPlayAndRecord] && (options != AVAudioSessionCategoryOptionAllowBluetooth) && (options !=AVAudioSessionCategoryOptionAllowBluetoothA2DP) )
575
584
{
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
+ }
578
591
}
579
592
580
593
BOOL isCategoryActivated = [myAudioSession setActive: YES error: &err];
@@ -613,6 +626,21 @@ + (NSString *) getAudioInputType: (NSString *) type
613
626
}
614
627
}
615
628
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
+
616
644
- (void )requestTransaction : (CXTransaction *)transaction
617
645
{
618
646
#ifdef DEBUG
0 commit comments