Skip to content

Commit ef9b901

Browse files
authored
feat: allow users to use screensharing without manual setup (#166)
* feat: allow users to use screensharing without manual setup Note: This adds the FOREGROUND_SERVICE and FOREGROUND_SERVICE_MEDIA_PROJECTION permissions. * example: clean up unneeded media projection permission * docs: update android screenshare instructions
1 parent ae5840d commit ef9b901

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,12 @@ 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+
298304
The example app uses [@supersami/rn-foreground-service](https://github.com/Raja0sama/rn-foreground-service) for this.
299305

300306
Add the following permissions to your `AndroidManifest.xml` file:

android/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
<uses-permission android:name="android.permission.WAKE_LOCK" />
1111
<uses-permission android:name="android.permission.BLUETOOTH" />
1212
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
13+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
14+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
1315
</manifest>

android/src/main/java/com/livekit/reactnative/LiveKitReactNative.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,14 @@ object LiveKitReactNative {
3030
*/
3131
@JvmStatic
3232
@JvmOverloads
33-
fun setup(context: Context, audioType: AudioType = AudioType.CommunicationAudioType()) {
33+
fun setup(
34+
context: Context,
35+
audioType: AudioType = AudioType.CommunicationAudioType()
36+
) {
3437
val options = WebRTCModuleOptions.getInstance()
3538
options.videoEncoderFactory = CustomVideoEncoderFactory(null, true, true)
3639
options.videoDecoderFactory = CustomVideoDecoderFactory()
40+
options.enableMediaProjectionService = true
3741

3842
val useHardwareAudioProcessing = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
3943

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
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_MEDIA_PROJECTION" />
13-
12+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
1413
<application
1514
android:name=".MainApplication"
1615
android:label="@string/app_name"
@@ -40,7 +39,7 @@
4039
android:value=""
4140
/>
4241
<service android:name="com.supersami.foregroundservice.ForegroundService"
43-
android:foregroundServiceType="mediaProjection" />
42+
android:foregroundServiceType="mediaPlayback" />
4443
<service android:name="com.supersami.foregroundservice.ForegroundServiceTask" />
4544
<service android:name="com.voximplant.foregroundservice.VIForegroundService" />
4645
</application>

0 commit comments

Comments
 (0)