Skip to content

Commit 27fa712

Browse files
committed
fix crash on null inputs
1 parent afc758c commit 27fa712

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

ios/RNTwilioClient/RNAudioManager.m

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,20 @@ - (AVAudioSessionPortDescription*)getAudioDeviceFromType:(NSString*)type {
116116
- (void)handleAudioRouteChange: (NSNotification *) notification {
117117
NSInteger routeChangeReason = [notification.userInfo[AVAudioSessionRouteChangeReasonKey] integerValue] || 0;
118118
AVAudioSession* session = [AVAudioSession sharedInstance];
119+
NSArray<AVAudioSessionPortDescription *> *inputs = session.currentRoute.inputs;
120+
NSArray<AVAudioSessionPortDescription *> *outputs = session.currentRoute.outputs;
119121

120-
AVAudioSessionPortDescription *input = [[session.currentRoute.inputs count] ? session.currentRoute.inputs:nil objectAtIndex:0];
121-
AVAudioSessionPortDescription *output = [[session.currentRoute.outputs count] ? session.currentRoute.outputs:nil objectAtIndex:0];
122-
NSString *reason = [self getAudioChangeReason: routeChangeReason];
123-
124-
AVAudioSessionRouteDescription *previousRoute = notification.userInfo[AVAudioSessionRouteChangePreviousRouteKey];
125-
AVAudioSessionPortDescription *previousInput = [[previousRoute.inputs count] ? previousRoute.inputs:nil objectAtIndex:0];
126-
AVAudioSessionPortDescription *previousOutput = [[previousRoute.outputs count] ? previousRoute.outputs:nil objectAtIndex:0];
122+
if (inputs && inputs.count > 0) {
123+
AVAudioSessionPortDescription *input = [[inputs count] ? inputs:nil objectAtIndex:0];
124+
AVAudioSessionPortDescription *output = [[outputs count] ? outputs:nil objectAtIndex:0];
125+
NSString *reason = [self getAudioChangeReason: routeChangeReason];
127126

128-
NSLog(@"[IIMobile - RNAudioManager][handleRouteChange] with reason %@ from INPUT %@ to %@", reason, previousInput.portType, input.portType);
129-
NSLog(@"[IIMobile - RNAudioManager][handleRouteChange] with reason %@ from OUTPUT %@ to %@", reason, previousOutput.portType, output.portType);
127+
AVAudioSessionRouteDescription *previousRoute = notification.userInfo[AVAudioSessionRouteChangePreviousRouteKey];
128+
AVAudioSessionPortDescription *previousInput = [[previousRoute.inputs count] ? previousRoute.inputs:nil objectAtIndex:0];
129+
AVAudioSessionPortDescription *previousOutput = [[previousRoute.outputs count] ? previousRoute.outputs:nil objectAtIndex:0];
130130

131-
if (input != nil) {
131+
NSLog(@"[IIMobile - RNAudioManager][handleRouteChange] with reason %@ from INPUT %@ to %@", reason, previousInput.portType, input.portType);
132+
NSLog(@"[IIMobile - RNAudioManager][handleRouteChange] with reason %@ from OUTPUT %@ to %@", reason, previousOutput.portType, output.portType);
132133
if (!([input.portType isEqualToString:AVAudioSessionPortBuiltInMic] && speakerEnabled)) {
133134
[RNEventEmitterHelper emitEventWithName:@"audioRouteChanged"
134135
andPayload:@{

0 commit comments

Comments
 (0)