Skip to content

Commit

Permalink
feat: allow users to use screensharing without manual setup (#166)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
davidliu authored Aug 5, 2024
1 parent ae5840d commit ef9b901
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ Enabling screenshare requires extra installation steps:

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

From 2.4.0 onwards, this is handled internally and no extra setup is required.

---

On versions prior to 2.4.0, you must declare your own foreground service.

The example app uses [@supersami/rn-foreground-service](https://github.com/Raja0sama/rn-foreground-service) for this.

Add the following permissions to your `AndroidManifest.xml` file:
Expand Down
2 changes: 2 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ object LiveKitReactNative {
*/
@JvmStatic
@JvmOverloads
fun setup(context: Context, audioType: AudioType = AudioType.CommunicationAudioType()) {
fun setup(
context: Context,
audioType: AudioType = AudioType.CommunicationAudioType()
) {
val options = WebRTCModuleOptions.getInstance()
options.videoEncoderFactory = CustomVideoEncoderFactory(null, true, true)
options.videoDecoderFactory = CustomVideoDecoderFactory()
options.enableMediaProjectionService = true

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

Expand Down
5 changes: 2 additions & 3 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
Expand Down Expand Up @@ -40,7 +39,7 @@
android:value=""
/>
<service android:name="com.supersami.foregroundservice.ForegroundService"
android:foregroundServiceType="mediaProjection" />
android:foregroundServiceType="mediaPlayback" />
<service android:name="com.supersami.foregroundservice.ForegroundServiceTask" />
<service android:name="com.voximplant.foregroundservice.VIForegroundService" />
</application>
Expand Down

0 comments on commit ef9b901

Please sign in to comment.