Skip to main content

πŸš€ Expo Integration Guide for react-native-pitel-voip-v2

This guide explains how to integrate the Pitel VoIP Calling SDK v2 (react-native-pitel-voip-v2) into an Expo application (supports Expo SDK 50 up to Expo SDK 57+, React 19, New Architecture, and Expo Router).


CAUTION

Expo Go is NOT supported because react-native-pitel-voip-v2 contains custom C++ (PJSIP) and native iOS CallKit / Android Foreground Service modules. You must run the app using Expo Development Builds (expo-dev-client) or build via EAS Build.


πŸ“¦ Step 1: Install Dependencies​

In your Expo project root, install the SDK, Firebase modules, and Expo Development Client:

# Using pnpm (Recommended)
pnpm add react-native-pitel-voip-v2 @react-native-firebase/app @react-native-firebase/messaging @react-native-async-storage/async-storage
npx expo install expo-dev-client expo-build-properties

# Using npm
npm install react-native-pitel-voip-v2 @react-native-firebase/app @react-native-firebase/messaging @react-native-async-storage/async-storage
npx expo install expo-dev-client expo-build-properties

# Using yarn
yarn add react-native-pitel-voip-v2 @react-native-firebase/app @react-native-firebase/messaging @react-native-async-storage/async-storage
npx expo install expo-dev-client expo-build-properties

βš™οΈ Step 2: Configure app.json​

  1. Place your google-services.json (Android) and GoogleService-Info.plist (iOS) in the root folder of your Expo project.
  2. Update your app.json with the bundle identifier, package name, Firebase file paths, and config plugins:
{
"expo": {
"name": "My VoIP App",
"slug": "my-voip-app",
"version": "1.0.0",
"ios": {
"bundleIdentifier": "com.yourcompany.app",
"googleServicesFile": "./GoogleService-Info.plist",
"supportsTablet": true
},
"android": {
"package": "com.yourcompany.app",
"googleServicesFile": "./google-services.json"
},
"plugins": [
[
"react-native-pitel-voip-v2",
{
"microphonePermission": "CαΊ§n quyền micro để thα»±c hiện cuα»™c gọi VoIP.",
"incomingCallMode": "fullscreen"
}
],
[
"expo-build-properties",
{
"ios": {
"useFrameworks": "static"
}
}
]
]
}
}
NOTE
  • react-native-pitel-voip-v2 config plugin automatically injects required permissions (RECORD_AUDIO, POST_NOTIFICATIONS, FOREGROUND_SERVICE, USE_FULL_SCREEN_INTENT) into AndroidManifest.xml and background modes (audio, voip, fetch, remote-notification) into Info.plist.
  • expo-build-properties with "useFrameworks": "static" is mandatory for Firebase and native static library linking on iOS.

πŸ›  Step 3: Run Expo Prebuild​

Generate the native android and ios project directories:

npx expo prebuild

πŸ€– Step 4: Verify & Complete Native Configurations​

After prebuild finishes, complete the following native configurations:

4.1 Android Configuration​

  1. Verify android/build.gradle: Ensure Google Services classpath is present in dependencies:

    buildscript {
    dependencies {
    classpath('com.google.gms:google-services:4.4.2') // or 4.3.15+
    }
    }
  2. Verify android/app/build.gradle: Apply Google Services plugin and ensure FCM dependencies:

    apply plugin: "com.google.gms.google-services"

    dependencies {
    // Required for Kotlin compilation of Custom Messaging Service
    implementation("com.google.firebase:firebase-messaging:24.1.0")
    }
  3. Declare Custom Messaging Service in android/app/src/main/AndroidManifest.xml: Inside <application>, register your custom FCM receiver and remove conflicting default services:

    <!-- Custom Messaging Service for multiplexing VoIP Push & normal notifications -->
    <service
    android:name=".MyCustomMessagingService"
    android:exported="false">
    <intent-filter>
    <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
    </service>

    <!-- Prevent multiple FCM receivers from conflicting -->
    <service
    android:name="com.pitel.voip.sdk.service.PitelFirebaseMessagingService"
    tools:node="remove" />
    <service
    android:name="io.invertase.firebase.messaging.ReactNativeFirebaseMessagingService"
    tools:node="remove" />

    <meta-data
    android:name="com.google.firebase.messaging.default_notification_channel_id"
    android:value="pitel_incoming_call_channel_v3"
    tools:replace="android:value" />
  4. Create MyCustomMessagingService.kt: In android/app/src/main/java/<package_path>/MyCustomMessagingService.kt:

    package <YOUR_APP_PACKAGE_NAME>

    import com.google.firebase.messaging.RemoteMessage
    import com.pitel.voip.sdk.core.PitelClient
    import io.invertase.firebase.messaging.ReactNativeFirebaseMessagingService

    class MyCustomMessagingService : ReactNativeFirebaseMessagingService() {
    override fun onMessageReceived(remoteMessage: RemoteMessage) {
    val data = remoteMessage.data
    if (PitelClient.isPitelPushNotification(data)) {
    PitelClient.initialize(applicationContext)
    PitelClient.handleFCMMessage(applicationContext, data)
    } else {
    super.onMessageReceived(remoteMessage)
    }
    }

    override fun onNewToken(token: String) {
    PitelClient.initialize(applicationContext)
    PitelClient.saveFcmToken(token)
    super.onNewToken(token)
    }
    }

4.2 iOS Configuration (AppDelegate.swift)​

In ios/<YourAppName>/AppDelegate.swift, initialize CallKit & PushKit listeners before the React Native bridge launches:

Merge these SDK calls into your generated AppDelegate, preserving its superclass, Expo/React Native initialization, and bundle URL overrides. The RCTAppDelegate snippet below illustrates where the calls belong; keep the startup structure generated by your Expo version. See the iOS setup guide.

import UIKit
import React
import React_RCTAppDelegate
import FirebaseCore
import react_native_pitel_voip_v2

@main
class AppDelegate: RCTAppDelegate {
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
self.moduleName = "main"
self.initialProps = [:]

FirebaseApp.configure()

// 1. Initialize PitelVoIPDelegate before JS bridge starts
_ = PitelVoIPDelegate()
PitelVoIP.configure()

let result = super.application(application, didFinishLaunchingWithOptions: launchOptions)

// 2. Register presentation host for native Call Screen
PitelVoIP.registerCallPresentationHostProvider { [weak self] in
self?.window.rootViewController
}

return result
}
}

⚑ Step 5: JavaScript / Expo Router Integration​

In your root layout (app/_layout.tsx for Expo Router, or App.tsx):

import React, { useEffect } from 'react';
import { Platform } from 'react-native';
import { getMessaging, getToken, requestPermission } from '@react-native-firebase/messaging';
import { PitelVoipClient } from 'react-native-pitel-voip-v2';

export default function RootLayout() {
const client = PitelVoipClient.instance;

useEffect(() => {
const setupVoip = async () => {
// 1. Request Runtime Permissions
// Microphone on both platforms; notifications on Android 13+.
const granted = await client.requestPermissions();
if (!granted) return;

// 2. Sync FCM Token to Pitel SDK
try {
const messaging = getMessaging();
if (Platform.OS === 'ios') {
await requestPermission(messaging);
}
const fcmToken = await getToken(messaging);
if (fcmToken) {
await client.setFCMToken(fcmToken);
}
} catch (e) {
console.warn('Failed to get FCM Token:', e);
}

// 3. Attempt Auto Login with cached credentials
const autoLoggedIn = await client.autoLogin();
if (!autoLoggedIn) {
// Show your app's SIP login UI and call client.login(settings).
}
};

setupVoip();
}, []);

// Return your navigation / slot
return null;
}

On a fresh installation there are no saved credentials. Follow Authenticate SIP Extension for the required login() settings, and observe the registration listener before enabling outgoing calls.

Also complete the following push handling:

  • Subscribe to onTokenRefresh and forward each new token to client.setFCMToken(token). Remove the subscription when its owner unmounts; see the example listeners.
  • On iOS, forward call-cancellation payloads to client.handlePushNotification(message.data) through onMessage in the foreground and setBackgroundMessageHandler in the background. Register the background handler once in the app entry file, outside React components. Follow the iOS token and message handling guide; see also the example entry file. Keep FCM forwarding in React Native Firebase rather than adding another handler in AppDelegate.

πŸ“± Step 6: Run & Build​

1. Run Local Development Build:​

# Run Android Development Build
npx expo run:android

# Run iOS Development Build (Physical iPhone required for VoIP push & CallKit)
npx expo run:ios --device

2. Build Production with EAS Build:​

# Build standalone APK/AAB for Android
eas build --platform android --profile production

# Build standalone IPA for iOS
eas build --platform ios --profile production

βœ… Summary Checklist for Expo Developers​

  • Use expo-dev-client (do not run via Expo Go app).
  • Declare react-native-pitel-voip-v2 and expo-build-properties (static linkage) in app.json.
  • Place google-services.json and GoogleService-Info.plist at the project root and link them in app.json.
  • Run npx expo prebuild and verify native configurations.
  • Always test inbound VoIP calls on a physical iOS device (PushKit does not work on Simulator).