RTCEXPRESS DOCUMENTATION

Build real-time communication into your app

This quickstart takes you from a project credential to a test call while keeping authorization under your control.

Open API reference

Before you begin

Create a project in the customer portal. Each project has an App ID and App Secret. The App Secret belongs only in a secure backend environment, never in a browser, mobile app, or public Git repository.

Choose your pathFree includes chat and 1:1 voice. Starter adds group voice. Pro adds video and screen sharing.

1. Issue a user token from your backend

Authenticate your user in your own system, confirm that they can enter the requested room, and then call the token endpoint using project credentials.

POST /v1/token

{ "appId": "app_…", "appSecret": "sec_…", "userId": "user_123", "roomId": "room_42" }

On Node.js, the rtcexpress-server package makes this call for you (Python: pip install rtcexpress-server, see the Python server SDK):

npm install rtcexpress-server

const { token } = await rtc.createToken({ userId: "user_123", roomId: "room_42" });

Return the short-lived token to the client. Do not trust a room or user ID solely because the browser submitted it.

2. Initialize and join

Register listeners before initialization. When the connection is ready, join the authorized room. Enable chat and call controls after the room-joined event.

const rtc = new RTCExpress();
rtc.on("roomJoined", () => rtc.sendMessage("Hello"));
await rtc.init({ serverUrl, appId, userId, token });
rtc.joinRoom("room_42");

Use the customer portal’s Integration section for the project-specific endpoint and examples.

3. Test the actual user experience

  • Use two distinct users in the same project and room.
  • Test camera and microphone permission denial, reconnects, and network changes.
  • Test chat, voice, and video separately on real devices.
  • Record the call ID and UTC time when reporting a problem.

Push notifications: ring a phone when your app is closed

While your app is open, RTCExpress delivers calls over its live connection. When the app is in the background, closed, or the phone is locked or on silent, only Google (Android) or Apple (iOS) can wake the phone. RTCExpress asks them to do it, using credentials from your Firebase and Apple accounts.

Required: create your own Firebase projectEvery app that uses RTCExpress needs its own Firebase project. Device tokens belong to the Firebase project your app is built with, so RTCExpress cannot send to your users with any other project. Your end users never see or set up Firebase. This is a one-time setup for your development team. Firebase Cloud Messaging is free.

How a call reaches a closed app

Caller taps "Call"  →  RTCExpress server  →  Google FCM / Apple APNs  →  Callee's phone wakes and rings
                        (uses YOUR uploaded key)                         →  User accepts  →  app reconnects to RTCExpress

Android setup (once per app)

  1. Create a Firebase project at console.firebase.google.com.
    Firebase console with the Create a new Firebase project card highlighted
    Click “Create a new Firebase project”.
  2. Add your Android app to it with your exact package name (for example com.yourcompany.app). Download google-services.json and place it in your app module folder.
    Firebase project settings with the google-services.json download link highlighted
    Project settings → Your apps → download google-services.json.
    YourProject/
    ├── app/
    │   ├── google-services.json   ← put it here
    │   ├── build.gradle.kts
    │   └── src/
    └── build.gradle.kts
  3. Add Firebase Messaging to your app: the com.google.gms.google-services Gradle plugin and the firebase-messaging dependency.
  4. Generate a server key: Firebase console → Project settings → Service accounts → Generate new private key. This downloads a JSON file. It is not google-services.json.
    Firebase Service accounts tab with the Generate new private key button highlighted
    Project settings → Service accounts → Generate new private key.
  5. Upload that key in the RTCExpress console under Service management → In-app chat → Android offline push. Keep the file private. Never put it in your app or Git.
    RTCExpress console Android offline push section with Add credentials and the file chooser highlighted
    In the RTCExpress console: Add credentials → choose the service-account JSON → tick the confirmation → Save credentials.
  6. Register each signed-in device and handle incoming calls in your app (code below).
// After the user signs in, and again in onNewToken():
FirebaseMessaging.getInstance().token.addOnSuccessListener { fcmToken ->
    // POST https://api.devsquarelabs.com/v1/push/devices
    // Authorization: Bearer <this user's RTC token>
    // {"installationId":"<random id saved on the device>","platform":"android","token": fcmToken}
}

// In your FirebaseMessagingService:
override fun onMessageReceived(message: RemoteMessage) {
    if (message.data["type"] != "rtc_call_invite") return
    val expiresAt = message.data["expiresAt"]?.toLongOrNull() ?: return
    if (System.currentTimeMillis() > expiresAt) return   // call already ended
    // Show a full-screen incoming-call UI using callId, roomId, fromUserId, callType.
    // On Accept: get a fresh RTC token, init, joinRoom(roomId), acceptCall().
}

Also request the notification permission on Android 13+, and declare full-screen intent for the ringing screen. On logout, call DELETE /v1/push/devices/<installationId> so the old user's calls stop ringing that phone.

The pushes RTCExpress sends

All are FCM data messages (no visible notification of their own), so your app decides what to show. Check data.type:

  • rtc_call_invite: someone is calling. Fields: callId, roomId, fromUserId, callType (voice or video), expiresAt (milliseconds). Show a ringing screen until it expires.
  • rtc_call_cancel: the call stopped ringing (caller hung up, it was answered on another device, or declined). Fields: callId, reason. Stop ringing.
  • rtc_missed_call: nobody answered. Fields: callId, fromUserId, callType. Stop ringing and add it to your missed-calls list.
  • rtc_chat_message: a new chat message while the app is in the background (after you enable room alerts). Fields: roomId, messageId.

React Native: ring, answer and stop ringing

Tested on Android phones with the app in the background, swiped away and on a locked screen. Uses @react-native-firebase/messaging for the push and @notifee/react-native for the full-screen ringing notification. Put the background handler in index.js, so it runs even when the app is closed.

// index.js (runs even when the app is closed)
import { AppRegistry } from "react-native";
import messaging from "@react-native-firebase/messaging";
import notifee, { AndroidCategory, AndroidImportance, EventType } from "@notifee/react-native";
import AsyncStorage from "@react-native-async-storage/async-storage";
import App from "./App";

async function showIncomingCall(d) {
  await notifee.createChannel({ id: "calls", name: "Incoming calls", importance: AndroidImportance.HIGH, sound: "default" });
  await notifee.displayNotification({
    id: `call-${d.callId}`,
    title: d.fromUserId,
    body: d.callType === "video" ? "Incoming video call" : "Incoming voice call",
    data: { ...d, kind: "call" },
    android: {
      channelId: "calls", category: AndroidCategory.CALL, importance: AndroidImportance.HIGH,
      ongoing: true, loopSound: true,
      timeoutAfter: Math.max(5000, Number(d.expiresAt) - Date.now()),
      fullScreenAction: { id: "default" },
      actions: [
        { title: "Answer", pressAction: { id: "answer", launchActivity: "default" } },
        { title: "Decline", pressAction: { id: "decline" } },
      ],
    },
  });
}

messaging().setBackgroundMessageHandler(async ({ data }) => {
  if (data?.type === "rtc_call_invite") await showIncomingCall(data);
  else if (data?.type === "rtc_call_cancel" || data?.type === "rtc_missed_call")
    await notifee.cancelNotification(`call-${data.callId}`);
});

notifee.onBackgroundEvent(async ({ type, detail }) => {
  const d = detail.notification?.data;
  if (type !== EventType.ACTION_PRESS || d?.kind !== "call") return;
  await notifee.cancelNotification(`call-${d.callId}`);
  if (detail.pressAction?.id === "answer") await AsyncStorage.setItem("answerCallId", String(d.callId));
});

AppRegistry.registerComponent("YourApp", () => App);
// App.tsx: after the app opens from "Answer"
const answerId = await AsyncStorage.getItem("answerCallId");
await rtc.init({ serverUrl, appId, userId, token: await getTokenFromYourBackend() });
// A call that is still ringing is sent to the app again as soon as it connects:
rtc.on("callInvite", (invite) => {
  if (invite.callId === answerId) { AsyncStorage.removeItem("answerCallId"); rtc.acceptCall(); }
  else showYourIncomingCallScreen(invite);
});

Register the device after every login with POST /v1/push/devices (above), and again in messaging().onTokenRefresh. While the app is open, the SDK's own callInvite event rings it, so you don't need the push then.

iOS setup (once per app)

On iPhone, Apple wakes the phone instead of Google, so RTCExpress needs an APNs key from your Apple Developer account. Firebase is not used for iOS calls.

  1. Create an APNs key: Apple Developer → Certificates, IDs & Profiles → Keys → add a key with Apple Push Notifications service (APNs) enabled. Download the .p8 file. Apple lets you download it only once, so store it safely.
  2. Note two IDs: the Key ID is shown on the key's page. Your Team ID is under Membership details. Both are 10 characters.
  3. Enable push for your app: in Identifiers, open your App ID and turn on Push Notifications. In Xcode, add the Push Notifications capability and Background Modes → Voice over IP.
  4. Upload in the RTCExpress console under Service management → In-app chat → iOS: Bundle ID, environment, Team ID, Key ID and the .p8 file. Upload it once for sandbox (Xcode builds) and once for production (TestFlight and App Store). The same key can be used for both.
  5. Register two tokens per device with POST /v1/push/devices, using the same installation ID: the PushKit token with pushType: "voip" for calls, and the normal APNs token with pushType: "alert" for chat alerts.
  6. Show calls through CallKit as soon as a VoIP push arrives (code below).
// Calls: PushKit token → register with pushType "voip"
func pushRegistry(_ registry: PKPushRegistry, didUpdate creds: PKPushCredentials, for type: PKPushType) {
    let token = creds.token.map { String(format: "%02x", $0) }.joined()
    // POST /v1/push/devices  (Authorization: Bearer <RTC user token>)
    // {"installationId":"<saved id>","platform":"ios","pushType":"voip","token": token,
    //  "bundleId":"com.yourcompany.app","environment":"production"}
}

// Incoming call push: report to CallKit immediately, or iOS stops waking your app
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload,
                  for type: PKPushType, completion: @escaping () -> Void) {
    // payload.dictionaryPayload has type "rtc_call_invite", callId, roomId, fromUserId, callType, expiresAt
    provider.reportNewIncomingCall(with: UUID(), update: CXCallUpdate()) { _ in completion() }
    // On answer: get a fresh RTC token, connect, joinRoom(roomId), acceptCall()
}

// Chat alerts: normal APNs token → register with pushType "alert"
func application(_ app: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    let token = deviceToken.map { String(format: "%02x", $0) }.joined()
    // Same endpoint and installationId, with "pushType":"alert"
}

If the phone is switched off

A call invitation lives for 60 seconds. If the phone comes online within that time it rings. Otherwise the call expires and the caller sees it was not answered, so a phone switched on hours later does not ring for an old call.

Checklist

  • Firebase project is your own, and its Android app uses the same package name as your Play Store app.
  • The uploaded file is the service-account key, not google-services.json.
  • Devices are registered after login and re-registered when the FCM token changes.
  • iOS: the APNs key is uploaded for both sandbox and production, with the same Bundle ID as your app.
  • iOS: both the VoIP token and the alert token are registered, and every VoIP push is reported to CallKit.
  • Tested on a real phone with the app in the background, swiped away, and the screen locked.
  • Push attempts are visible in Portal → Diagnostics. Google accepting a push does not prove the phone displayed it.

Prefer to send pushes from your own server? Subscribe to the call.ringing webhook instead, and do not enable both senders for the same device.

Diagnostics and support

Signed-in customers can search diagnostics by call ID and inspect call events, quality, push attempts, and webhook delivery. Check service status before opening a support request.

Ready to create a project?

Create free accountDeveloper hub