Skip to content

Commit 230bb73

Browse files
authored
Merge pull request #708 from JoL0712/master
Add iOS setup options for overriding AVAudioSession setCategory options and setMode mode
2 parents a360c6d + 2d18d1f commit 230bb73

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-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,

index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,29 @@ const RNCallKeepModule = NativeModules.RNCallKeep;
66
const isIOS = Platform.OS === 'ios';
77
const supportConnectionService = !isIOS && Platform.Version >= 23;
88

9+
const AudioSessionCategoryOption = {
10+
mixWithOthers: 0x1,
11+
duckOthers: 0x2,
12+
interruptSpokenAudioAndMixWithOthers: 0x11,
13+
allowBluetooth: 0x4,
14+
allowBluetoothA2DP: 0x20,
15+
allowAirPlay: 0x40,
16+
defaultToSpeaker: 0x8,
17+
overrideMutedMicrophoneInterruption: 0x80,
18+
}
19+
20+
const AudioSessionMode = {
21+
default: 'AVAudioSessionModeDefault',
22+
gameChat: 'AVAudioSessionModeGameChat',
23+
measurement: 'AVAudioSessionModeMeasurement',
24+
moviePlayback: 'AVAudioSessionModeMoviePlayback',
25+
spokenAudio: 'AVAudioSessionModeSpokenAudio',
26+
videoChat: 'AVAudioSessionModeVideoChat',
27+
videoRecording: 'AVAudioSessionModeVideoRecording',
28+
voiceChat: 'AVAudioSessionModeVoiceChat',
29+
voicePrompt: 'AVAudioSessionModeVoicePrompt',
30+
}
31+
932
const CONSTANTS = {
1033
END_CALL_REASONS: {
1134
FAILED: 1,
@@ -17,7 +40,7 @@ const CONSTANTS = {
1740
},
1841
};
1942

20-
export { emit, CONSTANTS };
43+
export { emit, CONSTANTS, AudioSessionCategoryOption, AudioSessionMode };
2144

2245
class EventListener {
2346
constructor(type, listener, callkeep) {

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];

0 commit comments

Comments
 (0)