Skip to content

Commit 5fda5b0

Browse files
manuquentinJoL0712
authored andcommitted
Add iOS setup options for overriding AVAudioSession setCategory options and setMode mode during configureAudioSession.
1 parent aa681cb commit 5fda5b0

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ Alternative on iOS you can perform setup in `AppDelegate.m`. Doing this allows c
130130
- `displayCallReachabilityTimeout`: number in ms (optional)
131131
If provided, starts a timeout that checks if the application is reachable and ends the call if not (Default: null)
132132
You'll have to call `setReachable()` as soon as your Javascript application is started.
133+
- `audioSession`: object
134+
- `categoryOptions`: AudioSessionCategoryOption|number (optional)
135+
If provided, it will override the default AVAudioSession setCategory options.
136+
- `mode`: AudioSessionMode|string (optional)
137+
If provided, it will override the default AVAudioSession setMode mode.
133138
- `android`: object
134139
- `alertTitle`: string (required)
135140
When asking for _phone account_ permission, we need to provider a title for the `Alert` to ask the user for it

index.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,29 @@ declare module 'react-native-callkeep' {
6464
selected?: boolean
6565
}
6666

67+
export enum AudioSessionCategoryOption {
68+
mixWithOthers = 0x1,
69+
duckOthers = 0x2,
70+
interruptSpokenAudioAndMixWithOthers = 0x11,
71+
allowBluetooth = 0x4,
72+
allowBluetoothA2DP = 0x20,
73+
allowAirPlay = 0x40,
74+
defaultToSpeaker = 0x8,
75+
overrideMutedMicrophoneInterruption = 0x80,
76+
}
77+
78+
export enum AudioSessionMode {
79+
default = 'AVAudioSessionModeDefault',
80+
gameChat = 'AVAudioSessionModeGameChat',
81+
measurement = 'AVAudioSessionModeMeasurement',
82+
moviePlayback = 'AVAudioSessionModeMoviePlayback',
83+
spokenAudio = 'AVAudioSessionModeSpokenAudio',
84+
videoChat = 'AVAudioSessionModeVideoChat',
85+
videoRecording = 'AVAudioSessionModeVideoRecording',
86+
voiceChat = 'AVAudioSessionModeVoiceChat',
87+
voicePrompt = 'AVAudioSessionModeVoicePrompt',
88+
}
89+
6790
interface IOptions {
6891
ios: {
6992
appName: string,
@@ -73,6 +96,10 @@ declare module 'react-native-callkeep' {
7396
maximumCallsPerCallGroup?: string,
7497
ringtoneSound?: string,
7598
includesCallsInRecents?: boolean
99+
audioSession?: {
100+
categoryOptions?: AudioSessionCategoryOption | number,
101+
mode?: AudioSessionMode | string,
102+
}
76103
},
77104
android: {
78105
alertTitle: string,

ios/RNCallKeep/RNCallKeep.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,10 +896,24 @@ - (void)configureAudioSession
896896
NSLog(@"[RNCallKeep][configureAudioSession] Activating audio session");
897897
#endif
898898

899+
NSUInteger categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP;
900+
NSString *mode = AVAudioSessionModeDefault;
901+
902+
NSDictionary *settings = [RNCallKeep getSettings];
903+
if (settings && settings[@"audioSession"]) {
904+
if (settings[@"audioSession"][@"categoryOptions"]) {
905+
categoryOptions = [settings[@"audioSession"][@"categoryOptions"] integerValue];
906+
}
907+
908+
if (settings[@"audioSession"][@"mode"]) {
909+
mode = settings[@"audioSession"][@"mode"];
910+
}
911+
}
912+
899913
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
900-
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP error:nil];
914+
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:categoryOptions error:nil];
901915

902-
[audioSession setMode:AVAudioSessionModeDefault error:nil];
916+
[audioSession setMode:mode error:nil];
903917

904918
double sampleRate = 44100.0;
905919
[audioSession setPreferredSampleRate:sampleRate error:nil];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-callkeep",
3-
"version": "4.3.8",
3+
"version": "4.3.9",
44
"description": "iOS 10 CallKit and Android ConnectionService Framework For React Native",
55
"main": "index.js",
66
"scripts": {},

0 commit comments

Comments
 (0)