Keeping The Call Alive In Background

One of the crucial functionalities of a video or audio calling application is to keep the call alive in the background. On this page, we focus on what must be added to your app to support this. After enabling, the user of your app will notice that the call is kept alive even if the app goes to the background as they will still hear the remote audio streams while the app is kept in the background.

Android Setup

In Android, we use a foreground service to keep the call alive. The SDK will automatically create and manage the foreground service. The first step is to install the Notifee library so that SDK can handle a foreground service. To install the Notifee library, run the following command in your terminal of choice:

Terminal
npx expo install @notifee/react-native

The next step is, in order to be able to use the foreground service, some declarations need to be added the AndroidManifest.xml. In app.json, in the plugins field, add true to the androidKeepCallAlive property in the @stream-io/video-react-native-sdk plugin. This will add the declarations automatically.

app.json
{
 "plugins": [
      [
        "@stream-io/video-react-native-sdk",
        {
           "androidKeepCallAlive": true
        }
      ],
      // your other plugins
  ]
}

If Expo EAS build is not used, please do npx expo prebuild --clean to edit the AndroidManifest.xml again after adding the config plugin property.

Optional: override the default configuration of the foreground service notifications

import { StreamVideoRN } from '@stream-io/video-react-native-sdk';
import { AndroidImportance } from '@notifee/react-native';

StreamVideoRN.updateConfig({
  foregroundService: {
    android: {
      // see https://notifee.app/react-native/reference/nativeandroidchannel
      // for the various properties that can be used
      channel: {
        id: 'stream_call_foreground_service',
        name: 'Service to keep call alive',
        lights: false,
        vibration: false,
        importance: AndroidImportance.DEFAULT,
      },
      // you can edit the title and body of the notification here
      notificationTexts: {
        title: 'Video call is in progress',
        body: 'Tap to return to the call',
      },
    },
  },
});

iOS Setup

The way to keep audio alive in the background is to enable the audio background mode. When you enable this capability, your app’s audio playback will continue to play when users lock their iOS device or switch to another app. In Xcode: Open the Info.plist file and add audio in UIBackgroundModes. By editing this file with a text editor, you should see:

<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
</array>
© Getstream.io, Inc. All Rights Reserved.