Skip to content
One-to-one Calls

Ringing when the app is closed

Ring a phone through CallKit and Firebase when your app is in the background or closed.

A phone rings for a call while your app is closed through a push: a VoIP push and CallKit on iPhones, a Firebase message on Android.

Add your credentials

Open your project's Services tab, and add your Apple (APNs) and Firebase credentials in the Push credentials card. Use Test credentials to check that Apple and Google accept them.

Once a project has its own credentials, it uses only those. A platform you leave empty gets no pushes.

Register the device

// When the user signs in, and whenever Firebase replaces the token.
await calls.registerPush(fcmToken: await FirebaseMessaging.instance.getToken());
await VoxeraCalls.requestRingPermissions();
 
// When the user signs out.
await calls.unregisterPush();

Create the controller and call connect as early as you can after your app starts. That is how a call the user just answered on the system's screen gets connected.

Android

Your app keeps its own Firebase setup and passes the messages on, from the foreground and the background. Register a background handler too, so a call declined while your app is closed stops ringing for the caller right away. Both have to be top-level functions:

@pragma('vm:entry-point')
Future<void> onBackgroundMessage(RemoteMessage message) async {
  await VoxeraCalls.handlePush(message.data);
}
 
@pragma('vm:entry-point')
Future<void> onBackgroundCallEvent(CallEvent event) async {
  await VoxeraCalls.handleBackgroundEvent(event, config: callConfig);
}
 
void main() {
  FirebaseMessaging.onBackgroundMessage(onBackgroundMessage);
  FirebaseMessaging.onMessage.listen((message) => VoxeraCalls.handlePush(message.data));
  VoxeraCalls.registerBackgroundHandler(onBackgroundCallEvent);
  // ...
}

Without the handler, the caller hears it ring until the call times out.

iOS

iOS ends any app that gets a VoIP push and does not show a call straight away, so this part is in Swift. Turn on the Push Notifications capability and the voip, audio and remote-notification background modes, then copy AppDelegate.swift from the package's example app. Add your engine's address to Info.plist as VoxeraBaseUrl, the same baseUrl as your VoxeraCallConfig.

CallKit does not work in the Simulator, so test this on an iPhone.

Pass your Firebase messages to VoxeraCalls.handlePush on iOS too. They stop the ringing when the caller gives up or another device answers.

Ask for permissions early

Ask for the microphone, and the camera if you offer video, before the first call comes in. On a locked phone nobody can answer the prompt, and a call answered without the microphone is declined.