Skip to content

Commit b154a28

Browse files
authored
docs: update readme for background processing (#167)
1 parent ef9b901 commit b154a28

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

README.md

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -295,29 +295,7 @@ Enabling screenshare requires extra installation steps:
295295

296296
Android screenshare requires a foreground service with type `mediaProjection` to be present.
297297

298-
From 2.4.0 onwards, this is handled internally and no extra setup is required.
299-
300-
---
301-
302-
On versions prior to 2.4.0, you must declare your own foreground service.
303-
304-
The example app uses [@supersami/rn-foreground-service](https://github.com/Raja0sama/rn-foreground-service) for this.
305-
306-
Add the following permissions to your `AndroidManifest.xml` file:
307-
308-
```xml
309-
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
310-
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
311-
```
312-
313-
Declare the the service and ensure it's labelled a `mediaProjection` service like so:
314-
315-
```xml
316-
<service android:name="com.supersami.foregroundservice.ForegroundService" android:foregroundServiceType="mediaProjection" />
317-
<service android:name="com.supersami.foregroundservice.ForegroundServiceTask" />
318-
```
319-
320-
Once setup, start the foreground service prior to using screenshare.
298+
From version 2.4.0 onwards, this is handled internally and no extra setup is required.
321299

322300
### iOS
323301

@@ -362,6 +340,50 @@ return (
362340

363341
You will not be able to publish camera or microphone tracks on iOS Simulator.
364342

343+
## Background Processing
344+
345+
### Android
346+
347+
To support staying connected to LiveKit in the background, you will need a foreground service on Android.
348+
349+
The example app uses [@supersami/rn-foreground-service](https://github.com/Raja0sama/rn-foreground-service) for this.
350+
351+
Add the following permissions to your `AndroidManifest.xml` file:
352+
353+
```xml
354+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
355+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
356+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
357+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
358+
```
359+
360+
Declare the the service and ensure it's labelled a `mediaProjection` service like so:
361+
362+
```xml
363+
<service android:name="com.supersami.foregroundservice.ForegroundService" android:foregroundServiceType="camera|microphone|mediaPlayback" />
364+
<service android:name="com.supersami.foregroundservice.ForegroundServiceTask" />
365+
```
366+
367+
The camera and microphone permissions/foreground service types can be omitted if you are not using those.
368+
369+
Once setup, [start the foreground service](https://github.com/livekit/client-sdk-react-native/blob/main/example/src/callservice/CallService.android.ts) to keep the app alive in the background.
370+
371+
### iOS
372+
373+
By default, simple background processing can be enabled by selecting the `audio` and `voip`
374+
[UIBackgroundModes](https://developer.apple.com/documentation/bundleresources/information_property_list/uibackgroundmodes)
375+
in your XCode project. In your project, select your app target -> Signing & Capabilities -> Add Capability -> Background Modes.
376+
377+
These background modes will keep the app alive in the background as long as a mic or audio track is playing.
378+
379+
For a more robust background that isn't sensitive to the above conditions, we suggest using
380+
[CallKit](https://developer.apple.com/documentation/callkit/) to maintain the
381+
connection while in the background. The example uses
382+
[react-native-callkeep](https://github.com/react-native-webrtc/react-native-callkeep)
383+
for simple integration with CallKit.
384+
385+
Our example code can be found [here](https://github.com/livekit/client-sdk-react-native/blob/main/example/src/callservice/CallService.android.ts).
386+
365387
## Troubleshooting
366388

367389
#### Cannot read properties of undefined (reading 'split')

example/android/app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
1010
<uses-permission android:name="android.permission.WAKE_LOCK" />
1111
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
12+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
13+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
1214
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
1315
<application
1416
android:name=".MainApplication"
@@ -39,7 +41,7 @@
3941
android:value=""
4042
/>
4143
<service android:name="com.supersami.foregroundservice.ForegroundService"
42-
android:foregroundServiceType="mediaPlayback" />
44+
android:foregroundServiceType="camera|microphone|mediaPlayback" />
4345
<service android:name="com.supersami.foregroundservice.ForegroundServiceTask" />
4446
<service android:name="com.voximplant.foregroundservice.VIForegroundService" />
4547
</application>

0 commit comments

Comments
 (0)