react-native-webrtc 124.0.4 → 124.0.6

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.
Files changed (104) hide show
  1. package/.nvmrc +1 -0
  2. package/android/build.gradle +3 -2
  3. package/android/consumer-rules.pro +2 -0
  4. package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +30 -3
  5. package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +180 -73
  6. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +53 -24
  7. package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionNotification.java +11 -19
  8. package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionService.java +0 -2
  9. package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +4 -2
  10. package/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +25 -0
  11. package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +6 -4
  12. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +20 -14
  13. package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +37 -0
  14. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +15 -9
  15. package/android/src/main/java/org/webrtc/Camera1Helper.java +0 -1
  16. package/android/src/main/java/org/webrtc/Camera2Helper.java +4 -3
  17. package/ios/RCTWebRTC/CaptureController.h +3 -0
  18. package/ios/RCTWebRTC/CaptureController.m +12 -0
  19. package/ios/RCTWebRTC/I420Converter.h +22 -0
  20. package/ios/RCTWebRTC/I420Converter.m +164 -0
  21. package/ios/RCTWebRTC/PIPController.h +24 -0
  22. package/ios/RCTWebRTC/PIPController.m +234 -0
  23. package/ios/RCTWebRTC/RTCVideoViewManager.h +23 -0
  24. package/ios/RCTWebRTC/RTCVideoViewManager.m +131 -28
  25. package/ios/RCTWebRTC/SampleBufferVideoCallView.h +12 -0
  26. package/ios/RCTWebRTC/SampleBufferVideoCallView.m +178 -0
  27. package/ios/RCTWebRTC/ScreenCaptureController.m +4 -0
  28. package/ios/RCTWebRTC/VideoCaptureController.h +3 -0
  29. package/ios/RCTWebRTC/VideoCaptureController.m +95 -30
  30. package/ios/RCTWebRTC/WebRTCModule+Permissions.m +4 -8
  31. package/ios/RCTWebRTC/WebRTCModule+RTCAudioSession.m +20 -0
  32. package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +31 -40
  33. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +5 -0
  34. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +93 -28
  35. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +26 -55
  36. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +11 -28
  37. package/ios/RCTWebRTC/WebRTCModuleOptions.h +1 -0
  38. package/ios/RCTWebRTC/videoEffects/ProcessorProvider.h +9 -0
  39. package/ios/RCTWebRTC/videoEffects/ProcessorProvider.m +23 -0
  40. package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.h +13 -0
  41. package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.m +23 -0
  42. package/ios/RCTWebRTC/videoEffects/VideoFrameProcessor.h +8 -0
  43. package/ios/RCTWebRTC.xcodeproj/project.pbxproj +4 -0
  44. package/lib/commonjs/Constraints.js +2 -0
  45. package/lib/commonjs/Constraints.js.map +1 -0
  46. package/lib/commonjs/MediaDevices.js.map +1 -1
  47. package/lib/commonjs/MediaStreamTrack.js +31 -5
  48. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  49. package/lib/commonjs/RTCAudioSession.js +33 -0
  50. package/lib/commonjs/RTCAudioSession.js.map +1 -0
  51. package/lib/commonjs/RTCPIPView.js +38 -0
  52. package/lib/commonjs/RTCPIPView.js.map +1 -0
  53. package/lib/commonjs/RTCPeerConnection.js +2 -4
  54. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  55. package/lib/commonjs/RTCUtil.js +2 -3
  56. package/lib/commonjs/RTCUtil.js.map +1 -1
  57. package/lib/commonjs/RTCView.js.map +1 -1
  58. package/lib/commonjs/getUserMedia.js.map +1 -1
  59. package/lib/commonjs/index.js +28 -0
  60. package/lib/commonjs/index.js.map +1 -1
  61. package/lib/module/Constraints.js +2 -0
  62. package/lib/module/Constraints.js.map +1 -0
  63. package/lib/module/MediaDevices.js.map +1 -1
  64. package/lib/module/MediaStreamTrack.js +32 -6
  65. package/lib/module/MediaStreamTrack.js.map +1 -1
  66. package/lib/module/RTCAudioSession.js +26 -0
  67. package/lib/module/RTCAudioSession.js.map +1 -0
  68. package/lib/module/RTCPIPView.js +26 -0
  69. package/lib/module/RTCPIPView.js.map +1 -0
  70. package/lib/module/RTCPeerConnection.js +2 -4
  71. package/lib/module/RTCPeerConnection.js.map +1 -1
  72. package/lib/module/RTCUtil.js +2 -3
  73. package/lib/module/RTCUtil.js.map +1 -1
  74. package/lib/module/RTCView.js.map +1 -1
  75. package/lib/module/getUserMedia.js.map +1 -1
  76. package/lib/module/index.js +3 -1
  77. package/lib/module/index.js.map +1 -1
  78. package/lib/typescript/Constraints.d.ts +19 -0
  79. package/lib/typescript/MediaDevices.d.ts +2 -1
  80. package/lib/typescript/MediaStreamTrack.d.ts +27 -5
  81. package/lib/typescript/RTCAudioSession.d.ts +10 -0
  82. package/lib/typescript/RTCPIPView.d.ts +15 -0
  83. package/lib/typescript/RTCPeerConnection.d.ts +2 -1
  84. package/lib/typescript/RTCUtil.d.ts +7 -1
  85. package/lib/typescript/RTCView.d.ts +58 -1
  86. package/lib/typescript/getUserMedia.d.ts +4 -4
  87. package/lib/typescript/index.d.ts +5 -3
  88. package/package.json +2 -1
  89. package/src/.eslintrc.cjs +1 -1
  90. package/src/Constraints.ts +21 -0
  91. package/src/MediaDevices.ts +2 -2
  92. package/src/MediaStreamTrack.ts +47 -9
  93. package/src/RTCAudioSession.ts +25 -0
  94. package/src/RTCPIPView.tsx +47 -0
  95. package/src/RTCPeerConnection.ts +4 -5
  96. package/src/RTCUtil.ts +10 -3
  97. package/src/RTCView.ts +60 -2
  98. package/src/getUserMedia.ts +4 -3
  99. package/src/index.ts +12 -3
  100. package/tools/release.sh +1 -1
  101. package/tsconfig.json +3 -1
  102. package/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  103. package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  104. package/tools/build-webrtc.py +0 -344
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 22
@@ -14,10 +14,11 @@ android {
14
14
  buildToolsVersion safeExtGet('buildToolsVersion', "23.0.1")
15
15
 
16
16
  defaultConfig {
17
- minSdkVersion safeExtGet('minSdkVersion', 24)
17
+ minSdkVersion 24
18
18
  targetSdkVersion safeExtGet('targetSdkVersion', 24)
19
19
  versionCode 1
20
20
  versionName "1.0"
21
+ consumerProguardFiles 'consumer-rules.pro'
21
22
  }
22
23
 
23
24
  // WebRTC requires Java 8 features
@@ -29,7 +30,7 @@ android {
29
30
  }
30
31
 
31
32
  dependencies {
32
- implementation 'com.facebook.react:react-native:+'
33
+ implementation "com.facebook.react:react-android:+"
33
34
  api 'org.jitsi:webrtc:124.+'
34
35
  implementation "androidx.core:core:1.7.0"
35
36
  }
@@ -0,0 +1,2 @@
1
+ # WebRTC
2
+ -keep class org.webrtc.** { *; }
@@ -1,11 +1,18 @@
1
1
  package com.oney.WebRTCModule;
2
2
 
3
+ import androidx.annotation.Nullable;
4
+ import androidx.core.util.Consumer;
5
+
6
+ import com.facebook.react.bridge.Arguments;
7
+ import com.facebook.react.bridge.ReadableMap;
8
+ import com.facebook.react.bridge.WritableMap;
9
+
3
10
  import org.webrtc.VideoCapturer;
4
11
 
5
12
  public abstract class AbstractVideoCaptureController {
6
- protected final int targetWidth;
7
- protected final int targetHeight;
8
- protected final int targetFps;
13
+ protected int targetWidth;
14
+ protected int targetHeight;
15
+ protected int targetFps;
9
16
 
10
17
  protected int actualWidth;
11
18
  protected int actualHeight;
@@ -31,6 +38,9 @@ public abstract class AbstractVideoCaptureController {
31
38
  videoCapturer = createVideoCapturer();
32
39
  }
33
40
 
41
+ @Nullable
42
+ public abstract String getDeviceId();
43
+
34
44
  public void dispose() {
35
45
  if (videoCapturer != null) {
36
46
  videoCapturer.dispose();
@@ -50,6 +60,16 @@ public abstract class AbstractVideoCaptureController {
50
60
  return actualFps;
51
61
  }
52
62
 
63
+ public WritableMap getSettings() {
64
+ WritableMap settings = Arguments.createMap();
65
+ settings.putString("deviceId", getDeviceId());
66
+ settings.putString("groupId", "");
67
+ settings.putInt("height", getHeight());
68
+ settings.putInt("width", getWidth());
69
+ settings.putInt("frameRate", getFrameRate());
70
+ return settings;
71
+ }
72
+
53
73
  public VideoCapturer getVideoCapturer() {
54
74
  return videoCapturer;
55
75
  }
@@ -73,6 +93,13 @@ public abstract class AbstractVideoCaptureController {
73
93
  }
74
94
  }
75
95
 
96
+ public void applyConstraints(ReadableMap constraints, @Nullable Consumer<Exception> onFinishedCallback) {
97
+ if (onFinishedCallback != null) {
98
+ onFinishedCallback.accept(
99
+ new UnsupportedOperationException("This video track does not support applyConstraints."));
100
+ }
101
+ }
102
+
76
103
  public void setCapturerEventsListener(CapturerEventsListener listener) {
77
104
  this.capturerEventsListener = listener;
78
105
  }
@@ -4,9 +4,12 @@ import android.content.Context;
4
4
  import android.hardware.camera2.CameraManager;
5
5
  import android.util.Log;
6
6
  import android.util.Pair;
7
+
7
8
  import androidx.annotation.Nullable;
9
+ import androidx.core.util.Consumer;
8
10
 
9
11
  import com.facebook.react.bridge.ReadableMap;
12
+ import com.facebook.react.bridge.WritableMap;
10
13
 
11
14
  import org.webrtc.Camera1Capturer;
12
15
  import org.webrtc.Camera1Helper;
@@ -19,6 +22,7 @@ import org.webrtc.VideoCapturer;
19
22
 
20
23
  import java.util.ArrayList;
21
24
  import java.util.List;
25
+ import java.util.Objects;
22
26
 
23
27
  public class CameraCaptureController extends AbstractVideoCaptureController {
24
28
  /**
@@ -28,17 +32,29 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
28
32
 
29
33
  private boolean isFrontFacing;
30
34
 
35
+ /**
36
+ * Equivalent to the camera index as a String
37
+ */
38
+ @Nullable
39
+ private String currentDeviceId;
40
+
31
41
  private final Context context;
32
42
  private final CameraEnumerator cameraEnumerator;
33
- private final ReadableMap constraints;
43
+ private ReadableMap constraints;
34
44
 
35
45
  /**
36
46
  * The {@link CameraEventsHandler} used with
37
- * {@link CameraEnumerator#createCapturer}. Cached because the
38
- * implementation does not do anything but logging unspecific to the camera
39
- * device's name anyway.
47
+ * {@link CameraEnumerator#createCapturer}.
40
48
  */
41
- private final CameraEventsHandler cameraEventsHandler = new CameraEventsHandler();
49
+ private final CameraEventsHandler cameraEventsHandler = new CameraEventsHandler() {
50
+ @Override
51
+ public void onCameraOpening(String cameraName) {
52
+ super.onCameraOpening(cameraName);
53
+ int cameraIndex = findCameraIndex(cameraName);
54
+ updateActualSize(cameraIndex, cameraName, videoCapturer);
55
+ CameraCaptureController.this.currentDeviceId = cameraIndex == -1 ? null : String.valueOf(cameraIndex);
56
+ }
57
+ };
42
58
 
43
59
  public CameraCaptureController(Context context, CameraEnumerator cameraEnumerator, ReadableMap constraints) {
44
60
  super(constraints.getInt("width"), constraints.getInt("height"), constraints.getInt("frameRate"));
@@ -48,36 +64,135 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
48
64
  this.constraints = constraints;
49
65
  }
50
66
 
51
- public void switchCamera() {
52
- if (videoCapturer instanceof CameraVideoCapturer) {
53
- CameraVideoCapturer capturer = (CameraVideoCapturer) videoCapturer;
54
- String[] deviceNames = cameraEnumerator.getDeviceNames();
55
- int deviceCount = deviceNames.length;
67
+ @Nullable
68
+ @Override
69
+ public String getDeviceId() {
70
+ return currentDeviceId;
71
+ }
56
72
 
57
- // Nothing to switch to.
58
- if (deviceCount < 2) {
59
- return;
73
+ private int findCameraIndex(String cameraName) {
74
+ String[] deviceNames = cameraEnumerator.getDeviceNames();
75
+ for (int i = 0; i < deviceNames.length; i++) {
76
+ if (Objects.equals(deviceNames[i], cameraName)) {
77
+ return i;
60
78
  }
79
+ }
80
+ return -1;
81
+ }
61
82
 
62
- // The usual case.
63
- if (deviceCount == 2) {
64
- capturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() {
65
- @Override
66
- public void onCameraSwitchDone(boolean b) {
67
- isFrontFacing = b;
68
- }
83
+ @Override
84
+ public WritableMap getSettings() {
85
+ WritableMap settings = super.getSettings();
86
+ settings.putString("facingMode", isFrontFacing ? "user" : "environment");
87
+ return settings;
88
+ }
69
89
 
70
- @Override
71
- public void onCameraSwitchError(String s) {
72
- Log.e(TAG, "Error switching camera: " + s);
73
- }
74
- });
75
- return;
90
+ @Override
91
+ public void applyConstraints(ReadableMap constraints, @Nullable Consumer<Exception> onFinishedCallback) {
92
+ ReadableMap oldConstraints = this.constraints;
93
+ int oldTargetWidth = this.targetWidth;
94
+ int oldTargetHeight = this.targetHeight;
95
+ int oldTargetFps = this.targetFps;
96
+
97
+ // Don't save constraints yet, since we may fail to find a fit.
98
+ Runnable saveConstraints = () -> {
99
+ this.constraints = constraints;
100
+ this.targetWidth = constraints.getInt("width");
101
+ this.targetHeight = constraints.getInt("height");
102
+ this.targetFps = constraints.getInt("frameRate");
103
+ };
104
+
105
+ if (videoCapturer == null) {
106
+ // No existing capturer, just let it initialize normally.
107
+ saveConstraints.run();
108
+ if (onFinishedCallback != null) {
109
+ onFinishedCallback.accept(null);
76
110
  }
111
+ return;
112
+ }
77
113
 
78
- // If we are here the device has more than 2 cameras. Cycle through them
79
- // and switch to the first one of the desired facing mode.
80
- switchCamera(!isFrontFacing, deviceCount);
114
+ // Find target camera to switch to.
115
+ String[] deviceNames = cameraEnumerator.getDeviceNames();
116
+ final String deviceId = ReactBridgeUtil.getMapStrValue(constraints, "deviceId");
117
+ final String facingMode = ReactBridgeUtil.getMapStrValue(constraints, "facingMode");
118
+ int cameraIndex = -1;
119
+ String cameraName = null;
120
+
121
+ // If deviceId is specified, then it takes precedence over facingMode.
122
+ if (deviceId != null) {
123
+ try {
124
+ cameraIndex = Integer.parseInt(deviceId);
125
+ cameraName = deviceNames[cameraIndex];
126
+ } catch (Exception e) {
127
+ Log.d(TAG, "failed to find device with id: " + deviceId);
128
+ }
129
+ }
130
+
131
+ // Otherwise, use facingMode (defaulting to front/user facing).
132
+ if (cameraName == null) {
133
+ cameraIndex = -1;
134
+ final boolean isFrontFacing = facingMode == null || facingMode.equals("user");
135
+ for (String name : deviceNames) {
136
+ cameraIndex++;
137
+ if (cameraEnumerator.isFrontFacing(name) == isFrontFacing) {
138
+ cameraName = name;
139
+ break;
140
+ }
141
+ }
142
+ }
143
+
144
+ if (cameraName == null) {
145
+ if (onFinishedCallback != null) {
146
+ onFinishedCallback.accept(new Exception("OverconstrainedError: could not find camera with deviceId: "
147
+ + deviceId + " or facingMode: " + facingMode));
148
+ }
149
+ return;
150
+ }
151
+
152
+ // For lambda reference
153
+ final int finalCameraIndex = cameraIndex;
154
+ final String finalCameraName = cameraName;
155
+ boolean shouldSwitchCamera = false;
156
+ try {
157
+ int currentCameraIndex = Integer.parseInt(currentDeviceId);
158
+ shouldSwitchCamera = cameraIndex != currentCameraIndex;
159
+ } catch (Exception e) {
160
+ shouldSwitchCamera = true;
161
+ Log.d(TAG, "Forcing camera switch, couldn't parse current device id: " + currentDeviceId);
162
+ }
163
+
164
+ CameraVideoCapturer capturer = (CameraVideoCapturer) videoCapturer;
165
+ Runnable changeFormatIfNeededAndFinish = () -> {
166
+ saveConstraints.run();
167
+ if (targetWidth != oldTargetWidth || targetHeight != oldTargetHeight || targetFps != oldTargetFps) {
168
+ updateActualSize(finalCameraIndex, finalCameraName, videoCapturer);
169
+ capturer.changeCaptureFormat(targetWidth, targetHeight, targetFps);
170
+ }
171
+ if (onFinishedCallback != null) {
172
+ onFinishedCallback.accept(null);
173
+ }
174
+ };
175
+
176
+ if (shouldSwitchCamera) {
177
+ capturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() {
178
+ @Override
179
+ public void onCameraSwitchDone(boolean isFrontCamera) {
180
+ CameraCaptureController.this.isFrontFacing = isFrontCamera;
181
+ changeFormatIfNeededAndFinish.run();
182
+ }
183
+
184
+ @Override
185
+ public void onCameraSwitchError(String s) {
186
+ Exception e = new Exception("Error switching camera: " + s);
187
+ Log.e(TAG, "OnCameraSwitchError", e);
188
+ if (onFinishedCallback != null) {
189
+ onFinishedCallback.accept(e);
190
+ }
191
+ }
192
+ }, cameraName);
193
+ } else {
194
+ // No camera switch needed, just change format if needed.
195
+ changeFormatIfNeededAndFinish.run();
81
196
  }
82
197
  }
83
198
 
@@ -86,19 +201,21 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
86
201
  String deviceId = ReactBridgeUtil.getMapStrValue(this.constraints, "deviceId");
87
202
  String facingMode = ReactBridgeUtil.getMapStrValue(this.constraints, "facingMode");
88
203
 
89
- Pair<String, VideoCapturer> result = createVideoCapturer(deviceId, facingMode);
90
- if(result == null) {
204
+ CreateCapturerResult result = createVideoCapturer(deviceId, facingMode);
205
+ if (result == null) {
91
206
  return null;
92
207
  }
93
208
 
94
- String cameraName = result.first;
95
- VideoCapturer videoCapturer = result.second;
209
+ updateActualSize(result.cameraIndex, result.cameraName, result.videoCapturer);
96
210
 
211
+ return result.videoCapturer;
212
+ }
213
+
214
+ private void updateActualSize(int cameraIndex, String cameraName, VideoCapturer videoCapturer) {
97
215
  // Find actual capture format.
98
216
  Size actualSize = null;
99
217
  if (videoCapturer instanceof Camera1Capturer) {
100
- int cameraId = Camera1Helper.getCameraId(cameraName);
101
- actualSize = Camera1Helper.findClosestCaptureFormat(cameraId, targetWidth, targetHeight);
218
+ actualSize = Camera1Helper.findClosestCaptureFormat(cameraIndex, targetWidth, targetHeight);
102
219
  } else if (videoCapturer instanceof Camera2Capturer) {
103
220
  CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
104
221
  actualSize = Camera2Helper.findClosestCaptureFormat(cameraManager, cameraName, targetWidth, targetHeight);
@@ -108,37 +225,6 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
108
225
  actualWidth = actualSize.width;
109
226
  actualHeight = actualSize.height;
110
227
  }
111
-
112
- return videoCapturer;
113
- }
114
-
115
- /**
116
- * Helper function which tries to switch cameras until the desired facing mode is found.
117
- *
118
- * @param desiredFrontFacing - The desired front facing value.
119
- * @param tries - How many times to try switching.
120
- */
121
- private void switchCamera(boolean desiredFrontFacing, int tries) {
122
- CameraVideoCapturer capturer = (CameraVideoCapturer) videoCapturer;
123
-
124
- capturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() {
125
- @Override
126
- public void onCameraSwitchDone(boolean b) {
127
- if (b != desiredFrontFacing) {
128
- int newTries = tries - 1;
129
- if (newTries > 0) {
130
- switchCamera(desiredFrontFacing, newTries);
131
- }
132
- } else {
133
- isFrontFacing = desiredFrontFacing;
134
- }
135
- }
136
-
137
- @Override
138
- public void onCameraSwitchError(String s) {
139
- Log.e(TAG, "Error switching camera: " + s);
140
- }
141
- });
142
228
  }
143
229
 
144
230
  /**
@@ -155,14 +241,15 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
155
241
  * {@code deviceId} constraint, or null.
156
242
  */
157
243
  @Nullable
158
- private Pair<String, VideoCapturer> createVideoCapturer(String deviceId, String facingMode) {
244
+ private CreateCapturerResult createVideoCapturer(String deviceId, String facingMode) {
159
245
  String[] deviceNames = cameraEnumerator.getDeviceNames();
160
246
  List<String> failedDevices = new ArrayList<>();
161
247
 
162
248
  String cameraName = null;
249
+ int cameraIndex = -1;
163
250
  try {
164
- int index = Integer.parseInt(deviceId);
165
- cameraName = deviceNames[index];
251
+ cameraIndex = Integer.parseInt(deviceId);
252
+ cameraName = deviceNames[cameraIndex];
166
253
  } catch (Exception e) {
167
254
  Log.d(TAG, "failed to find device with id: " + deviceId);
168
255
  }
@@ -174,7 +261,8 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
174
261
  if (videoCapturer != null) {
175
262
  Log.d(TAG, message + " succeeded");
176
263
  this.isFrontFacing = cameraEnumerator.isFrontFacing(cameraName);
177
- return new Pair(cameraName, videoCapturer);
264
+ this.currentDeviceId = String.valueOf(cameraIndex);
265
+ return new CreateCapturerResult(cameraIndex, cameraName, videoCapturer);
178
266
  } else {
179
267
  // fallback to facingMode
180
268
  Log.d(TAG, message + " failed");
@@ -183,8 +271,10 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
183
271
  }
184
272
 
185
273
  // Otherwise, use facingMode (defaulting to front/user facing).
186
- final boolean isFrontFacing = facingMode == null || !facingMode.equals("environment");
274
+ final boolean isFrontFacing = facingMode == null || facingMode.equals("user");
275
+ cameraIndex = -1;
187
276
  for (String name : deviceNames) {
277
+ cameraIndex++;
188
278
  if (failedDevices.contains(name)) {
189
279
  continue;
190
280
  }
@@ -196,22 +286,26 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
196
286
  if (videoCapturer != null) {
197
287
  Log.d(TAG, message + " succeeded");
198
288
  this.isFrontFacing = cameraEnumerator.isFrontFacing(name);
199
- return new Pair(name, videoCapturer);
289
+ this.currentDeviceId = String.valueOf(cameraIndex);
290
+ return new CreateCapturerResult(cameraIndex, name, videoCapturer);
200
291
  } else {
201
292
  Log.d(TAG, message + " failed");
202
293
  failedDevices.add(name);
203
294
  }
204
295
  }
205
296
 
297
+ cameraIndex = -1;
206
298
  // Fallback to any available camera.
207
299
  for (String name : deviceNames) {
300
+ cameraIndex++;
208
301
  if (!failedDevices.contains(name)) {
209
302
  VideoCapturer videoCapturer = cameraEnumerator.createCapturer(name, cameraEventsHandler);
210
303
  String message = "Create fallback camera " + name;
211
304
  if (videoCapturer != null) {
212
305
  Log.d(TAG, message + " succeeded");
213
306
  this.isFrontFacing = cameraEnumerator.isFrontFacing(name);
214
- return new Pair(name, videoCapturer);
307
+ this.currentDeviceId = String.valueOf(cameraIndex);
308
+ return new CreateCapturerResult(cameraIndex, name, videoCapturer);
215
309
  } else {
216
310
  Log.d(TAG, message + " failed");
217
311
  failedDevices.add(name);
@@ -219,8 +313,21 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
219
313
  }
220
314
  }
221
315
 
316
+ currentDeviceId = null;
222
317
  Log.w(TAG, "Unable to identify a suitable camera.");
223
318
 
224
319
  return null;
225
320
  }
321
+
322
+ private static class CreateCapturerResult {
323
+ public final int cameraIndex;
324
+ public final String cameraName;
325
+ public final VideoCapturer videoCapturer;
326
+
327
+ public CreateCapturerResult(int cameraIndex, String cameraName, VideoCapturer videoCapturer) {
328
+ this.cameraIndex = cameraIndex;
329
+ this.cameraName = cameraName;
330
+ this.videoCapturer = videoCapturer;
331
+ }
332
+ }
226
333
  }
@@ -7,6 +7,8 @@ import android.media.projection.MediaProjectionManager;
7
7
  import android.util.DisplayMetrics;
8
8
  import android.util.Log;
9
9
 
10
+ import androidx.core.util.Consumer;
11
+
10
12
  import com.facebook.react.bridge.Arguments;
11
13
  import com.facebook.react.bridge.BaseActivityEventListener;
12
14
  import com.facebook.react.bridge.Callback;
@@ -25,8 +27,11 @@ import org.webrtc.*;
25
27
 
26
28
  import java.util.ArrayList;
27
29
  import java.util.HashMap;
30
+ import java.util.List;
28
31
  import java.util.Map;
32
+ import java.util.Objects;
29
33
  import java.util.UUID;
34
+ import java.util.stream.Collectors;
30
35
 
31
36
  /**
32
37
  * The implementation of {@code getUserMedia} extracted into a separate file in
@@ -191,8 +196,8 @@ class GetUserMediaImpl {
191
196
 
192
197
  Log.d(TAG, "getUserMedia(video): " + videoConstraintsMap);
193
198
 
194
- CameraCaptureController cameraCaptureController =
195
- new CameraCaptureController(reactContext.getCurrentActivity(), getCameraEnumerator(), videoConstraintsMap);
199
+ CameraCaptureController cameraCaptureController = new CameraCaptureController(
200
+ reactContext.getCurrentActivity(), getCameraEnumerator(), videoConstraintsMap);
196
201
 
197
202
  videoTrack = createVideoTrack(cameraCaptureController);
198
203
  }
@@ -233,11 +238,23 @@ class GetUserMediaImpl {
233
238
  }
234
239
  }
235
240
 
236
- void switchCamera(String trackId) {
241
+ void applyConstraints(String trackId, ReadableMap constraints, Promise promise) {
237
242
  TrackPrivate track = tracks.get(trackId);
238
- if (track != null && track.videoCaptureController instanceof CameraCaptureController) {
239
- CameraCaptureController cameraCaptureController = (CameraCaptureController) track.videoCaptureController;
240
- cameraCaptureController.switchCamera();
243
+ if (track != null && track.videoCaptureController instanceof AbstractVideoCaptureController) {
244
+ AbstractVideoCaptureController captureController =
245
+ (AbstractVideoCaptureController) track.videoCaptureController;
246
+ captureController.applyConstraints(constraints, new Consumer<Exception>() {
247
+ public void accept(Exception e) {
248
+ if (e != null) {
249
+ promise.reject(e);
250
+ return;
251
+ }
252
+
253
+ promise.resolve(captureController.getSettings());
254
+ }
255
+ });
256
+ } else {
257
+ promise.reject(new Exception("Camera track not found!"));
241
258
  }
242
259
  }
243
260
 
@@ -327,10 +344,13 @@ class GetUserMediaImpl {
327
344
  if (track instanceof VideoTrack) {
328
345
  TrackPrivate tp = this.tracks.get(trackId);
329
346
  AbstractVideoCaptureController vcc = tp.videoCaptureController;
347
+ trackInfo.putMap("settings", vcc.getSettings());
348
+ }
349
+
350
+ if (track instanceof AudioTrack) {
330
351
  WritableMap settings = Arguments.createMap();
331
- settings.putInt("height", vcc.getHeight());
332
- settings.putInt("width", vcc.getWidth());
333
- settings.putInt("frameRate", vcc.getFrameRate());
352
+ settings.putString("deviceId", "audio-1");
353
+ settings.putString("groupId", "");
334
354
  trackInfo.putMap("settings", settings);
335
355
  }
336
356
 
@@ -388,28 +408,35 @@ class GetUserMediaImpl {
388
408
  }
389
409
 
390
410
  /**
391
- * Set video effect to the TrackPrivate corresponding to the trackId with the help of VideoEffectProcessor
392
- * corresponding to the name.
411
+ * Set video effects to the TrackPrivate corresponding to the trackId with the help of VideoEffectProcessor
412
+ * corresponding to the names.
393
413
  * @param trackId TrackPrivate id
394
- * @param name VideoEffectProcessor name
414
+ * @param names VideoEffectProcessor names
395
415
  */
396
- void setVideoEffect(String trackId, String name) {
416
+ void setVideoEffects(String trackId, ReadableArray names) {
397
417
  TrackPrivate track = tracks.get(trackId);
398
418
 
399
419
  if (track != null && track.videoCaptureController instanceof CameraCaptureController) {
400
420
  VideoSource videoSource = (VideoSource) track.mediaSource;
401
421
  SurfaceTextureHelper surfaceTextureHelper = track.surfaceTextureHelper;
402
422
 
403
- if (name != null) {
404
- VideoFrameProcessor videoFrameProcessor = ProcessorProvider.getProcessor(name);
405
-
406
- if (videoFrameProcessor == null) {
407
- Log.e(TAG, "no videoFrameProcessor associated with this name");
408
- return;
409
- }
410
-
411
- VideoEffectProcessor videoEffectProcessor =
412
- new VideoEffectProcessor(videoFrameProcessor, surfaceTextureHelper);
423
+ if (names != null) {
424
+ List<VideoFrameProcessor> processors =
425
+ names.toArrayList()
426
+ .stream()
427
+ .filter(name -> name instanceof String)
428
+ .map(name -> {
429
+ VideoFrameProcessor videoFrameProcessor =
430
+ ProcessorProvider.getProcessor((String) name);
431
+ if (videoFrameProcessor == null) {
432
+ Log.e(TAG, "no videoFrameProcessor associated with this name: " + name);
433
+ }
434
+ return videoFrameProcessor;
435
+ })
436
+ .filter(Objects::nonNull)
437
+ .collect(Collectors.toList());
438
+
439
+ VideoEffectProcessor videoEffectProcessor = new VideoEffectProcessor(processors, surfaceTextureHelper);
413
440
  videoSource.setVideoProcessor(videoEffectProcessor);
414
441
 
415
442
  } else {
@@ -488,5 +515,7 @@ class GetUserMediaImpl {
488
515
  }
489
516
  }
490
517
 
491
- public interface BiConsumer<T, U> { void accept(T t, U u); }
518
+ public interface BiConsumer<T, U> {
519
+ void accept(T t, U u);
520
+ }
492
521
  }
@@ -1,18 +1,14 @@
1
1
  package com.oney.WebRTCModule;
2
2
 
3
3
  import android.app.Notification;
4
- import android.app.Service;
5
- import android.content.Context;
6
-
7
- import androidx.core.app.NotificationCompat;
8
-
9
4
  import android.app.NotificationChannel;
10
5
  import android.app.NotificationManager;
11
-
6
+ import android.app.Service;
7
+ import android.content.Context;
12
8
  import android.os.Build;
13
-
14
9
  import android.util.Log;
15
10
 
11
+ import androidx.core.app.NotificationCompat;
16
12
 
17
13
  /**
18
14
  * Helper class for creating the media projection notification which is used with
@@ -23,7 +19,6 @@ class MediaProjectionNotification {
23
19
 
24
20
  static final String ONGOING_CONFERENCE_CHANNEL_ID = "OngoingConferenceChannel";
25
21
 
26
-
27
22
  static void createNotificationChannel(Context context) {
28
23
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
29
24
  return;
@@ -34,22 +29,19 @@ class MediaProjectionNotification {
34
29
  return;
35
30
  }
36
31
 
37
- NotificationManager notificationManager
38
- = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
32
+ NotificationManager notificationManager =
33
+ (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
39
34
 
40
- NotificationChannel channel
41
- = notificationManager.getNotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID);
35
+ NotificationChannel channel = notificationManager.getNotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID);
42
36
 
43
37
  if (channel != null) {
44
38
  // The channel was already created, no need to do it again.
45
39
  return;
46
40
  }
47
41
 
48
- channel = new NotificationChannel(
49
- ONGOING_CONFERENCE_CHANNEL_ID,
42
+ channel = new NotificationChannel(ONGOING_CONFERENCE_CHANNEL_ID,
50
43
  context.getString(R.string.ongoing_notification_channel_name),
51
- NotificationManager.IMPORTANCE_DEFAULT
52
- );
44
+ NotificationManager.IMPORTANCE_DEFAULT);
53
45
  channel.enableLights(false);
54
46
  channel.enableVibration(false);
55
47
  channel.setShowBadge(false);
@@ -60,8 +52,7 @@ class MediaProjectionNotification {
60
52
  static Notification buildMediaProjectionNotification(Context context) {
61
53
  NotificationCompat.Builder builder = new NotificationCompat.Builder(context, ONGOING_CONFERENCE_CHANNEL_ID);
62
54
 
63
- builder
64
- .setCategory(NotificationCompat.CATEGORY_CALL)
55
+ builder.setCategory(NotificationCompat.CATEGORY_CALL)
65
56
  .setContentTitle(context.getString(R.string.media_projection_notification_title))
66
57
  .setContentText(context.getString(R.string.media_projection_notification_text))
67
58
  .setPriority(NotificationCompat.PRIORITY_LOW)
@@ -70,7 +61,8 @@ class MediaProjectionNotification {
70
61
  .setAutoCancel(true)
71
62
  .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
72
63
  .setOnlyAlertOnce(true)
73
- .setSmallIcon(context.getResources().getIdentifier("ic_notification", "drawable", context.getPackageName()))
64
+ .setSmallIcon(
65
+ context.getResources().getIdentifier("ic_notification", "drawable", context.getPackageName()))
74
66
  .setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE);
75
67
 
76
68
  return builder.build();