@@ -131,12 +131,12 @@ - (void)startObserving
131
131
- (void )stopObserving
132
132
{
133
133
_hasListeners = FALSE ;
134
-
134
+
135
135
// Fix for https://github.com/react-native-webrtc/react-native-callkeep/issues/406
136
136
// We use Objective-C Key Value Coding(KVC) to sync _RTCEventEmitter_ `_listenerCount`.
137
137
@try {
138
138
[self setValue: @0 forKey: @" _listenerCount" ];
139
- }
139
+ }
140
140
@catch ( NSException *e ){
141
141
NSLog (@" [RNCallKeep][stopObserving] exception: %@ " ,e);
142
142
NSLog (@" [RNCallKeep][stopObserving] RNCallKeep parent class RTCEventEmitter might have a broken state." );
@@ -189,7 +189,16 @@ + (void)initCallKitProvider {
189
189
}
190
190
191
191
+ (NSString *) getAudioOutput {
192
- return [AVAudioSession sharedInstance ].currentRoute .outputs .count > 0 ? [AVAudioSession sharedInstance ].currentRoute .outputs [0 ].portType : nil ;
192
+ @try {
193
+ NSArray <AVAudioSessionPortDescription *>* outputs = [AVAudioSession sharedInstance ].currentRoute .outputs ;
194
+ if (outputs != nil && outputs.count > 0 ){
195
+ return outputs[0 ].portType ;
196
+ }
197
+ } @catch (NSException * error) {
198
+ NSLog (@" getAudioOutput error :%@ " , [error description ]);
199
+ }
200
+
201
+ return nil ;
193
202
}
194
203
195
204
+ (void )setup : (NSDictionary *)options {
@@ -554,7 +563,7 @@ + (NSMutableArray *) formatAudioInputs: (NSMutableArray *)inputs
554
563
{
555
564
NSMutableArray *newInputs = [NSMutableArray new ];
556
565
NSString * selected = [RNCallKeep getSelectedAudioRoute ];
557
-
566
+
558
567
NSMutableDictionary *speakerDict = [[NSMutableDictionary alloc ]init];
559
568
[speakerDict setObject: @" Speaker" forKey: @" name" ];
560
569
[speakerDict setObject: AVAudioSessionPortBuiltInSpeaker forKey: @" type" ];
@@ -645,13 +654,13 @@ + (NSString *) getSelectedAudioRoute
645
654
AVAudioSession* myAudioSession = [AVAudioSession sharedInstance ];
646
655
AVAudioSessionRouteDescription *currentRoute = [myAudioSession currentRoute ];
647
656
NSArray *selectedOutputs = currentRoute.outputs ;
648
-
657
+
649
658
AVAudioSessionPortDescription *selectedOutput = selectedOutputs[0 ];
650
-
659
+
651
660
if (selectedOutput && [selectedOutput.portType isEqualToString: AVAudioSessionPortBuiltInReceiver]) {
652
661
return @" Phone" ;
653
662
}
654
-
663
+
655
664
return [RNCallKeep getAudioInputType: selectedOutput.portType];
656
665
}
657
666
@@ -909,7 +918,7 @@ - (void)configureAudioSession
909
918
910
919
NSUInteger categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP;
911
920
NSString *mode = AVAudioSessionModeDefault;
912
-
921
+
913
922
NSDictionary *settings = [RNCallKeep getSettings ];
914
923
if (settings && settings[@" audioSession" ]) {
915
924
if (settings[@" audioSession" ][@" categoryOptions" ]) {
@@ -920,7 +929,7 @@ - (void)configureAudioSession
920
929
mode = settings[@" audioSession" ][@" mode" ];
921
930
}
922
931
}
923
-
932
+
924
933
AVAudioSession* audioSession = [AVAudioSession sharedInstance ];
925
934
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord withOptions: categoryOptions error: nil ];
926
935
0 commit comments