Hello, I’m implementing voice calling using LiveKi...
# ask-ai
d
Hello, I’m implementing voice calling using LiveKit WebRTC inside a React Native (Expo) app. The call connects and audio works perfectly while the app is in the foreground, but when the app goes to background or screen locks, the microphone stops capturing audio and on iOS the entire app suspends, breaking the ongoing call. I’ve already followed the recommended steps for native audio session setup and background support for both Android and iOS, but the issue still persists.
Copy code
Configuration Details:
Expo app.json:
{
  "plugins": [
    "@config-plugins/react-native-webrtc",
    [
      "@livekit/react-native-expo-plugin",
      {
        "android": {
          "audioType": "communication"
        }
      ]
    ]
  ],
  "android": {
    "permissions": [
      "FOREGROUND_SERVICE",
      "FOREGROUND_SERVICE_MICROPHONE",
      "FOREGROUND_SERVICE_MEDIA_PROJECTION",
      "FOREGROUND_SERVICE_MEDIA_PLAYBACK",
      "FOREGROUND_SERVICE_CONNECTED_DEVICE",
      "POST_NOTIFICATIONS"
    ],
    "foregroundService": {
      "type": "microphone|mediaPlayback",
      "notificationTitle": "Call Active",
      "notificationBody": "Your call is running in the background."
    }
  },
  "ios": {
    "infoPlist": {
      "UIBackgroundModes": [
        "audio",
        "voip",
        "fetch",
        "remote-notification",
        "processing"
      ]
    }
  }
}
Android Setup: On Android, I’m using
@supersami/rn-foreground-service
to keep the process alive and maintain audio focus in background.
Copy code
import ReactNativeForegroundService from "@supersami/rn-foreground-service";

ReactNativeForegroundService.register({
  config: {
    alert: false,
    onServiceErrorCallBack: () => {},
  },
});
The foreground service runs fine. However, audio capture (microphone) stops once the app goes background or screen locks. iOS Setup Enabled Background Modes in Xcode: • Audio • VoIP • Background fetch • Remote notifications And configured:
Copy code
await AudioSession.configureAudio({
  ios: { defaultOutput: "speaker" },
});
await AudioSession.startAudioSession();
However, as soon as I switch to another app or lock the screen: • iOS suspends the app • LiveKit connection drops silently • Audio session stops transmitting Even after unlocking the screen, the session doesn’t automatically resume unless the user reopens the app. Call Implementation :
Copy code
import {
  AudioSession,
  LiveKitRoom,
} from "@livekit/react-native";
import React, { useEffect, useState } from "react";
import { SafeAreaView, TouchableOpacity, View, Platform } from "react-native";
import { Ionicons } from "@expo/vector-icons";
import RNForegroundService from "@supersami/rn-foreground-service";

export default function CallScreen({ route }) {
  const [isMuted, setIsMuted] = useState(false);

  useEffect(() => {
    const init = async () => {
      await startNativeAudioSession();
      if (Platform.OS === "android") await startForegroundService();
    };
    init();

    return () => {
      AudioSession.stopAudioSession();
      RNForegroundService.stopAll();
    };
  }, []);

  const startNativeAudioSession = async () => {
    await AudioSession.configureAudio({
      android: {
        preferredOutputList: ["bluetooth", "headset", "speaker", "earpiece"],
        audioTypeOptions: {
          manageAudioFocus: true,
          audioMode: "inCommunication",
          audioAttributesUsageType: "voiceCommunication",
          audioAttributesContentType: "speech",
        },
      },
      ios: { defaultOutput: "speaker" },
    });
    await AudioSession.startAudioSession();
  };

  return (
    <SafeAreaView>
      <LiveKitRoom
        serverUrl={serverUrl}
        token={route.params.token}
        connect={true}
        audio={true}
        video={false}
      >
        <View>
          <TouchableOpacity
            onPress={() => {
              setIsMuted(!isMuted);
            }}
          >
            <Ionicons name={isMuted ? "mic-off" : "mic"} size={32} />
          </TouchableOpacity>
        </View>
      </LiveKitRoom>
    </SafeAreaView>
  );
}
In Android, I want to keep the microphone active and continue transmitting audio during background or screen lock. For iOS, how to properly configure iOS so that audio capture continues when the app is backgrounded or the screen is locked. Any guidance or examples for both Android and iOS background audio handling would be really helpful
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 maintain background audio and microphone capture in your LiveKit React Native app, let’s walk through some platform-specific steps together: Android: • First, make sure you have all the necessary permissions set in your
AndroidManifest.xml
, including
FOREGROUND_SERVICE
and permissions for microphone and media playback. • Using a foreground service is key to keeping your app active in the background. I recommend
@supersami/rn-foreground-service
to manage this smoothly. Don’t forget to configure the service with a notification so users know there’s an ongoing call. • If you’d like a detailed example, check out the CallService.android.ts example—it’s a great resource. iOS: • In Xcode, be sure to enable Background Modes, especially "Audio" and "VoIP" under
UIBackgroundModes
. • If you’re working with iOS 18 or later, configuring multitasking camera access in your AppDelegate is important. • Integrating CallKit can really strengthen background handling. The CallService.ios.ts example offers a helpful guide. • Also, consider using the
useIOSAudioManagement
hook to adapt audio settings dynamically during calls. For both Android and iOS, don’t forget to request runtime permissions for the microphone and camera—libraries like
react-native-permissions
make this easier. I hope these steps make things clearer and help you get your background audio and mic working perfectly. If you run into any bumps or have more questions, I’m here to help—just let me know! Sources: ios/LivekitReactNativeModule.m | Camera & microphone | LiveKit Docs
d
but this configuration is for react-native i want it to integrate into react-native expo project which is different what configuations needed to set into app.json file and in android still microphone is not taking input when screen is locking and switching between apps
t
I'm here to help you integrate LiveKit into your React Native Expo project, especially when it comes to handling background audio and microphone capture. Let's walk through the steps together: 1. Update app.json:
Copy code
{
  "expo": {
    "plugins": [
      "@livekit/react-native-expo-plugin",
      "@config-plugins/react-native-webrtc"
    ],
    "android": {
      "permissions": [
        "CAMERA",
        "RECORD_AUDIO",
        "INTERNET",
        "MODIFY_AUDIO_SETTINGS",
        "FOREGROUND_SERVICE"
      ],
      "foregroundService": {
        "type": "microphone|mediaPlayback",
        "notificationTitle": "Call Active",
        "notificationBody": "Your call is running in the background."
      }
    },
    "ios": {
      "infoPlist": {
        "NSCameraUsageDescription": "Allow access to camera for video calls",
        "NSMicrophoneUsageDescription": "Allow access to microphone for voice calls",
        "UIBackgroundModes": [
          "audio",
          "voip"
        ]
      }
    }
  }
}
2. Android Foreground Service: • Consider using
@supersami/rn-foreground-service
to keep your app running smoothly in the background. It’s great to configure it with a notification so users know their call is active. • Don’t forget to add the
FOREGROUND_SERVICE
permission in your `app.json`—this is key! 3. iOS Background Modes: • Make sure "Audio" and "VoIP" are enabled in
UIBackgroundModes
within your
app.json
. • Using the
useIOSAudioManagement
hook can really help with managing audio sessions dynamically during calls. 4. Build the App: • When you’re ready, run
npx expo run:android
or
npx expo run:ios
to build your app with all the necessary native modules included. These steps should help fix the microphone issue when your app is in the background or the screen is locked. If anything feels unclear or you run into any other questions, please don’t hesitate to reach out—I’m here to support you! Sources: Documentation/iOSInstallation.md | android/src/main/java/com/livekit/reactnative/LivekitReactNativeModule.kt | Camera & microphone | LiveKit Docs | README.md | README.md
d
how to configure this app for @supersami/rn-foreground-service in which files and what changes do i need to do in react-native expo project also how during the call microphone would be active when switching between apps and locking the phone
t
Hi there! To help you set up
@supersami/rn-foreground-service
in your React Native Expo project for keeping the microphone active during calls in the background, I've put together some easy steps for you to follow: 1. Install Required Dependencies:
Copy code
npx expo install livekit-client @livekit/react-native @livekit/react-native-expo-plugin @livekit/react-native-webrtc @config-plugins/react-native-webrtc
npm install @supersami/rn-foreground-service
2. Update app.json:
Copy code
{
  "expo": {
    "plugins": [
      "@livekit/react-native-expo-plugin",
      "@config-plugins/react-native-webrtc"
    ],
    "android": {
      "permissions": [
        "FOREGROUND_SERVICE",
        "FOREGROUND_SERVICE_MICROPHONE",
        "RECORD_AUDIO",
        "MODIFY_AUDIO_SETTINGS"
      ],
      "foregroundService": {
        "type": "microphone|mediaPlayback",
        "notificationTitle": "Call Active",
        "notificationBody": "Your call is running in the background."
      }
    },
    "ios": {
      "infoPlist": {
        "UIBackgroundModes": [
          "audio",
          "voip"
        ]
      }
    }
  }
}
3. Configure Foreground Service:
Copy code
import ReactNativeForegroundService from "@supersami/rn-foreground-service";

export function setupCallService() {
  ReactNativeForegroundService.register({
    config: {
      alert: false,
      onServiceErrorCallBack: () => {
        console.error("Foreground service error occurred");
      },
    },
  });
}

export async function startCallService() {
  await ReactNativeForegroundService.start({
    id: 3456,
    title: "LiveKit Call",
    message: "Call in progress",
    importance: "none",
    vibration: false,
    icon: "ic_launcher",
    ServiceType: "microphone",
  });
}

export async function stopCallService() {
  await ReactNativeForegroundService.stop();
}
4. Initialize in App:
Copy code
import { registerGlobals, AudioSession } from "@livekit/react-native";

useEffect(() => {
  registerGlobals();
  AudioSession.startAudioSession();
  setupCallService();

  return () => {
    AudioSession.stopAudioSession();
  };
}, []);
5. Build and Test: • Run
npx expo run:android
or
eas build --platform android
to create a development build. • Try testing on a physical device since background behavior can be different compared to simulators. Following these steps should help keep your microphone active even when your app is in the background or the screen is locked. If you run into any issues or have questions, please don’t hesitate to reach out—I’m here to help! Sources: Expo quickstart | LiveKit docs | README.md | patches/@supersami+rn-foreground-service+2.1.0.patch | docs/index.html
d
still microphone is stopping when switching between apps and when phone is locking
t
Hey there! If your microphone is still stopping when switching apps or locking the phone, let’s make sure a few important configurations are set up correctly. I’m here to help you through this! 1. Verify Foreground Service Permissions:
Copy code
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
2. Declare Foreground Service:
Copy code
<service android:name="com.supersami.foregroundservice.ForegroundService"
         android:foregroundservicetype="microphone|mediaPlayback"/>
<service android:name="com.supersami.foregroundservice.ForegroundServiceTask"/>
3. Start Foreground Service Before Backgrounding:
Copy code
await ReactNativeForegroundService.start({
  id: 3456,
  title: "Call in progress",
  message: "LiveKit is using the microphone",
  icon: "ic_launcher",
  ServiceType: "microphone",
  importance: "none",
  vibration: false,
});
4. Initialize WebRTC and Audio Session:
Copy code
import { registerGlobals, AudioSession } from "@livekit/react-native";
registerGlobals();

useEffect(() => {
  const setup = async () => {
    await AudioSession.configureAudio({
      android: { audioTypeOptions: "communication" },
    });
    await AudioSession.startAudioSession();
  };
  setup();

  return () => {
    AudioSession.stopAudioSession();
  };
}, []);
5. Troubleshooting: • If you’re on Android devices with strict background restrictions (like Xiaomi or Huawei), try disabling battery optimization for your app. • Make sure the foreground service starts right away without any delays. • It’s also a good idea to test on different Android versions since behavior can vary. I hope these steps help you get everything running smoothly! If you run into any more issues or have questions, please don’t hesitate to reach out—I’m here to support you. Sources: example/src/types/Foreground.d.ts | patches/@supersami+rn-foreground-service+2.1.0.patch
d
foreground service is running but it's notification is not showing in the notification bar whereas when switching between the apps and screen is locked then microphone is not taking input
t
Hi there! If you’re noticing that the foreground service notification isn’t showing up and the microphone stops working when you switch apps or lock the screen, don’t worry—let’s walk through some steps together to get this sorted out: 1. Verify Permissions in AndroidManifest.xml:
Copy code
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
Make sure these permissions are correctly added so your app can access the microphone and run foreground services. 2. Declare Foreground Service:
Copy code
<service android:name="com.supersami.foregroundservice.ForegroundService"
         android:foregroundservicetype="microphone|mediaPlayback"/>
<service android:name="com.supersami.foregroundservice.ForegroundServiceTask"/>
This declaration tells Android about your foreground service and its purpose. 3. Start Foreground Service with Notification:
Copy code
await ReactNativeForegroundService.start({
  id: 3456,
  title: "LiveKit Call",
  message: "Call in progress",
  importance: "high",
  vibration: false,
  icon: "ic_launcher",
});
Just a quick reminder to ensure the
icon
you use is a valid drawable resource in your Android project—something like
ic_launcher
usually works well. 4. Register Foreground Service:
Copy code
import ReactNativeForegroundService from "@supersami/rn-foreground-service";
ReactNativeForegroundService.register();
It’s best to call this early on in your app’s lifecycle, for example in your
index.tsx
file, so everything is set up properly. 5. Use Expo Development Build:
Copy code
npx expo install expo-dev-client
npx expo run:android
Just a heads-up: foreground services need a custom development build to work, so they won’t function with Expo Go. 6. Start Audio Session:
Copy code
import { AudioSession } from "@livekit/react-native";
await AudioSession.startAudioSession();
Starting the audio session helps keep the microphone active even when your app goes to the background. Give these steps a try, and hopefully, they’ll resolve the notification and microphone issues you’re experiencing. If you run into any trouble or have more questions, please don’t hesitate to reach out—I’m here to help! Sources: README.md | index.tsx | Expo quickstart | LiveKit docs
d
where can i see ic_launcher
t
I'm happy to help you locate the
ic_launcher
icon in your React Native project! You'll find it in the
android/app/src/main/res/mipmap
directory. This directory contains several folders tailored for different screen densities, such as: •
mipmap-mdpi
•
mipmap-hdpi
•
mipmap-xhdpi
•
mipmap-xxhdpi
•
mipmap-xxxhdpi
If you're working with adaptive icons, the
ic_launcher.xml
file is located in the
mipmap-anydpi-v26
folder. This file points to: •
@drawable/ic_launcher_foreground
for the foreground image •
@drawable/ic_launcher_background
for the background color or image Here’s how you can customize your icon: 1. Swap out the PNG files in each
mipmap-
folder if you’re using static icons. 2. For adaptive icons, update the
ic_launcher_foreground
and
ic_launcher_background
drawables found in the
res/drawable
folder. 3. Make sure your
AndroidManifest.xml
references
@mipmap/ic_launcher
for both the
android:icon
and
android:roundIcon
attributes. If you’d like, I’m here to guide you through any part of this process or answer any questions you might have about customizing or replacing your icon. Just let me know! Sources: examples/mobile/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_roun... | ci/android/app/src/main/AndroidManifest.xml | src/callservice/CallService.android.ts | sample-app-record-local/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xm... | examples/llama.android/app/src/main/res/mipmap-anydpi/ic_launcher.xml
d
await ReactNativeForegroundService.start({ id: 3456, title: "LiveKit Call", message: "Call in progress", importance: "high", vibration: false, icon: "ic_launcher", }); Error starting foreground service [Error: ForegroundService: ServiceType is required]
t
It looks like you're encountering the error "ForegroundService: ServiceType is required" because the
ServiceType
parameter might be missing or not set up quite right. No worries—let's walk through how to fix this together: 1. Update your AndroidManifest.xml file:
Copy code
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>

<service android:name="com.supersami.foregroundservice.ForegroundService"
         android:foregroundservicetype="microphone|mediaPlayback"/>
<service android:name="com.supersami.foregroundservice.ForegroundServiceTask"
         android:foregroundservicetype="microphone|mediaPlayback"/>
2. Make sure to pass the ServiceType when you start the service:
Copy code
await ReactNativeForegroundService.start({
  id: 3456,
  title: "LiveKit Call",
  message: "Call in progress",
  importance: "high",
  vibration: false,
  icon: "ic_launcher",
  ServiceType: "microphone",
});
Just a quick tip: the
ServiceType
here needs to match one of the types you declared in the
android:foregroundServiceType
attribute in your manifest, like
microphone
or
mediaPlayback
. If you have any questions or want me to help you with the next steps, please don’t hesitate to reach out. I’m here to help! Sources: example/src/types/Foreground.d.ts
d
foreground service started with notification but in the notification bar no notification is showing
\
t
Hi there! If you’re not seeing the foreground service notification in your notification bar, let’s go through a few important checks together to get this sorted out: 1. Add Required Permissions:
Copy code
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
Starting with Android 13, it’s important to request the
POST_NOTIFICATIONS
permission at runtime to make sure notifications can show up. 2. Verify Foreground Service Declaration:
Copy code
<service android:name="com.supersami.foregroundservice.ForegroundService"
         android:foregroundservicetype="microphone|mediaPlayback"/>
3. Configure Notification Channel:
Copy code
<meta-data android:name="com.supersami.foregroundservice.notification_channel_name"
          android:value="Call"/>
<meta-data android:name="com.supersami.foregroundservice.notification_channel_description"
          android:value="Description"/>
4. Set Notification Importance:
Copy code
await ReactNativeForegroundService.start({
  id: 3456,
  title: "LiveKit Call",
  message: "Call in progress",
  importance: "high",
  vibration: false,
  icon: "ic_launcher",
  ServiceType: "microphone",
});
Make sure the
importance
is set to
"high"
so the notification is clearly visible. 5. Check Icon Resource: Please double-check that the
ic_launcher
icon is available in your
res/mipmap
folders. Following these steps usually does the trick! If you still don’t see the notification after trying this, just let me know—I’m here to help you through it. Sources: example/src/types/Foreground.d.ts | livekit-android-sdk/src/main/java/io/livekit/android/room/track/LocalScreen... | Screen sharing | LiveKit docs | src/callservice/CallService.android.ts
d
do for enabling background processing do i need to setup any configuartion in mainapplication.kt mainactivity.java or inside java folder do i need to create some file or need to create a plugin if yes then give me step by step complete code for this for react-native expo project
t
Hi there! For your React Native Expo project, the great news is you don’t need to manually tweak
MainApplication.kt
or
MainActivity.java
to enable background processing. Expo takes care of the native configurations for you through config plugins and the build process, making things a lot smoother! Here’s a friendly step-by-step guide for Expo: 1. Install Required Dependencies:
Copy code
npm install @livekit/react-native @livekit/react-native-webrtc livekit-client @supersami/rn-foreground-service
2. Update app.json:
Copy code
{
  "expo": {
    "android": {
      "permissions": [
        "FOREGROUND_SERVICE",
        "FOREGROUND_SERVICE_MICROPHONE",
        "POST_NOTIFICATIONS"
      ],
      "manifest": {
        "application": {
          "service": [
            {
              "@android:name": "com.supersami.foregroundservice.ForegroundService",
              "@android:foregroundServiceType": "microphone|mediaPlayback"
            }
          ]
        }
      }
    }
  }
}
3. Use the LiveKit Expo Plugin:
Copy code
{
  "plugins": [
    "@livekit/expo-plugin"
  ]
}
4. Start Foreground Service in JavaScript:
Copy code
import ReactNativeForegroundService from "@supersami/rn-foreground-service";

export async function startCallService() {
  await ReactNativeForegroundService.start({
    id: 3456,
    title: "LiveKit Call",
    message: "Call in progress",
    importance: "high",
    icon: "ic_launcher",
  });
}
5. Register WebRTC Globals:
Copy code
import { registerGlobals } from "@livekit/react-native";
registerGlobals();
Following these steps should have your background processing running smoothly without the need to touch native files. If anything feels unclear or you hit any bumps along the way, please don’t hesitate to reach out—I’m here to help! Sources: docs/index.html | Expo quickstart | LiveKit docs | src/types/Foreground.d.ts
d
what configurations do i need to do for ios
t
Hi there! To help you enable background processing on iOS in your React Native Expo project using LiveKit, here’s a friendly step-by-step guide you can follow: 1. Enable Background Modes: • Start by opening your project in Xcode. • Navigate to your app target → Signing & Capabilities → Add Capability → Background Modes. • Make sure to check these options: ◦ Audio, AirPlay, and Picture in Picture ◦ Voice over IP (VoIP) 2. Use Expo Development Build: • Add the LiveKit Expo plugin to your
app.json
like this:
Copy code
{
  "plugins": [
    "livekit-react-native-expo-plugin"
  ]
}
• Then, build your app using
expo build:ios
or
npx expo run:ios
. 3. Integrate CallKit (Optional for Robust Background Support): • If you want smoother background call handling, install
react-native-callkeep
and set it up to register calls with iOS. • Use
RNCallKeep.startCall()
and
RNCallKeep.endCall()
to manage your calls effectively. 4. Optional: Enable Multi-tasking Camera Access (iOS 18+): • If your app needs camera access while in the background, you can enable it in your
AppDelegate
like this:
Copy code
#import "WebRTCModuleOptions.h"
WebRTCModuleOptions *options = [WebRTCModuleOptions sharedInstance];
options.enableMultitaskingCameraAccess = YES;
Following these steps will help your app keep audio processing and connectivity going smoothly in the background. If you have any questions or want me to walk you through any part, just let me know—I’m here to help! Sources: docs/index.html | Expo quickstart | LiveKit docs
d
how to integrate callkit for robust background support for calls give me step by step process
t
Hi there! To help you smoothly integrate CallKit for strong background support in your React Native Expo project, here’s a friendly step-by-step guide you can follow: 1. Install CallKit Dependency:
Copy code
npm install react-native-callkeep
2. Configure CallKit Service:
Copy code
import RNCallKeep, { AudioSessionCategoryOption, AudioSessionMode } from "react-native-callkeep";

export function setupCallService() {
  const options = {
    ios: {
      appName: "LiveKitReactNative",
      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",
      foregroundService: {
        channelId: "io.livekit.reactnative",
        channelName: "Foreground Service",
        notificationTitle: "LiveKit Call in progress",
      },
    },
  };
  RNCallKeep.setSettings(options);
}
3. Handle Audio Session Events:
Copy code
import { RTCAudioSession } from "@livekit/react-native-webrtc";

RNCallKeep.addEventListener("didActivateAudioSession", () => {
  RTCAudioSession.audioSessionDidActivate();
});
RNCallKeep.addEventListener("didDeactivateAudioSession", () => {
  RTCAudioSession.audioSessionDidDeactivate();
});
4. Start and Stop Call Service:
Copy code
export async function startCallService() {
  const uuid = "1932b99c-4fe1-4bf4-897f-763bc4dc21c2";
  const handle = "1234567";
  const 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);
}
5. Configure VoIP Background Mode: • Simply add the following to your `Info.plist`:
Copy code
<key>UIBackgroundModes</key>
<array>
  <string>voip</string>
  <string>audio</string>
</array>
• And don’t forget to enable Background Modes in Xcode under Signing & Capabilities: ◦ Make sure to check Voice over IP and Audio, AirPlay, and Picture in Picture. 6. Optional: Enable Background Camera Access (iOS 18+):
Copy code
import { WebRTCModuleOptions } from "@livekit/react-native-webrtc";

const options = WebRTCModuleOptions.sharedInstance();
options.enableMultitaskingCameraAccess = true;
These steps should set you up nicely with CallKit and solid background support for your calls. If you run into any questions or need a hand with anything else, just let me know—I’m here to help! Sources: docs/index.html | README.md | Documentation/iOSInstallation.md | Expo quickstart | LiveKit docs
d
do i need to add entitlements for this in app.json like com.apple.developer.pushkit.unrestricted-voip com.apple.developer.usernotifications.communication or any other changes in appdelegate.swift
t
Hi there! When integrating CallKit into your React Native Expo project, there are a few important entitlements and configurations you might want to consider based on your app’s needs. Let’s walk through them together: 1. Required Background Modes: • Make sure to enable Audio and VoIP background modes in your
Info.plist
file:
Copy code
<key>UIBackgroundModes</key>
<array>
  <string>voip</string>
  <string>audio</string>
</array>
• In Xcode, head over to Signing & Capabilities → Add Capability → Background Modes, and check: ◦ Voice over IP ◦ Audio, AirPlay, and Picture in Picture 2. Entitlements: • com.apple.developer.pushkit.unrestricted-voip: You’ll need this if your app uses PushKit for VoIP push notifications to wake the app and report incoming calls through CallKit. It’s a good idea to start without it and add it only if necessary. • com.apple.developer.usernotifications.communication: This one isn’t required for CallKit-based voice calling, so you can skip it. 3. Expo Configuration: • To get things up and running smoothly, use a custom development build with `expo-dev-client`:
Copy code
npx expo install expo-dev-client
• Also, add the LiveKit Expo plugin to your `app.json`:
Copy code
{
  "plugins": [
    "livekit-react-native-expo-plugin"
  ]
}
4. Optional Changes in AppDelegate: • If you’re targeting iOS 18 or newer and need background camera access, you can enable multitasking camera access in your
AppDelegate.swift
like this:
Copy code
import { WebRTCModuleOptions } from "@livekit/react-native-webrtc";

let options = WebRTCModuleOptions.sharedInstance();
options.enableMultitaskingCameraAccess = true;
If you have any questions or need a hand with these steps, please don’t hesitate to reach out. I’m here to help you every step of the way! Sources: Expo quickstart | LiveKit docs | README.md | callkit/README.md
d
just like for android we do this is app.tsx for android do we need to register for nativemodules const ForegroundServiceModule = Platform.OS === 'android' ? NativeModules.ForegroundService : null; const foregroundServiceEventEmitter = Platform.OS === 'android' && ForegroundServiceModule ? new NativeEventEmitter(ForegroundServiceModule) : null; registerGlobals();
t
Hi there! For iOS in a React Native Expo project, you actually don’t need to register native modules in
App.tsx
for CallKit or background processing. These features are usually managed through native configurations and libraries like
react-native-callkeep
, which makes things a bit smoother. Here are some key points to keep in mind: • Use
react-native-callkeep
to integrate CallKit. The setup and initialization typically happen in native iOS files or a dedicated service file such as
CallService.ios.ts
. • Make sure to enable Audio and VoIP background modes in your app’s capabilities through Xcode or Expo’s config plugin. • Coordinate audio session events with WebRTC by calling
RTCAudioSession.audioSessionDidActivate()
and
RTCAudioSession.audioSessionDidDeactivate()
when CallKit events occur. • To simplify native setup without ejecting, you can use the LiveKit Expo config plugin like this:
Copy code
{
  "plugins": [
    "livekit-react-native-expo-plugin"
  ]
}
• Also, create a custom development build with
expo-dev-client
to include native modules by running:
Copy code
npx expo install expo-dev-client
npx expo run:ios
If you have any questions or need a hand with these steps, please don’t hesitate to reach out—I’m here to help! Sources: README.md | Expo quickstart | LiveKit docs
d
in ios i'm getting this error ERROR [runtime not ready]: Invariant Violation:
new NativeEventEmitter()
requires a non-null argument., js engine: hermes
t
I'm sorry you're encountering the error "new NativeEventEmitter() requires a non-null argument." This usually happens when the native module isn't properly initialized or linked. Don't worry, let's work through this together! Here are some steps you can follow to fix this on iOS: 1. Ensure Proper Setup in AppDelegate: • In
AppDelegate.m
or
AppDelegate.swift
, make sure to call the setup method before any other React Native initialization:
Copy code
// Objective-C (AppDelegate.m)
#import "LivekitReactNative.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [LivekitReactNative setup];
  // Other initialization
}
Copy code
// Swift (AppDelegate.swift)
import livekit_react_native

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
  LivekitReactNative.setup()
  // Other initialization
}
2. Verify Installation: • Let's double-check that all dependencies are installed correctly:
Copy code
npm install @livekit/react-native @livekit/react-native-webrtc livekit-client
cd ios && pod install
3. Check Native Module Availability: • You can log the native modules to make sure they're properly registered:
Copy code
import { NativeModules } from "react-native";
console.log("LiveKitModule:", NativeModules.LivekitReactNativeModule);
console.log("WebRTCModule:", NativeModules.WebRTCModule);
4. Clean and Rebuild: • Sometimes a clean build helps. Try cleaning the iOS build and reinstalling dependencies:
Copy code
cd ios
rm -rf build/ Pods/ Podfile.lock
pod install
npx react-native run-ios
5. Register WebRTC Globals: • Make sure
registerGlobals()
is called in your
index.js
file:
Copy code
import { registerGlobals } from "@livekit/react-native";
registerGlobals();
Give these steps a try, and hopefully, this will resolve the issue for you. If you run into any more trouble or have questions, please don't hesitate to reach out—I’m here to help! Sources: android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java | ios/Podfile | React Native SDK | livekit/livekit_composite | DeepWiki | src/hooks/useMultibandTrackVolume.ts
d
for android i'm doing this for ios what to do const ForegroundServiceModule = Platform.OS === 'android' ? NativeModules.ForegroundService : null; const foregroundServiceEventEmitter =( Platform.OS === 'android' && ForegroundServiceModule) ? new NativeEventEmitter(ForegroundServiceModule) : null;
t
Hi there! I understand you're looking to achieve background execution on iOS similar to Android's
ForegroundServiceModule
. While iOS handles this a bit differently using background modes and CallKit, I’m here to guide you through the setup step-by-step: 1. Enable Background Modes: • Open Xcode, select your app target → Signing & Capabilities → Add Capability → Background Modes. • Make sure to enable: ◦ Audio, AirPlay, and Picture in Picture ◦ Voice over IP (VoIP) 2. Use CallKit for Background Persistence:
Copy code
import RNCallKeep from "react-native-callkeep";
import { RTCAudioSession } from "@livekit/react-native-webrtc";

export async function startCallService() {
  RNCallKeep.startCall("uuid", "1234", "Caller");
  RNCallKeep.reportConnectedOutgoingCallWithUUID("uuid");
}

export function setupCallService() {
  const options = {
    ios: {
      appName: "LiveKitReactNative",
      audioSession: {
        category: "playAndRecord",
        mode: "videoChat",
        options: ["allowBluetooth", "allowAirPlay", "defaultToSpeaker"],
      },
    },
  };
  RNCallKeep.setSettings(options);
}
3. Use NativeEventEmitter for Events:
Copy code
import { NativeEventEmitter } from "react-native";
import LiveKitModule from "../LKNativeModule";

const nativeEmitter = new NativeEventEmitter(LiveKitModule);
nativeEmitter.addListener("LK_AUDIO_DATA", (data) => {
  console.log("Received audio data:", data);
});
Following these steps will help keep your app running smoothly in the background on iOS and handle events properly. If you run into any questions or need a hand with anything else, please don’t hesitate to reach out—I’m here to help! Sources: docs/index.html
d
ERROR [runtime not ready]: Invariant Violation:
new NativeEventEmitter()
requires a non-null argument., js engine: hermes
t
Hi there! It looks like you're encountering the error "new NativeEventEmitter() requires a non-null argument," which usually happens when the native module passed to
NativeEventEmitter
is
null
or undefined. Don’t worry, I’m here to help you work through this on iOS. Let’s go through some steps together: 1. Ensure Proper Setup in AppDelegate: • In your
AppDelegate.m
or
AppDelegate.swift
, make sure to call the setup method before any React Native initialization:
Copy code
// Objective-C (AppDelegate.m)
#import "LivekitReactNative.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [LivekitReactNative setup];
  // Other initialization
}
Copy code
// Swift (AppDelegate.swift)
import livekit_react_native

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
  LivekitReactNative.setup()
  // Other initialization
}
2. Verify Installation: • Let’s double-check that all dependencies are installed and properly linked:
Copy code
npm install @livekit/react-native @livekit/react-native-webrtc livekit-client
cd ios && pod install
3. Check Native Module Availability: • It’s helpful to log the native modules to confirm they’re registered correctly:
Copy code
import { NativeModules } from "react-native";
console.log("LiveKitModule:", NativeModules.LivekitReactNativeModule);
console.log("WebRTCModule:", NativeModules.WebRTCModule);
4. Clean and Rebuild: • Sometimes a fresh build can clear up issues. Try cleaning the iOS build and reinstalling dependencies:
Copy code
cd ios
rm -rf build/ Pods/ Podfile.lock
pod install
npx react-native run-ios
5. Ensure Proper Event Emitter Usage: • Make sure you’re using
NativeEventEmitter
with a valid native module like this:
Copy code
import { NativeEventEmitter } from "react-native";
import LiveKitModule from "../LKNativeModule";

const nativeEmitter = new NativeEventEmitter(LiveKitModule);
nativeEmitter.addListener("LK_AUDIO_DATA", (data) => {
  console.log("Received audio data:", data);
});
I hope these steps help you get things running smoothly! If you run into any more issues or have questions, please don’t hesitate to reach out. I’m here to support you every step of the way! Sources: README.md | examples/GumTestApp/ios/Podfile | React Native SDK | livekit/livekit_composite | DeepWiki | [Flutter iOS] SoundWaveformWidget / AudioVisualizerWidget Not Working (Miss...
It looks like you're encountering the error "Cannot find LivekitReactNative in scope," which usually means the LiveKit native module isn't linked or configured correctly. Don't worry, I’m here to help you get this sorted out in your Expo project! Just follow these steps: 1. Use the LiveKit Expo Plugin: • First, install the necessary dependencies by running:
Copy code
npx expo install livekit-client @livekit/react-native @livekit/react-native-webrtc @livekit/react-native-expo-plugin @config-plugins/react-native-webrtc
• Then, add these plugins to your
app.json
file:
Copy code
{
  "expo": {
    "plugins": [
      "@livekit/react-native-expo-plugin",
      "@config-plugins/react-native-webrtc"
    ]
  }
}
• After that, rebuild your app using these commands:
Copy code
npx expo prebuild --clean
npx expo run:ios
2. Manual Setup (if you prefer not to use the plugin): • Make sure to import LiveKit in your
AppDelegate.swift
like this:
Copy code
import livekit_react_native
• And don’t forget to call
LivekitReactNative.setup()
inside `application(_didFinishLaunchingWithOptions)`:
Copy code
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    LivekitReactNative.setup()
    return true
}
3. Verify Installation: • Double-check that all dependencies are installed and linked by running:
Copy code
cd ios && pod install
• Then, rebuild your app to make sure everything is applied correctly. 4. Debugging Tips: • Make sure you’re using a development build and not Expo Go. • Confirm that the plugin is modifying native files during the build process. • If things still seem off, try running
npx expo prebuild --clean
to regenerate native code. If you run into any trouble or have questions along the way, please don’t hesitate to reach out—I’m here to help you! Sources: docs/index.html | README.md | React Native quickstart | LiveKit docs
d
is rebuild command is required
t
Absolutely, when you make changes to native configurations in your Expo project, a rebuild is definitely needed. This usually happens when you: • Add or modify plugins in
app.json
(like the LiveKit Expo plugin). • Update native files such as
AppDelegate.swift
or
Info.plist
. • Install new native dependencies (for example,
@livekit/react-native
). To make sure everything is set up correctly, you can run these commands:
Copy code
npx expo prebuild --clean
npx expo run:ios
This process will apply all your native changes and include them in your build. If you have any questions or need a hand with this, just let me know—I’m here to help!
d
i'm getting error again and again ios ERROR [runtime not ready]: Invariant Violation:
new NativeEventEmitter()
requires a non-null argument., js engine: hermes whereas in android it's fine
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
d
now when i am doing calling using livekit it's working in the lock state and when going on the home screen and notes whereas when going on the apps like whatsapp snapchat there call is disconnecting