From 5fda5b0dcccad8d1e0ba388490a839ffcf50e5db Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Mon, 12 Jun 2023 07:29:03 -0400 Subject: [PATCH 1/2] Add iOS setup options for overriding AVAudioSession setCategory options and setMode mode during configureAudioSession. --- README.md | 5 +++++ index.d.ts | 27 +++++++++++++++++++++++++++ ios/RNCallKeep/RNCallKeep.m | 18 ++++++++++++++++-- package.json | 2 +- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f81b7686..636a8212 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,11 @@ Alternative on iOS you can perform setup in `AppDelegate.m`. Doing this allows c - `displayCallReachabilityTimeout`: number in ms (optional) If provided, starts a timeout that checks if the application is reachable and ends the call if not (Default: null) You'll have to call `setReachable()` as soon as your Javascript application is started. + - `audioSession`: object + - `categoryOptions`: AudioSessionCategoryOption|number (optional) + If provided, it will override the default AVAudioSession setCategory options. + - `mode`: AudioSessionMode|string (optional) + If provided, it will override the default AVAudioSession setMode mode. - `android`: object - `alertTitle`: string (required) When asking for _phone account_ permission, we need to provider a title for the `Alert` to ask the user for it diff --git a/index.d.ts b/index.d.ts index ee1a7fbe..9ef03829 100644 --- a/index.d.ts +++ b/index.d.ts @@ -64,6 +64,29 @@ declare module 'react-native-callkeep' { selected?: boolean } + export enum AudioSessionCategoryOption { + mixWithOthers = 0x1, + duckOthers = 0x2, + interruptSpokenAudioAndMixWithOthers = 0x11, + allowBluetooth = 0x4, + allowBluetoothA2DP = 0x20, + allowAirPlay = 0x40, + defaultToSpeaker = 0x8, + overrideMutedMicrophoneInterruption = 0x80, + } + + export enum AudioSessionMode { + default = 'AVAudioSessionModeDefault', + gameChat = 'AVAudioSessionModeGameChat', + measurement = 'AVAudioSessionModeMeasurement', + moviePlayback = 'AVAudioSessionModeMoviePlayback', + spokenAudio = 'AVAudioSessionModeSpokenAudio', + videoChat = 'AVAudioSessionModeVideoChat', + videoRecording = 'AVAudioSessionModeVideoRecording', + voiceChat = 'AVAudioSessionModeVoiceChat', + voicePrompt = 'AVAudioSessionModeVoicePrompt', + } + interface IOptions { ios: { appName: string, @@ -73,6 +96,10 @@ declare module 'react-native-callkeep' { maximumCallsPerCallGroup?: string, ringtoneSound?: string, includesCallsInRecents?: boolean + audioSession?: { + categoryOptions?: AudioSessionCategoryOption | number, + mode?: AudioSessionMode | string, + } }, android: { alertTitle: string, diff --git a/ios/RNCallKeep/RNCallKeep.m b/ios/RNCallKeep/RNCallKeep.m index e67c3cdc..96f67833 100644 --- a/ios/RNCallKeep/RNCallKeep.m +++ b/ios/RNCallKeep/RNCallKeep.m @@ -896,10 +896,24 @@ - (void)configureAudioSession NSLog(@"[RNCallKeep][configureAudioSession] Activating audio session"); #endif + NSUInteger categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP; + NSString *mode = AVAudioSessionModeDefault; + + NSDictionary *settings = [RNCallKeep getSettings]; + if (settings && settings[@"audioSession"]) { + if (settings[@"audioSession"][@"categoryOptions"]) { + categoryOptions = [settings[@"audioSession"][@"categoryOptions"] integerValue]; + } + + if (settings[@"audioSession"][@"mode"]) { + mode = settings[@"audioSession"][@"mode"]; + } + } + AVAudioSession* audioSession = [AVAudioSession sharedInstance]; - [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP error:nil]; + [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:categoryOptions error:nil]; - [audioSession setMode:AVAudioSessionModeDefault error:nil]; + [audioSession setMode:mode error:nil]; double sampleRate = 44100.0; [audioSession setPreferredSampleRate:sampleRate error:nil]; diff --git a/package.json b/package.json index d9f0c000..de8f2ddc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-callkeep", - "version": "4.3.8", + "version": "4.3.9", "description": "iOS 10 CallKit and Android ConnectionService Framework For React Native", "main": "index.js", "scripts": {}, From 187c365c04247eb1413518ba5ab35de894ca7596 Mon Sep 17 00:00:00 2001 From: John Lee Date: Mon, 3 Jul 2023 20:39:51 -0700 Subject: [PATCH 2/2] Adding javascript constants for AudioSessionCategoryOption and AudioSessionMode. --- index.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9f1312b4..7d31715d 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,29 @@ const RNCallKeepModule = NativeModules.RNCallKeep; const isIOS = Platform.OS === 'ios'; const supportConnectionService = !isIOS && Platform.Version >= 23; +const AudioSessionCategoryOption = { + mixWithOthers: 0x1, + duckOthers: 0x2, + interruptSpokenAudioAndMixWithOthers: 0x11, + allowBluetooth: 0x4, + allowBluetoothA2DP: 0x20, + allowAirPlay: 0x40, + defaultToSpeaker: 0x8, + overrideMutedMicrophoneInterruption: 0x80, +} + +const AudioSessionMode = { + default: 'AVAudioSessionModeDefault', + gameChat: 'AVAudioSessionModeGameChat', + measurement: 'AVAudioSessionModeMeasurement', + moviePlayback: 'AVAudioSessionModeMoviePlayback', + spokenAudio: 'AVAudioSessionModeSpokenAudio', + videoChat: 'AVAudioSessionModeVideoChat', + videoRecording: 'AVAudioSessionModeVideoRecording', + voiceChat: 'AVAudioSessionModeVoiceChat', + voicePrompt: 'AVAudioSessionModeVoicePrompt', +} + const CONSTANTS = { END_CALL_REASONS: { FAILED: 1, @@ -17,7 +40,7 @@ const CONSTANTS = { }, }; -export { emit, CONSTANTS }; +export { emit, CONSTANTS, AudioSessionCategoryOption, AudioSessionMode }; class EventListener { constructor(type, listener, callkeep) {