react-native-webrtc 118.0.1 → 118.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,14 @@
2
2
  package="com.oney.WebRTCModule"
3
3
  xmlns:tools="http://schemas.android.com/tools"
4
4
  >
5
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
6
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
7
+ <application>
8
+ <service
9
+ android:name=".MediaProjectionService"
10
+ android:foregroundServiceType="mediaProjection">
11
+ </service>
12
+ </application>
5
13
  <uses-feature
6
14
  android:name="android.hardware.usb.host"
7
15
  android:required="false"
@@ -95,7 +95,11 @@ class GetUserMediaImpl {
95
95
  }
96
96
 
97
97
  mediaProjectionPermissionResultData = data;
98
- createScreenStream();
98
+
99
+ ThreadUtils.runOnExecutor(() -> {
100
+ MediaProjectionService.launch(activity);
101
+ createScreenStream();
102
+ });
99
103
  }
100
104
  }
101
105
  });
@@ -0,0 +1,78 @@
1
+ package com.oney.WebRTCModule;
2
+
3
+ import android.app.Notification;
4
+ import android.app.Service;
5
+ import android.content.Context;
6
+
7
+ import androidx.core.app.NotificationCompat;
8
+
9
+ import android.app.NotificationChannel;
10
+ import android.app.NotificationManager;
11
+
12
+ import android.os.Build;
13
+
14
+ import android.util.Log;
15
+
16
+
17
+ /**
18
+ * Helper class for creating the media projection notification which is used with
19
+ * {@link MediaProjectionService}.
20
+ */
21
+ class MediaProjectionNotification {
22
+ private static final String TAG = MediaProjectionNotification.class.getSimpleName();
23
+
24
+ static final String ONGOING_CONFERENCE_CHANNEL_ID = "OngoingConferenceChannel";
25
+
26
+
27
+ static void createNotificationChannel(Context context) {
28
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
29
+ return;
30
+ }
31
+
32
+ if (context == null) {
33
+ Log.d(TAG, " Cannot create notification channel: no current context");
34
+ return;
35
+ }
36
+
37
+ NotificationManager notificationManager
38
+ = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
39
+
40
+ NotificationChannel channel
41
+ = notificationManager.getNotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID);
42
+
43
+ if (channel != null) {
44
+ // The channel was already created, no need to do it again.
45
+ return;
46
+ }
47
+
48
+ channel = new NotificationChannel(
49
+ ONGOING_CONFERENCE_CHANNEL_ID,
50
+ context.getString(R.string.ongoing_notification_channel_name),
51
+ NotificationManager.IMPORTANCE_DEFAULT
52
+ );
53
+ channel.enableLights(false);
54
+ channel.enableVibration(false);
55
+ channel.setShowBadge(false);
56
+
57
+ notificationManager.createNotificationChannel(channel);
58
+ }
59
+
60
+ static Notification buildMediaProjectionNotification(Context context) {
61
+ NotificationCompat.Builder builder = new NotificationCompat.Builder(context, ONGOING_CONFERENCE_CHANNEL_ID);
62
+
63
+ builder
64
+ .setCategory(NotificationCompat.CATEGORY_CALL)
65
+ .setContentTitle(context.getString(R.string.media_projection_notification_title))
66
+ .setContentText(context.getString(R.string.media_projection_notification_text))
67
+ .setPriority(NotificationCompat.PRIORITY_LOW)
68
+ .setOngoing(false)
69
+ .setUsesChronometer(false)
70
+ .setAutoCancel(true)
71
+ .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
72
+ .setOnlyAlertOnce(true)
73
+ .setSmallIcon(context.getResources().getIdentifier("ic_notification", "drawable", context.getPackageName()))
74
+ .setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE);
75
+
76
+ return builder.build();
77
+ }
78
+ }
@@ -0,0 +1,84 @@
1
+ package com.oney.WebRTCModule;
2
+
3
+ import android.app.Notification;
4
+ import android.app.Service;
5
+ import android.content.ComponentName;
6
+ import android.content.Context;
7
+ import android.content.Intent;
8
+ import android.content.pm.ServiceInfo;
9
+ import android.os.Build;
10
+ import android.os.IBinder;
11
+ import android.util.Log;
12
+
13
+ import java.util.Random;
14
+
15
+
16
+ /**
17
+ * This class implements an Android {@link Service}, a foreground one specifically, and it's
18
+ * responsible for presenting an ongoing notification when a conference is in progress.
19
+ * The service will help keep the app running while in the background.
20
+ *
21
+ * See: https://developer.android.com/guide/components/services
22
+ */
23
+ public class MediaProjectionService extends Service {
24
+ private static final String TAG = MediaProjectionService.class.getSimpleName();
25
+
26
+ static final int NOTIFICATION_ID = new Random().nextInt(99999) + 10000;
27
+
28
+ public static void launch(Context context) {
29
+ if (!WebRTCModuleOptions.getInstance().enableMediaProjectionService) {
30
+ return;
31
+ }
32
+
33
+ MediaProjectionNotification.createNotificationChannel(context);
34
+ Intent intent = new Intent(context, MediaProjectionService.class);
35
+ ComponentName componentName;
36
+
37
+ try {
38
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
39
+ componentName = context.startForegroundService(intent);
40
+ } else {
41
+ componentName = context.startService(intent);
42
+ }
43
+ } catch (RuntimeException e) {
44
+ // Avoid crashing due to ForegroundServiceStartNotAllowedException (API level 31).
45
+ // See: https://developer.android.com/guide/components/foreground-services#background-start-restrictions
46
+ Log.w(TAG, "Media projection service not started", e);
47
+ return;
48
+ }
49
+
50
+ if (componentName == null) {
51
+ Log.w(TAG, "Media projection service not started");
52
+ } else {
53
+ Log.i(TAG, "Media projection service started");
54
+ }
55
+ }
56
+
57
+ public static void abort(Context context) {
58
+ if (!WebRTCModuleOptions.getInstance().enableMediaProjectionService) {
59
+ return;
60
+ }
61
+
62
+ Intent intent = new Intent(context, MediaProjectionService.class);
63
+ context.stopService(intent);
64
+ }
65
+
66
+ @Override
67
+ public IBinder onBind(Intent intent) {
68
+ return null;
69
+ }
70
+
71
+ @Override
72
+ public int onStartCommand(Intent intent, int flags, int startId) {
73
+
74
+ Notification notification = MediaProjectionNotification.buildMediaProjectionNotification(this);
75
+
76
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
77
+ startForeground(NOTIFICATION_ID, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION);
78
+ } else {
79
+ startForeground(NOTIFICATION_ID, notification);
80
+ }
81
+
82
+ return START_NOT_STICKY;
83
+ }
84
+ }
@@ -23,11 +23,18 @@ public class ScreenCaptureController extends AbstractVideoCaptureController {
23
23
 
24
24
  private final OrientationEventListener orientationListener;
25
25
 
26
- public ScreenCaptureController(Context context, int width, int height, Intent mediaProjectionPermissionResultData) {
26
+ private final Context context;
27
+
28
+ public ScreenCaptureController(Context context,
29
+ int width,
30
+ int height,
31
+ Intent mediaProjectionPermissionResultData) {
27
32
  super(width, height, DEFAULT_FPS);
28
33
 
29
34
  this.mediaProjectionPermissionResultData = mediaProjectionPermissionResultData;
30
35
 
36
+ this.context = context;
37
+
31
38
  this.orientationListener = new OrientationEventListener(context) {
32
39
  @Override
33
40
  public void onOrientationChanged(int orientation) {
@@ -53,6 +60,12 @@ public class ScreenCaptureController extends AbstractVideoCaptureController {
53
60
  }
54
61
  }
55
62
 
63
+ @Override
64
+ public void dispose() {
65
+ MediaProjectionService.abort(context);
66
+ super.dispose();
67
+ }
68
+
56
69
  @Override
57
70
  protected VideoCapturer createVideoCapturer() {
58
71
  VideoCapturer videoCapturer =
@@ -15,6 +15,7 @@ public class WebRTCModuleOptions {
15
15
  public Loggable injectableLogger;
16
16
  public Logging.Severity loggingSeverity;
17
17
  public String fieldTrials;
18
+ public boolean enableMediaProjectionService;
18
19
 
19
20
  public static WebRTCModuleOptions getInstance() {
20
21
  if (instance == null) {
@@ -0,0 +1,5 @@
1
+ <resources>
2
+ <string name="media_projection_notification_title">Screen sharing</string>
3
+ <string name="media_projection_notification_text">You are currently sharing your screen.</string>
4
+ <string name="ongoing_notification_channel_name">Screen Sharing Notifications</string>
5
+ </resources>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-webrtc",
3
- "version": "118.0.1",
3
+ "version": "118.0.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/react-native-webrtc/react-native-webrtc.git"