|
6 | 6 | #import <CallKit/CallKit.h> |
7 | 7 | #import "UUIDStorage.h" |
8 | 8 | #import "Settings.h" |
| 9 | +#import "AudioSessionManager.h" |
9 | 10 |
|
10 | 11 | #ifdef DEBUG |
11 | 12 | static int const OUTGOING_CALL_WAKEUP_DELAY = 10; |
@@ -364,42 +365,6 @@ - (void)dealloc { |
364 | 365 | // } |
365 | 366 | //} |
366 | 367 |
|
367 | | - |
368 | | -- (void)configureAudioSession { |
369 | | -#ifdef DEBUG |
370 | | - NSLog(@"[Callingx][configureAudioSession] Activating audio session"); |
371 | | -#endif |
372 | | - |
373 | | - NSUInteger categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth | |
374 | | - AVAudioSessionCategoryOptionAllowBluetoothA2DP; |
375 | | - NSString *mode = AVAudioSessionModeDefault; |
376 | | - |
377 | | - NSDictionary *settings = [Settings getSettings]; |
378 | | - if (settings && settings[@"audioSession"]) { |
379 | | - if (settings[@"audioSession"][@"categoryOptions"]) { |
380 | | - categoryOptions = [settings[@"audioSession"][@"categoryOptions"] integerValue]; |
381 | | - } |
382 | | - |
383 | | - if (settings[@"audioSession"][@"mode"]) { |
384 | | - mode = settings[@"audioSession"][@"mode"]; |
385 | | - } |
386 | | - } |
387 | | - |
388 | | - AVAudioSession *audioSession = [AVAudioSession sharedInstance]; |
389 | | - [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord |
390 | | - withOptions:categoryOptions |
391 | | - error:nil]; |
392 | | - |
393 | | - [audioSession setMode:mode error:nil]; |
394 | | - |
395 | | - double sampleRate = 44100.0; |
396 | | - [audioSession setPreferredSampleRate:sampleRate error:nil]; |
397 | | - |
398 | | - NSTimeInterval bufferDuration = .005; |
399 | | - [audioSession setPreferredIOBufferDuration:bufferDuration error:nil]; |
400 | | - [audioSession setActive:TRUE error:nil]; |
401 | | -} |
402 | | - |
403 | 368 | - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule: |
404 | 369 | (const facebook::react::ObjCTurboModule::InitParams &)params { |
405 | 370 | return std::make_shared<facebook::react::NativeCallingxSpecJSI>(params); |
@@ -499,7 +464,8 @@ - (void)setupiOS:(JS::NativeCallingx::SpecSetupiOSOptions &)options { |
499 | 464 | @"handleType" : options.handleType(), |
500 | 465 | @"ringtoneSound" : options.sound(), |
501 | 466 | @"imageName" : options.imageName(), |
502 | | - @"includesCallsInRecents" : @(options.callsHistory()) |
| 467 | + @"includesCallsInRecents" : @(options.callsHistory()), |
| 468 | + @"autoConfigureAudioSession" : @(options.setupAudioSession()) |
503 | 469 | }; |
504 | 470 |
|
505 | 471 | _version = [[[NSProcessInfo alloc] init] operatingSystemVersion]; |
@@ -814,7 +780,7 @@ - (void)provider:(CXProvider *)provider |
814 | 780 | return; |
815 | 781 | } |
816 | 782 | // do this first, audio sessions are flakey |
817 | | - [self configureAudioSession]; |
| 783 | + [AudioSessionManager createAudioSessionIfNeeded]; |
818 | 784 | // tell the JS to actually make the call |
819 | 785 | [self sendEventWithNameWrapper:CallingxDidReceiveStartCallAction |
820 | 786 | body:@{ |
@@ -850,7 +816,7 @@ - (void)provider:(CXProvider *)provider |
850 | 816 | return; |
851 | 817 | } |
852 | 818 |
|
853 | | - [self configureAudioSession]; |
| 819 | + [AudioSessionManager createAudioSessionIfNeeded]; |
854 | 820 | [self sendEventWithNameWrapper:CallingxPerformAnswerCallAction |
855 | 821 | body:@{ |
856 | 822 | @"callId" : callId |
@@ -961,7 +927,6 @@ - (void)provider:(CXProvider *)provider |
961 | 927 | object:nil |
962 | 928 | userInfo:userInfo]; |
963 | 929 |
|
964 | | - [self configureAudioSession]; |
965 | 930 | [self sendEventWithNameWrapper:CallingxDidActivateAudioSession body:nil]; |
966 | 931 | } |
967 | 932 |
|
|
0 commit comments