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 manage the foreground service. But in order to be able to use the foreground service, some declarations need to be added in the AndroidManifest.xml
:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<!-- We declare the permissions to for using foreground service -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<!-- We specify to notifee that we will use microphone in the background -->
<service
android:name="app.notifee.core.ForegroundService"
android:stopWithTask="true"
android:foregroundServiceType="microphone" />
Check the compileSdk, targetSdk and minSdk versions
In android/build.gradle
make sure that the following is inside the buildscript
section:
buildscript {
ext {
...
minSdkVersion = 24
compileSdkVersion = 34
targetSdkVersion = 33
}
...
}
We have to temporarily use targetSdkVersion 33 due to a lack of support for dynamically setting foreground service types in the notifee library. We are aware of the August 31, 2024 deadline for updating to targetSdkVersion 34 and we are actively working on adding support in the notifee library.
Optional: override the default configuration of the notifications
You can also optionally override the default configuration of the notification used by the SDK. Below we give an example of that:
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>