what options need to set for audiocalling in react...
# ask-ai
d
what options need to set for audiocalling in react native expo iOS inside RNCallKeep.setSettings
t
Thanks for reaching out, Kanchan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you set up audio calling in React Native Expo iOS using
RNCallKeep.setSettings
, here’s a friendly guide on the options you’ll want to configure under the
ios
section: • appName: This is where you specify your app's name as it will appear in CallKit. • includeCallsInRecents: A true or false setting that decides if calls show up in the recent calls list (feel free to set it to
false
if you don’t want that). • audioSession: This object holds your audio session settings: ◦ categoryOptions: Combine options like
allowAirPlay
,
allowBluetooth
,
allowBluetoothA2DP
, and
defaultToSpeaker
to tailor the audio experience. ◦ mode: Setting this to
AudioSessionMode.videoChat
helps optimize voice and audio calling behavior. Here’s a simple example to get you started:
Copy code
const options = {
  ios: {
    appName: 'YourAppName',
    includeCallsInRecents: false,
    audioSession: {
      categoryOptions:
        AudioSessionCategoryOption.allowAirPlay +
        AudioSessionCategoryOption.allowBluetooth +
        AudioSessionCategoryOption.allowBluetoothA2DP +
        AudioSessionCategoryOption.defaultToSpeaker,
      mode: AudioSessionMode.videoChat,
    },
  },
  android: {
    alertTitle: 'Permissions required',
    alertDescription: 'This application needs to access your phone accounts',
    cancelButton: 'Cancel',
    okButton: 'Ok',
    imageName: 'phone_account_icon',
    additionalPermissions: [],
  },
};

RNCallKeep.setSettings(options);
When working specifically with Expo, here are a few important tips to keep in mind: • Make sure to use
expo-dev-client
for your development builds because LiveKit doesn’t play nicely with the Expo Go app. • Add the LiveKit Expo plugin to your
app.json
like this:
Copy code
{
  "expo": {
    "plugins": [
      "@livekit/expo-plugin"
    ]
  }
}
• Don’t forget to call
registerGlobals()
in your App.js to set up the necessary WebRTC libraries. • To enable background audio on iOS, add the "Background Modes" capability in Xcode and make sure "Audio, AirPlay, and Picture in Picture" is selected. If you have any questions or need a hand with anything else, just let me know—I’m here to help! Sources: Expo quickstart | LiveKit docs | Camera & microphone | LiveKit Docs | README.md
d
for doing audio call does i need to enable voip
t
Hi there! I wanted to share a little tip that can really help improve your calling experience. While enabling VoIP background mode isn’t absolutely necessary for audio calls to work when the app is open, it’s highly recommended to keep your calls stable and reliable, especially if the app is running in the background. If VoIP mode isn’t enabled, you might run into a few hiccups like: • The app getting suspended when it’s in the background, which can cause audio dropouts or calls to disconnect unexpectedly. • Missing incoming calls if the app isn’t the active window. • Interruptions in real-time communication, even if audio tracks are active. To help your app handle calls smoothly in the background, you can add both
audio
and
voip
to the
UIBackgroundModes
array in your app’s
Info.plist
file like this:
Copy code
<key>UIBackgroundModes</key>
<array>
  <string>voip</string>
  <string>audio</string>
</array>
This little change helps keep your app active during calls and avoids interruptions. If you have any questions or need a hand with this, just let me know—I’m here to help! Sources: docs/classes/AudioSession.html | Documentation/iOSInstallation.md
d
give me proper step by step configurations for AudioSessionMode.voiceChat i want to do voicecalling using livekit what modes do i need to enable what things are required
t
To help you configure
AudioSessionMode.voiceChat
for voice calling using LiveKit, here’s a friendly step-by-step guide you can follow: 1. Set the Audio Session Category: Start by using
AVAudioSession.Category.playAndRecord
. This setting allows your app to handle both audio input (like your microphone) and output (through speakers or a headset). 2. Configure Audio Session Category Options: Here are some options to include: ◦ `.mixWithOthers`: This lets background audio keep playing, so nothing gets interrupted. ◦ `.allowBluetooth`: Makes sure Bluetooth headsets and microphones work smoothly. ◦ `.allowBluetoothA2DP`: Supports high-quality audio when using Bluetooth A2DP devices. ◦ `.allowAirPlay`: Lets you stream audio to AirPlay devices effortlessly. 1. Set the Audio Session Mode: Use
AVAudioSession.Mode.voiceChat
to optimize the audio for real-time voice communication, which is perfect for calls. 2. Apply the Configuration via WebRTC: Here’s a snippet you can use in your app to set this up:
Copy code
let config = RTCAudioSessionConfiguration()
config.category = AVAudioSession.Category.playAndRecord.rawValue
config.categoryOptions = [
  .mixWithOthers,
  .allowBluetooth,
  .allowBluetoothA2DP,
  .allowAirPlay
]
config.mode = AVAudioSession.Mode.voiceChat.rawValue

RTCAudioSessionConfiguration.setWebRTC(config)
Just a couple more helpful notes: • If you’re working with React Native, try using
configureAudio
with
{ ios: { defaultOutput: 'earpiece' } }
— this will trigger the
voiceChat
mode for you. • Don’t forget to enable the background modes
audio
and
voip
in your app’s
Info.plist
file to keep calls running smoothly even when your app is in the background:
Copy code
<key>UIBackgroundModes</key>
<array>
  <string>voip</string>
  <string>audio</string>
</array>
This setup helps ensure your audio routes correctly, supports Bluetooth devices, and handles background calls seamlessly. If you have any questions or need a hand with anything else, just let me know — I’m here to help! Sources: Sources/LiveKit/Types/AudioSessionConfiguration.swift | shared_swift/LiveKitPlugin.swift | ios/LiveKitReactNativeModule.swift
d
give me configuration options like this for voice chat const options = { ios: { appName: 'LiveKitReactNative', includesCallsInRecents: false, audioSession: { categoryOptions: AudioSessionCategoryOption.allowAirPlay | AudioSessionCategoryOption.allowBluetooth | AudioSessionCategoryOption.allowBluetoothA2DP | AudioSessionCategoryOption.defaultToSpeaker | AudioSessionCategoryOption.mixWithOthers, mode: AudioSessionMode.voiceChat, }, }, // Android isn't used, but these fields are required for type safety. android: { alertTitle: 'Permissions required', alertDescription: 'This application needs to access your phone accounts', cancelButton: 'Cancel', okButton: 'Ok', imageName: 'phone_account_icon', additionalPermissions: [], foregroundService: { channelId: 'io.livekit.reactnative', channelName: 'Foreground Service', notificationTitle: 'LiveKit React Native Example is running in the background', }, }, }; RNCallKeep.setSettings(options); RNCallKeep.addEventListener('didChangeAudioRoute', () => { console.log("audio route is changed"); }); // To quell warnings. // For apps handling incoming calls from the background. RNCallKeep.addEventListener('didActivateAudioSession', () => { console.log("session is activated"); RTCAudioSession.audioSessionDidActivate(); }); RNCallKeep.addEventListener('didDeactivateAudioSession', () => { console.log("session is deactivated"); RTCAudioSession.audioSessionDidDeactivate(); }); also when during calling when going on a app like instagram which already using the microphone disconnecting the call whereas on other apps calling is running fine
t
Let's walk through how to set up voice chat using
AudioSessionMode.voiceChat
in RNCallKeep and smoothly handle any microphone conflicts you might encounter. Here’s a step-by-step guide for you: 1. RNCallKeep Configuration: First, set the audio session mode and category options for iOS like this:
Copy code
const options = {
  ios: {
    appName: 'YourApp',
    audioSession: {
      mode: AudioSessionMode.voiceChat, // Use voiceChat mode
      categoryOptions: [
        AudioSessionCategoryOption.allowBluetooth,
        AudioSessionCategoryOption.allowBluetoothA2DP,
        AudioSessionCategoryOption.defaultToSpeaker,
        AudioSessionCategoryOption.mixWithOthers
      ].reduce((acc, option) => acc + option, 0)
    }
  },
  android: {
    alertTitle: 'Permissions required',
    alertDescription: 'This application needs to access your phone accounts',
    cancelButton: 'Cancel',
    okButton: 'Ok',
    imageName: 'phone_account_icon',
    foregroundService: {
      channelId: 'io.livekit.reactnative',
      channelName: 'Foreground Service',
      notificationTitle: 'LiveKit React Native Example is running in the background',
    },
  }
};

RNCallKeep.setSettings(options);
1. LiveKit Audio Configuration: Next, configure LiveKit’s audio session specifically for voice chat like this:
Copy code
import AudioSession, { AppleAudioCategory, AppleAudioMode, AppleAudioCategoryOption } from '@livekit/react-native';

const audioConfig = {
  ios: {
    audioCategory: AppleAudioCategory.playAndRecord,
    audioCategoryOptions: [
      AppleAudioCategoryOption.allowBluetooth,
      AppleAudioCategoryOption.mixWithOthers
    ],
    audioMode: AppleAudioMode.voiceChat,
  },
  android: { /* Android settings if needed */ }
};

await AudioSession.configureAudio(audioConfig);
await AudioSession.startAudioSession();
1. Handle Microphone Conflicts: Sometimes, other apps like Instagram might use the microphone, causing iOS to deactivate your app’s audio session. To manage this gracefully, add these event listeners to respond to session activation and deactivation:
Copy code
RNCallKeep.addEventListener('didActivateAudioSession', () => {
  console.log("Audio session activated");
  RTCAudioSession.audioSessionDidActivate();
});

RNCallKeep.addEventListener('didDeactivateAudioSession', () => {
  console.log("Audio session deactivated");
  RTCAudioSession.audioSessionDidDeactivate();
});
A couple of helpful tips: • Make sure to enable
mixWithOthers
so your app’s audio can coexist with other sounds in the background, even though microphone access stays exclusive. • For Android, LiveKit takes care of audio focus automatically. You can also use
manageAudioFocus: true
if you want to handle interruptions more explicitly. If you have any questions or want me to clarify anything, just let me know—I’m here to help! Sources: Docs/audio.md | docs/index.html
d
Object literal may only specify known properties, and 'audioCategory' does not exist in type, also my app is still suspending from the background when going on apps like instagram whereas on other apps its working fine
t
Let's work together to resolve the
'audioCategory'
type error and keep your app running smoothly in the background when switching to apps like Instagram. Here’s a step-by-step guide to help you through this: 1. Fix the 'audioCategory' Type Error: Make sure you’re using the right types and valid values for
AppleAudioConfiguration
in LiveKit React Native. Here’s how you can do it:
Copy code
import { 
  AudioSession, 
  AppleAudioConfiguration, 
  AppleAudioCategory 
} from '@livekit/react-native';

const audioConfig: AppleAudioConfiguration = {
  audioCategory: 'playAndRecord', // Valid AppleAudioCategory value
  audioCategoryOptions: ['defaultToSpeaker', 'allowBluetooth'],
  audioMode: 'voiceChat'
};

await AudioSession.setAppleAudioConfiguration(audioConfig);
1. Prevent App Suspension in the Background: To keep your app connected while running in the background, using CallKit is a great approach. Here’s what to do: • Install react-native-callkeep:
npm install react-native-callkeep
• Configure CallKit:
Copy code
import RNCallKeep, {
  AudioSessionCategoryOption,
  AudioSessionMode
} from 'react-native-callkeep';
import { RTCAudioSession } from '@livekit/react-native-webrtc';

const options = {
  ios: {
    appName: 'YourApp',
    includeCallsInRecents: false,
    audioSession: {
      categoryOptions:
        AudioSessionCategoryOption.allowAirPlay +
        AudioSessionCategoryOption.allowBluetooth +
        AudioSessionCategoryOption.allowBluetoothA2DP +
        AudioSessionCategoryOption.defaultToSpeaker,
      mode: AudioSessionMode.voiceChat,
    },
  },
  android: {
    alertTitle: 'Permissions required',
    alertDescription: 'This application needs to access your phone accounts',
    cancelButton: 'Cancel',
    okButton: 'Ok',
    imageName: 'phone_account_icon',
    foregroundService: {
      channelId: 'io.livekit.reactnative',
      channelName: 'Foreground Service',
      notificationTitle: 'LiveKit React Native Example is running in the background',
    },
  },
};

RNCallKeep.setSettings(options);
• Handle Audio Session Events:
Copy code
RNCallKeep.addEventListener('didActivateAudioSession', () => {
  RTCAudioSession.audioSessionDidActivate();
});

RNCallKeep.addEventListener('didDeactivateAudioSession', () => {
  RTCAudioSession.audioSessionDidDeactivate();
});
• Enable Background Modes: Don’t forget to add these keys to your
Info.plist
to support background audio and VoIP:
Copy code
<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
  <string>voip</string>
</array>
• Start and Stop Call Service:
Copy code
let uuid = '1932b99c-4fe1-4bf4-897f-763bc4dc21c2';

export async function startCallService() {
  let handle = '1234567';
  let contactIdentifier = 'Caller Contact';
  RNCallKeep.startCall(uuid, handle, contactIdentifier, 'number', true);
  RNCallKeep.reportConnectingOutgoingCallWithUUID(uuid);
  setTimeout(() => {
    RNCallKeep.reportConnectedOutgoingCallWithUUID(uuid);
  }, 100);
}

export async function stopCallService() {
  RNCallKeep.endCall(uuid);
}
By following these steps, your app should stay active during calls and avoid suspension when users switch to other apps. If you have any questions or need a hand with any part of this, please don’t hesitate to reach out—I’m here to help! Sources: docs/index.html
d
does after adding voip in the background modes does it need to enable in the entitlements and from the apple side
t
Absolutely! After adding VoIP in the background modes, it’s important to also enable it in the entitlements and set it up correctly in Xcode. Here’s a simple guide to help you through the process: 1. Enable Background Modes in Xcode: Head over to your app target in Xcode, go to the "Signing & Capabilities" tab, add the "Background Modes" capability, and make sure to check both: ◦ Audio, AirPlay, and Picture in Picture ◦ Voice over IP (VoIP) 1. Configure Entitlements: If you’re using VoIP push notifications with PushKit, don’t forget to enable the
com.apple.developer.pushkit.unrestricted-voip
entitlement in your app’s entitlements file. This step is key to allowing your app to receive VoIP push notifications and handle incoming calls while running in the background. These settings will help your app stay active in the background for smooth VoIP functionality. If you have any questions or need a hand with anything else, just let me know—I’m here to help! Sources: Tests/LKTestHost/LKTestHost/Info.plist | callkit/README.md | README.md
d
i'm not using pushkit
t
If you’re not using PushKit, no worries! You can still enable VoIP functionality for background audio and call handling without needing to configure the
com.apple.developer.pushkit.unrestricted-voip
entitlement. Here’s a simple way to do it: 1. Enable Background Modes in Xcode: Head over to your app target in Xcode, click on the "Signing & Capabilities" tab, add the "Background Modes" capability, and make sure to check both: ◦ Audio, AirPlay, and Picture in Picture ◦ Voice over IP (VoIP) 1. Configure RNCallKeep and Audio Session: Make sure your app is set up correctly to handle audio sessions and CallKit events, just like we discussed before. This setup helps your app keep audio running smoothly in the background without needing PushKit. If you have any questions or need a hand with this, please don’t hesitate to reach out—I’m here to help!
d
but my app is suspending when going on some apps which using camera and mixrophone already
t
To help keep your app running smoothly when switching to other apps that use the camera and microphone, here are some friendly steps you can follow: 1. Enable Background Modes in Xcode: Head over to your app target → Signing & Capabilities → Add Capability → Background Modes. Then, make sure to enable: ◦ `audio`: This lets your app keep processing audio even when it’s in the background. ◦ `voip`: This supports VoIP services, so your app can maintain long-running connections. 1. Integrate RNCallKeep: Try using react-native-callkeep to connect with iOS CallKit. This helps simulate an ongoing call, which prevents your app from being suspended. 2. Start a Call Service: When you join a LiveKit room, call
startCallService()
to let the system know there’s an active call happening:
Copy code
import { startCallService } from './CallService.ios';

// Call when connecting to room
startCallService();
1. Handle Audio Session Activation: It’s important to notify WebRTC when CallKit activates or deactivates the audio session. You can do this by listening for these events:
Copy code
RNCallKeep.addEventListener('didActivateAudioSession', () => {
  RTCAudioSession.audioSessionDidActivate();
});

RNCallKeep.addEventListener('didDeactivateAudioSession', () => {
  RTCAudioSession.audioSessionDidDeactivate();
});
1. Stop the Call Service: When you leave the room, remember to call
stopCallService()
to properly end the simulated call:
Copy code
import { stopCallService } from './CallService.ios';

stopCallService();
1. (Optional) Enable Background Camera Access (iOS 18+): If your app needs to access the camera while in the background, you can enable multitasking camera access in your native code like this:
Copy code
// Objective-C
[WebRTCModuleOptions sharedInstance].enableMultitaskingCameraAccess = YES;

// Swift
let options = WebRTCModuleOptions.sharedInstance()
options.enableMultitaskingCameraAccess = true
Also, don’t forget to declare
NSCameraUsageDescription
and
NSMicrophoneUsageDescription
in your
Info.plist
to keep everything running smoothly. If you have any questions or need a hand with any of these steps, just let me know — I’m here to help! Sources: README.md | Documentation/iOSInstallation.md
d
in background i need microphone access for calling communication
t
To help you ensure microphone access for calling communication in the background using LiveKit and RNCallKeep on iOS, here’s a friendly step-by-step guide: 1. Enable Background Modes in Xcode: Head over to your app target → Signing & Capabilities → Add Capability → Background Modes. Make sure to enable: ◦ `audio`: This lets your app process audio even when it’s running in the background. ◦ `voip`: This keeps your VoIP services connected for longer calls. 1. Request Microphone Permissions: Don’t forget to add the
NSMicrophoneUsageDescription
key in your
Info.plist
file with a clear explanation of why your app needs microphone access. Also, be sure to request this permission at runtime using a library like
react-native-permissions
. 2. Configure RNCallKeep: Set up RNCallKeep with the right audio session settings to make everything run smoothly:
Copy code
const options = {
  ios: {
    appName: 'YourApp',
    audioSession: {
      categoryOptions:
        AudioSessionCategoryOption.allowBluetooth +
        AudioSessionCategoryOption.allowBluetoothA2DP +
        AudioSessionCategoryOption.defaultToSpeaker,
      mode: AudioSessionMode.videoChat,
    },
  },
};
RNCallKeep.setSettings(options);
1. Handle Audio Session Events: It’s important to listen for RNCallKeep events so you can keep LiveKit’s WebRTC audio session in sync:
Copy code
RNCallKeep.addEventListener('didActivateAudioSession', () => {
  RTCAudioSession.audioSessionDidActivate();
});

RNCallKeep.addEventListener('didDeactivateAudioSession', () => {
  RTCAudioSession.audioSessionDidDeactivate();
});
1. Start LiveKit Audio Session: Finally, make sure LiveKit’s audio session is properly configured and started like this:
Copy code
import { AudioSession } from '@livekit/react-native';
await AudioSession.startAudioSession();
Following these steps should help keep your microphone active during background calls. If you have any questions or need a hand with any part of this, just let me know—I’m here to help! Sources: README.md | Camera & microphone | LiveKit Docs
d
what to configure in appdelegate.swift and app.json
t
To help you configure
AppDelegate.swift
and
app.json
for LiveKit and RNCallKeep on iOS, here’s a simple guide you can follow: 1. AppDelegate.swift Configuration: Start by adding the following code to initialize LiveKit. You can also optionally enable multitasking camera access for iOS 18 and above if needed:
Copy code
import livekit_react_native
import livekit_react_native_webrtc

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
  func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
  ) -> Bool {

    // Required: Initialize LiveKit
    LivekitReactNative.setup()

    // Optional: Enable multitasking camera access (iOS 18+, requires voip background mode)
    // let options = WebRTCModuleOptions.sharedInstance()
    // options.enableMultitaskingCameraAccess = true

    return true
  }
}
1. app.json Configuration: If you’re working with Expo, just add the LiveKit plugin to the
plugins
array in your
app.json
like this:
Copy code
{
  "expo": {
    "plugins": [
      [
        "../app.plugin.js",
        {
          "android": {
            "audioType": "media"
          }
        }
      ],
      "@config-plugins/react-native-webrtc"
    ]
  }
}
If your app isn’t using Expo, there’s no need to add anything specific to
app.json
for LiveKit or RNCallKeep. Please feel free to reach out if you have any questions or need a hand with anything else—I’m here to help! Sources: docs/index.html | Documentation/iOSInstallation.md | example/app.json | Camera & microphone | LiveKit Docs