When making calls using LiveKit, the call continue...
# ask-ai
d
When making calls using LiveKit, the call continues to work properly in the lock state and when switching to apps like Home or Notes. However, the call disconnects when switching to apps such as WhatsApp or Snapchat.
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.
I understand how frustrating it can be when LiveKit calls disconnect as you switch to apps like WhatsApp or Snapchat. This usually happens because of background processing limits. But don’t worry, I’m here to help you set up your app to support background mode smoothly: For iOS: • Make sure to enable the
audio
and
voip
UIBackgroundModes in your Xcode project by going to Signing & Capabilities → Add Capability → Background Modes. • If you’re using Flutter, just add the following to your `Info.plist`:
Copy code
<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
</array>
• For the best experience, consider integrating CallKit and managing audio session activation and deactivation properly. For Android: • Set up a foreground service and don’t forget to declare the necessary permissions in your
AndroidManifest.xml
, like
android.permission.FOREGROUND_SERVICE
. • Also, declare the service with the right foreground service types such as
camera
,
microphone
, or
mediaPlayback
. Testing and configuring your audio sessions carefully will really help keep your calls connected even when switching apps. If you’d like, I’m here to walk you through any part of this or provide more details. Just let me know! Sources: docs/index.html | README.md | How We Built a Globally Distributed WebRTC Mesh Network
d
these permissions are already there it's disconnecting only when going the apps who are already using microphone like whatsapp instagram where on lock state on phone it's working fine foreground service and callkit is working there
t
I understand how frustrating it can be when LiveKit calls disconnect after switching to apps like WhatsApp or Instagram. This usually happens because these apps take control of the microphone, which can interrupt your app's audio session. Let’s work through some steps to help you manage this smoothly: For iOS: • Make sure CallKit is properly set up to handle audio sessions. Pay special attention to
provider:didActivate:
and
provider:didDeactivate:
events to keep the audio session stable. • Try disabling automatic audio session configuration so you can manage the audio engine availability yourself. • Don’t forget to enable background modes like
Audio, AirPlay, and Picture in Picture
and
Voice over IP
in your Xcode project to keep things running smoothly. For Android: • It’s important to manage audio focus properly using
MODE_IN_COMMUNICATION
to support voice calls effectively. • Consider implementing a foreground service with the right permissions and service types, such as
microphone
and
mediaPlayback
, to help maintain the connection. • Also, handling audio interruptions and routing carefully can make a big difference in preventing disconnections. Following these suggestions should help keep microphone access stable and reduce disconnections when switching between apps. If you’d like, I’m here to guide you through any part of this process—just let me know! Sources: README.md | Flutter quickstart | LiveKit docs | callkit/README.md | Mobile SDKs (Flutter, iOS, Android) | livekit/livekit_composite | DeepWiki | docs/index.html
d
give me step by step guide for this
t
I'd love to help you with the issue of LiveKit calls disconnecting when switching to apps that use the microphone. Here's a friendly, step-by-step guide to walk you through the process: For iOS: 1. Start by opening your Xcode project and navigating to your app target. 2. Head over to Signing & Capabilities → Add Capability → Background Modes. 3. Make sure to enable these background modes: ◦
Audio, AirPlay, and Picture in Picture
◦
Voice over IP
1. Next, integrate CallKit into your app: ◦ Disable automatic audio session configuration by adding this code:
AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false
◦ Manually control the audio engine availability with:
try AudioManager.shared.setEngineAvailability(.none)
◦ Implement the
provider:didActivate:
and
provider:didDeactivate:
methods in your
CXProviderDelegate
to manage audio sessions smoothly:
Copy code
func provider(_: CXProvider, didActivate session: AVAudioSession) {
  try session.setCategory(.playAndRecord, mode: .voiceChat, options: [.mixWithOthers])
  try AudioManager.shared.setEngineAvailability(.default)
}

func provider(_: CXProvider, didDeactivate _: AVAudioSession) {
  try AudioManager.shared.setEngineAvailability(.none)
}
1. Finally, test your app to make sure the audio session stays active even when switching to other apps. For Android: 1. Open your
AndroidManifest.xml
file and add these permissions:
Copy code
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
2. Declare a foreground service in your
AndroidManifest.xml
with the right service types:
Copy code
<service android:name="your.foreground.service" 
         android:foregroundservicetype="microphone|mediaPlayback"/>
3. Set up audio focus management in your app: ◦ Use
MODE_IN_COMMUNICATION
for voice call audio mode. ◦ Handle audio interruptions and routing carefully to keep the connection stable. 1. Don’t forget to test your app to ensure the connection stays solid when switching between apps. Take your time with these steps, and please feel free to reach out if you want me to clarify anything or if you need a hand with any part of the setup. I’m here to support you!
d
how to setup audio focus management in the app
t
I'm here to help you set up audio focus management in your Android app with a simple step-by-step guide: 1. Choose Your Audio Handler: • AudioSwitchHandler (Recommended): This one offers advanced audio management, including device switching and handling audio focus smoothly. • AudioFocusHandler: A great choice if you want basic audio focus management without device switching. 2. Basic Configuration with Default Settings:
Copy code
// This is the default setup - no extra configuration needed
val room = LiveKit.create(applicationContext)
// AudioSwitchHandler is used automatically with default settings
3. Custom Audio Focus Configuration:
Copy code
val audioOptions = AudioOptions(
    audioHandler = AudioFocusHandler(context),
    audioOutputType = AudioType.CallAudioType() // Perfect for voice communication
)

val overrides = LiveKitOverrides(
    audioOptions = audioOptions
)

val room = LiveKit.create(applicationContext, overrides)
4. Advanced AudioSwitchHandler Configuration:
Copy code
val audioSwitchHandler = AudioSwitchHandler(context).apply {
    manageAudioFocus = true
    focusMode = AudioManager.AUDIOFOCUS_GAIN
    audioMode = AudioManager.MODE_IN_COMMUNICATION
    audioStreamType = AudioManager.STREAM_VOICE_CALL
    audioAttributeUsageType = AudioAttributes.USAGE_VOICE_COMMUNICATION
    audioAttributeContentType = AudioAttributes.CONTENT_TYPE_SPEECH

    onAudioFocusChangeListener = AudioManager.OnAudioFocusChangeListener { focusChange ->
        when (focusChange) {
            AudioManager.AUDIOFOCUS_GAIN -> {
                // Resume audio processing
            }
            AudioManager.AUDIOFOCUS_LOSS -> {
                // Pause audio processing
            }
            AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
                // Temporarily pause audio
            }
        }
    }
}

val audioOptions = AudioOptions(
    audioHandler = audioSwitchHandler,
    audioOutputType = AudioType.CallAudioType()
)

val overrides = LiveKitOverrides(audioOptions = audioOptions)
val room = LiveKit.create(applicationContext, overrides)
5. Handle Audio Focus Changes:
Copy code
audioSwitchHandler.onAudioFocusChangeListener = AudioManager.OnAudioFocusChangeListener { focusChange ->
    when (focusChange) {
        AudioManager.AUDIOFOCUS_GAIN -> {
            room.localParticipant.setMicrophoneEnabled(true)
        }
        AudioManager.AUDIOFOCUS_LOSS -> {
            room.localParticipant.setMicrophoneEnabled(false)
        }
        AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
            room.localParticipant.setMicrophoneEnabled(false)
        }
    }
}
Feel free to follow these steps, and if anything feels unclear or if you’d like me to walk you through any part in more detail, just let me know. I’m here to make sure everything works smoothly for you! Sources: README.md | README.md
d
in android it is fixed using await AudioSession.configureAudio({ android: { preferredOutputList: ["bluetooth", "headset", "speaker", "earpiece"], audioTypeOptions: AndroidAudioTypePresets.communication } }); does for ios is there any configuartion folr this
t
iOS doesn’t support a prioritized preferred audio output list like Android, but don’t worry—I’m here to help you navigate the options available for managing audio output on iOS: 1. Default Output Configuration: • You can use
defaultOutput
in
AudioConfiguration
to set the fallback output to either
speaker
or
earpiece
. By default, it’s set to
speaker
. • If you’d like the speaker to be preferred over the earpiece during automatic configuration, just set
isSpeakerOutputPreferred
to
true
. 2. Manual Audio Output Selection: • Try using the
getAudioOutputs()
method to see the available options (
default
and
force_speaker
). • Then, you can call
setAudioOutput()
to switch between these options whenever you need. 3. Show Audio Route Picker: • The
showAudioRoutePicker()
method lets you display iOS’s native route picker, so users can easily choose audio output devices like Bluetooth headsets, AirPlay speakers, or wired headphones. 4. Advanced Configuration: • If you want to dive a bit deeper, you can use
setAppleAudioConfiguration()
to customize the
AVAudioSession
settings, such as enabling
.allowBluetooth
,
.defaultToSpeaker
, or
.mixWithOthers
. If you’d like, I’m here to guide you through implementing any of these options—just let me know how I can assist! Sources: docs/classes/AudioSession.html | Sources/LiveKit/Audio/Manager/AudioManager.swift | lib/src/hardware/hardware.dart
d
in android it is fixed using AndroidAudioTypePresets.communication whereas for ios i'm using this setting import RNCallKeep, { AudioSessionCategoryOption, AudioSessionMode, CONSTANTS as CK_CONSTANTS, } from 'react-native-callkeep'; import { RTCAudioSession } from '@livekit/react-native-webrtc'; // import { v4 as uuidv4 } from 'uuid'; let uuid = '1932b99c-4fe1-4bf4-897f-763bc4dc21c2'; console.log("uuid is:=====> ", uuid); // This keeps the app alive in the background. export async function *startCallService*({Id, Name}) { let handle = '1234567'; let contactIdentifier = 'Caller Contact'; RNCallKeep.startCall(uuid, handle, contactIdentifier, 'number', false); RNCallKeep.reportConnectingOutgoingCallWithUUID(uuid); // Small delay to ensure proper state transition setTimeout(() => { RNCallKeep.reportConnectedOutgoingCallWithUUID(uuid); }, 100); } export async function *stopCallService*() { RNCallKeep.endCall(uuid); RNCallKeep.reportEndCallWithUUID( uuid, CK_CONSTANTS.END_CALL_REASONS.REMOTE_ENDED ); } export function *setupCallService*() { // iOS CallKit setup const options = { ios: { appName: 'LiveKitReactNative', includesCallsInRecents: false, audioSession: { categoryOptions: AudioSessionCategoryOption.allowAirPlay + AudioSessionCategoryOption.allowBluetooth + AudioSessionCategoryOption.allowBluetoothA2DP + AudioSessionCategoryOption.defaultToSpeaker, 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', () => {}); // To quell warnings. // For apps handling incoming calls from the background. RNCallKeep.addEventListener('didActivateAudioSession', () => { RTCAudioSession.audioSessionDidActivate(); }); RNCallKeep.addEventListener('didDeactivateAudioSession', () => { RTCAudioSession.audioSessionDidDeactivate(); }); }
t
To help you set up iOS CallKit with LiveKit and RNCallKeep for managing your audio sessions, here’s a step-by-step guide you can follow: 1. Initialize RNCallKeep:
Copy code
const options = {
  ios: {
    appName: 'LiveKitReactNative',
    includeCallsInRecents: false,
    audioSession: {
      categoryOptions:
        AudioSessionCategoryOption.allowAirPlay +
        AudioSessionCategoryOption.allowBluetooth +
        AudioSessionCategoryOption.allowBluetoothA2DP +
        AudioSessionCategoryOption.defaultToSpeaker,
      mode: AudioSessionMode.voiceChat,
    },
  },
};
RNCallKeep.setSettings(options);
2. Handle CallKit Audio Session Events:
Copy code
RNCallKeep.addEventListener('didActivateAudioSession', () => {
  RTCAudioSession.audioSessionDidActivate();
});
RNCallKeep.addEventListener('didDeactivateAudioSession', () => {
  RTCAudioSession.audioSessionDidDeactivate();
});
3. Configure LiveKit Audio:
Copy code
await AudioSession.configureAudio({
  ios: {
    defaultOutput: 'speaker',
    audioCategory: 'playAndRecord',
    audioCategoryOptions: [
      'allowAirPlay',
      'allowBluetooth',
      'allowBluetoothA2DP',
      'defaultToSpeaker'
    ],
    audioMode: 'voiceChat',
  }
});
4. Manage Call State:
Copy code
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);
  RNCallKeep.reportEndCallWithUUID(uuid, CK_CONSTANTS.END_CALL_REASONS.REMOTE_ENDED);
}
5. Troubleshooting: • Make sure background modes (
audio
and
voip
) are enabled in your iOS project settings. • It’s important to handle CallKit events before connecting to the LiveKit room to avoid any issues. • If you want to give users control over audio output, consider using
showAudioRoutePicker()
. If you run into any challenges or want me to walk you through a particular step, please don’t hesitate to ask. I’m here to help you get this working smoothly! Sources: src/index.tsx | README.md | README.md
d
for ios i want to setup it for voice communication not videochat and voice communication is working fine when on home screen when the screen is locked when goes on other apps like whatsapp snapchat livekit is diconnecting i want to actively do voice communication on the other apps also i already enabled the uibackgroundmodes voip audio in app.json and plist file
t
Hi there! To help you keep your voice communication running smoothly on iOS, even when switching to apps like WhatsApp or Snapchat, here’s a friendly step-by-step guide you can follow: 1. Enable Background Modes: • Open Xcode, go to your app target → Signing & Capabilities → Add Capability → Background Modes. • Make sure to select
Audio, AirPlay, and Picture in Picture
and
Voice over IP
. • Also, double-check that your
Info.plist
includes this:
Copy code
<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
  <string>voip</string>
</array>
2. Integrate CallKit: • Using
react-native-callkeep
is a great way to manage CallKit events. • Don’t forget to handle audio session activation and deactivation like this:
Copy code
RNCallKeep.addEventListener('didActivateAudioSession', () => {
  RTCAudioSession.audioSessionDidActivate();
});
RNCallKeep.addEventListener('didDeactivateAudioSession', () => {
  RTCAudioSession.audioSessionDidDeactivate();
});
3. Synchronize Audio Session with CallKit: • It’s helpful to disable automatic audio session configuration in LiveKit by setting: • Then, set the audio session category and mode when activating:
Copy code
func provider(_: CXProvider, didActivate session: AVAudioSession) {
  try session.setCategory(.playAndRecord, mode: .voiceChat, options: [.mixWithOthers])
  try AudioManager.shared.setEngineAvailability(.default)
}
• And when deactivating, make sure to revoke engine availability:
Copy code
func provider(_: CXProvider, didDeactivate _: AVAudioSession) {
  try AudioManager.shared.setEngineAvailability(.none)
}
4. Test and Troubleshoot: • Check that no other plugins or background services are conflicting with your audio functionality. • Try testing your app in real-world situations, like switching to other apps or locking the screen, to see how it behaves. Following these steps should really help keep your voice communication uninterrupted. If you hit any bumps or want to dive deeper into any part of the setup, just let me know—I’m here to help! Sources: Camera & microphone | LiveKit Docs | example/src/callservice/CallService.ios.ts | callkit/README.md | README.md
d
do i need to force entitlements for voip for livekit and is voip certificate is required?
t
Hi there! I wanted to share some helpful info about VoIP entitlements and certificates for LiveKit. Usually, they aren’t required for basic functionality, but if you’re looking to use some advanced features like background audio or CallKit integration, there are a few important settings to keep in mind: 1. Background Modes: • Make sure to enable
Audio
and
VoIP
in the
UIBackgroundModes
section of your
Info.plist
. This allows your app to keep running during calls in the background:
Copy code
<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
  <string>voip</string>
</array>
2. CallKit Integration: • If you’re using CallKit to handle incoming calls, you’ll need the
com.apple.developer.pushkit.unrestricted-voip
entitlement. This lets PushKit notifications trigger the CallKit interface smoothly. 3. Background Camera Access (iOS 18+): • For multitasking with the camera, don’t forget to enable the
voip
background mode and set
enableMultitaskingCameraAccess
in your app’s configuration. These steps help make sure your voice calls stay uninterrupted and that you can take full advantage of the advanced features. If you have any questions or want help with a specific part of your setup, just let me know—I’m here to help! Sources: Swift quickstart | LiveKit docs | README.md | minimal-pip/minimal-pip/Info.plist | VoiceAgent/Info.plist | Documentation/iOSInstallation.md
d
does this doesn't disconnect my apps over other apps or should i need to set this in ios configuration didDeactivateAudioSession function RNCallKeep.addEventListener('didDeactivateAudioSession', () => { console.log("session is deactivated"); RTCAudioSession.audioSessionDidDeactivate(); });
t
I completely understand how important it is to keep your LiveKit connection stable when switching apps. The
didDeactivateAudioSession
event from
RNCallKeep
won’t disconnect your LiveKit connection as long as it’s handled properly. It’s really helpful to call
RTCAudioSession.audioSessionDidDeactivate()
within this event to make sure your WebRTC connection stays smooth and the audio session state is managed correctly. This step lets the WebRTC backend know that the audio session has been deactivated, so LiveKit can take care of audio routing and background execution just right. You can safely add this to your configuration:
Copy code
RNCallKeep.addEventListener('didDeactivateAudioSession', () => {
  console.log("session is deactivated");
  RTCAudioSession.audioSessionDidDeactivate();
});
If you have any questions or want me to walk you through this setup, please don’t hesitate to ask. I’m here to help! Sources: docs/index.html | Documentation/iOSInstallation.md
d
before disconnections it showed me these logs audio route is changed session is deactivated // Start a CallKit call on iOS. import RNCallKeep, { AudioSessionCategoryOption, AudioSessionMode, CONSTANTS as CK_CONSTANTS, } from 'react-native-callkeep'; import { RTCAudioSession } from '@livekit/react-native-webrtc'; // import { v4 as uuidv4 } from 'uuid'; let uuid = '1932b99c-4fe1-4bf4-897f-763bc4dc21c2'; console.log("uuid is:=====> ", uuid); // This keeps the app alive in the background. export async function *startCallService*({Id, Name}) { let handle = '1234567'; let contactIdentifier = 'Caller Contact'; RNCallKeep.startCall(uuid, handle, contactIdentifier, 'number', false); RNCallKeep.reportConnectingOutgoingCallWithUUID(uuid); // Small delay to ensure proper state transition setTimeout(() => { RNCallKeep.reportConnectedOutgoingCallWithUUID(uuid); }, 100); } export async function *stopCallService*() { RNCallKeep.endCall(uuid); RNCallKeep.reportEndCallWithUUID( uuid, CK_CONSTANTS.END_CALL_REASONS.REMOTE_ENDED ); } export function *setupCallService*() { // iOS CallKit setup 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(); }); }
t
I understand how frustrating the disconnection issue can be after seeing the "audio route is changed" and "session is deactivated" logs. This happens because both CallKit and LiveKit are managing the audio session lifecycle, which can sometimes lead to conflicts. But don’t worry, I’m here to help you get this sorted out by properly synchronizing CallKit's audio session events with LiveKit's WebRTC session. Here’s a friendly guide to fix this: 1. Make sure you’re handling the
didActivateAudioSession
and
didDeactivateAudioSession
events correctly. This helps keep everything in sync:
Copy code
RNCallKeep.addEventListener('didActivateAudioSession', () => {
  console.log("session is activated");
  RTCAudioSession.audioSessionDidActivate();
});

RNCallKeep.addEventListener('didDeactivateAudioSession', () => {
  console.log("session is deactivated");
  RTCAudioSession.audioSessionDidDeactivate();
});
2. Check that your CallKit configuration includes the right audio session settings to support smooth audio handling:
Copy code
const options = {
  ios: {
    appName: 'LiveKitReactNative',
    includeCallsInRecents: false,
    audioSession: {
      categoryOptions:
        AudioSessionCategoryOption.allowAirPlay |
        AudioSessionCategoryOption.allowBluetooth |
        AudioSessionCategoryOption.allowBluetoothA2DP |
        AudioSessionCategoryOption.defaultToSpeaker |
        AudioSessionCategoryOption.mixWithOthers,
      mode: AudioSessionMode.voiceChat,
    },
  },
};
RNCallKeep.setSettings(options);
3. It’s also helpful to listen for the
didChangeAudioRoute
event to catch any audio route changes and respond accordingly:
Copy code
RNCallKeep.addEventListener('didChangeAudioRoute', () => {
  console.log("audio route is changed");
});
4. Lastly, double-check that the background modes for
audio
and
voip
are enabled in your Xcode project. This ensures your app can handle calls smoothly even when running in the background. By following these steps, you’ll help keep LiveKit’s WebRTC session stable through audio route changes and background transitions. If you run into any bumps or want me to walk you through any part, just let me know—I’m here to support you! Sources: README.md | src/RTCAudioSession.ts | callkit/README.md | README.md | How We Built a Globally Distributed WebRTC Mesh Network
d
what configuration need to set when audio route is changed also give me correct voice call setting to handle this
t
Let's walk through how to handle audio route changes and set up the right voice call settings for LiveKit with CallKit on iOS. I’m here to guide you every step of the way: 1. Disable Automatic Audio Session Configuration:
Copy code
AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false
try AudioManager.shared.setEngineAvailability(.none)
2. Handle CallKit Audio Session Events:
Copy code
func provider(_: CXProvider, didActivate session: AVAudioSession) {
    do {
        try session.setCategory(.playAndRecord, mode: .voiceChat, options: [
            .allowAirPlay,
            .allowBluetooth,
            .allowBluetoothA2DP,
            .defaultToSpeaker,
            .mixWithOthers
        ])
        try AudioManager.shared.setEngineAvailability(.default)
    } catch {
        // Handle error
    }
}

func provider(_: CXProvider, didDeactivate _: AVAudioSession) {
    do {
        try AudioManager.shared.setEngineAvailability(.none)
    } catch {
        // Handle error
    }
}
3. React Native Audio Route Change Handling:
Copy code
RNCallKeep.addEventListener('didChangeAudioRoute', () => {
    console.log("Audio route changed");
});
4. Configure Audio Session Options: • `allowAirPlay`: Enables AirPlay audio routing • `allowBluetooth`: Supports Bluetooth hands-free devices • `allowBluetoothA2DP`: Supports high-quality Bluetooth audio • `defaultToSpeaker`: Routes audio to speaker by default • `mixWithOthers`: Allows mixing with other audio sources 5. Test and Troubleshoot: • Make sure background modes (
audio
and
voip
) are enabled in Xcode. • Try testing with different audio routes like speaker, Bluetooth, and wired headphones. • Double-check that CallKit events are handled on the main thread to prevent any silent issues. Following these steps will help ensure your audio routes change smoothly and your voice calls stay uninterrupted. If you run into any bumps or have questions, please don’t hesitate to reach out—I’m happy to help! Sources: README.md | Docs/audio.md | README.md
d
how to disable this in AudioManager.shared.audioSession.isAutomaticConfigurationEnabled = false try AudioManager.shared.setEngineAvailability(.none) in this file // Start a CallKit call on iOS. import RNCallKeep, { AudioSessionCategoryOption, AudioSessionMode, CONSTANTS as CK_CONSTANTS, } from 'react-native-callkeep'; import { RTCAudioSession } from '@livekit/react-native-webrtc'; // import { v4 as uuidv4 } from 'uuid'; let uuid = '1932b99c-4fe1-4bf4-897f-763bc4dc21c2'; console.log("uuid is:=====> ", uuid); // This keeps the app alive in the background. export async function *startCallService*({Id, Name}) { let handle = '1234567'; let contactIdentifier = 'Caller Contact'; RNCallKeep.startCall(uuid, handle, contactIdentifier, 'number', false); RNCallKeep.reportConnectingOutgoingCallWithUUID(uuid); // Small delay to ensure proper state transition setTimeout(() => { RNCallKeep.reportConnectedOutgoingCallWithUUID(uuid); }, 100); } export async function *stopCallService*() { RNCallKeep.endCall(uuid); RNCallKeep.reportEndCallWithUUID( uuid, CK_CONSTANTS.END_CALL_REASONS.REMOTE_ENDED ); } export function *setupCallService*() { // iOS CallKit setup 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(); }); }
t
Thank you for reaching out! I understand you're looking into the property
AudioManager.shared.audioSession.isAutomaticConfigurationEnabled
, which is specific to the LiveKit Swift SDK and isn’t directly available in the React Native SDK. But don’t worry, there are some great ways to achieve similar control in React Native: 1. Custom Audio Configuration:
Copy code
import { AudioSession } from '@livekit/react-native';

await AudioSession.configureAudio({
  ios: {
    defaultOutput: 'earpiece', // or 'speaker'
  },
});
2. Dynamic Audio Management: You can use the
useIOSAudioManagement
hook to automatically adjust audio settings based on track publishing states, which makes things smoother for you. 3. Platform-Specific Audio Control: On iOS,
AudioSession.selectAudioOutput()
lets you switch between
default
and
force_speaker
options easily. If you’re working with CallKit and need more manual control over the audio session, you might want to explore the native Swift SDK or even build a custom native module. Please feel free to reach out if you’d like me to walk you through any of these options—I’m here to help! Sources: Sources/LiveKit/Audio/Manager/AudioManager.swift | callkit/README.md | docs/index.html
d
what options need to set for audiocalling for RNCallKeep.setSettings
t
To help you set up
RNCallKeep.setSettings
for audio calling in React Native LiveKit, here’s a friendly guide with the options you’ll want to use: iOS Configuration:
Copy code
const options = {
  ios: {
    appName: 'LiveKitReactNative',
    includeCallsInRecents: false,
    audioSession: {
      categoryOptions:
        AudioSessionCategoryOption.allowAirPlay +
        AudioSessionCategoryOption.allowBluetooth +
        AudioSessionCategoryOption.allowBluetoothA2DP +
        AudioSessionCategoryOption.defaultToSpeaker,
      mode: AudioSessionMode.voiceChat,
    },
  },
  // Android settings are required for type safety but not used here
};
RNCallKeep.setSettings(options);
Here’s a quick explanation of the key options: • `allowAirPlay`: Lets your audio route through AirPlay. • `allowBluetooth`: Supports Bluetooth hands-free devices, so calls work smoothly. • `allowBluetoothA2DP`: Enables high-quality Bluetooth audio for a better experience. • `defaultToSpeaker`: Makes sure audio goes to the speaker by default. • `mode: AudioSessionMode.voiceChat`: Tailors the audio session specifically for real-time voice communication. These settings are designed to ensure your voice calls sound great and behave just right. If you have any questions or need a hand with this setup, please don’t hesitate to ask—I’m here to help! Sources: example/ios/Podfile.lock
b
Is there an option for Flutter Android ?
t
For Flutter on Android,
RNCallKeep.setSettings
does not directly configure audio calling behavior. Instead, audio settings are managed through LiveKit's
AndroidAudioTypeOptions
in the
configureAudio
method. RNCallKeep Android Configuration: • `alertTitle`: Title for the permissions alert • `alertDescription`: Description for the permissions alert • `cancelButton`: Text for the cancel button • `okButton`: Text for the OK button • `foregroundService`: Configuration for the foreground service, including
channelId
,
channelName
, and
notificationTitle
. LiveKit Audio Configuration:
Copy code
await AudioSession.configureAudio({
  android: {
    audioAttributesContentType: 'speech',
    audioAttributesUsageType: 'voiceCommunication',
    audioFocusMode: 'gain',
    audioMode: 'inCommunication',
    audioStreamType: 'voiceCall',
    forceHandleAudioRouting: false,
    manageAudioFocus: true,
  },
});
These settings ensure proper audio behavior during calls. Let me know if you need further assistance with the configuration.