react-native-webrtc 124.0.4 → 124.0.5
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.
- package/android/build.gradle +2 -1
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +29 -3
- package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +181 -72
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +22 -7
- package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +5 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +4 -2
- package/ios/RCTWebRTC/CaptureController.h +3 -0
- package/ios/RCTWebRTC/CaptureController.m +13 -0
- package/ios/RCTWebRTC/I420Converter.h +21 -0
- package/ios/RCTWebRTC/I420Converter.m +156 -0
- package/ios/RCTWebRTC/PIPController.h +24 -0
- package/ios/RCTWebRTC/PIPController.m +242 -0
- package/ios/RCTWebRTC/RTCVideoViewManager.h +23 -0
- package/ios/RCTWebRTC/RTCVideoViewManager.m +105 -23
- package/ios/RCTWebRTC/SampleBufferVideoCallView.h +12 -0
- package/ios/RCTWebRTC/SampleBufferVideoCallView.m +180 -0
- package/ios/RCTWebRTC/ScreenCaptureController.m +8 -0
- package/ios/RCTWebRTC/VideoCaptureController.h +2 -0
- package/ios/RCTWebRTC/VideoCaptureController.m +96 -30
- package/ios/RCTWebRTC/WebRTCModule+RTCAudioSession.m +20 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +40 -14
- package/ios/RCTWebRTC/WebRTCModuleOptions.h +1 -0
- package/ios/RCTWebRTC.xcodeproj/project.pbxproj +4 -0
- package/lib/commonjs/Constraints.js +2 -0
- package/lib/commonjs/Constraints.js.map +1 -0
- package/lib/commonjs/MediaDevices.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +26 -3
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCAudioSession.js +33 -0
- package/lib/commonjs/RTCAudioSession.js.map +1 -0
- package/lib/commonjs/RTCPIPView.js +42 -0
- package/lib/commonjs/RTCPIPView.js.map +1 -0
- package/lib/commonjs/RTCView.js.map +1 -1
- package/lib/commonjs/getUserMedia.js.map +1 -1
- package/lib/commonjs/index.js +28 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Constraints.js +2 -0
- package/lib/module/Constraints.js.map +1 -0
- package/lib/module/MediaDevices.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +27 -4
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCAudioSession.js +26 -0
- package/lib/module/RTCAudioSession.js.map +1 -0
- package/lib/module/RTCPIPView.js +30 -0
- package/lib/module/RTCPIPView.js.map +1 -0
- package/lib/module/RTCView.js.map +1 -1
- package/lib/module/getUserMedia.js.map +1 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/Constraints.d.ts +19 -0
- package/lib/typescript/MediaDevices.d.ts +2 -1
- package/lib/typescript/MediaStreamTrack.d.ts +26 -5
- package/lib/typescript/RTCAudioSession.d.ts +10 -0
- package/lib/typescript/RTCPIPView.d.ts +14 -0
- package/lib/typescript/RTCView.d.ts +44 -1
- package/lib/typescript/getUserMedia.d.ts +4 -4
- package/lib/typescript/index.d.ts +5 -3
- package/package.json +2 -1
- package/src/.eslintrc.cjs +1 -1
- package/src/Constraints.ts +21 -0
- package/src/MediaDevices.ts +2 -2
- package/src/MediaStreamTrack.ts +41 -7
- package/src/RTCAudioSession.ts +25 -0
- package/src/RTCPIPView.tsx +46 -0
- package/src/RTCView.ts +50 -2
- package/src/getUserMedia.ts +4 -3
- package/src/index.ts +12 -3
- package/tsconfig.json +3 -1
- package/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
package/android/build.gradle
CHANGED
|
@@ -14,10 +14,11 @@ android {
|
|
|
14
14
|
buildToolsVersion safeExtGet('buildToolsVersion', "23.0.1")
|
|
15
15
|
|
|
16
16
|
defaultConfig {
|
|
17
|
-
minSdkVersion
|
|
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
|
|
@@ -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
|
|
7
|
-
protected
|
|
8
|
-
protected
|
|
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,12 @@ 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(new UnsupportedOperationException("This video track does not support applyConstraints."));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
76
102
|
public void setCapturerEventsListener(CapturerEventsListener listener) {
|
|
77
103
|
this.capturerEventsListener = listener;
|
|
78
104
|
}
|
|
@@ -5,8 +5,10 @@ import android.hardware.camera2.CameraManager;
|
|
|
5
5
|
import android.util.Log;
|
|
6
6
|
import android.util.Pair;
|
|
7
7
|
import androidx.annotation.Nullable;
|
|
8
|
+
import androidx.core.util.Consumer;
|
|
8
9
|
|
|
9
10
|
import com.facebook.react.bridge.ReadableMap;
|
|
11
|
+
import com.facebook.react.bridge.WritableMap;
|
|
10
12
|
|
|
11
13
|
import org.webrtc.Camera1Capturer;
|
|
12
14
|
import org.webrtc.Camera1Helper;
|
|
@@ -19,6 +21,7 @@ import org.webrtc.VideoCapturer;
|
|
|
19
21
|
|
|
20
22
|
import java.util.ArrayList;
|
|
21
23
|
import java.util.List;
|
|
24
|
+
import java.util.Objects;
|
|
22
25
|
|
|
23
26
|
public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
24
27
|
/**
|
|
@@ -28,17 +31,30 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
28
31
|
|
|
29
32
|
private boolean isFrontFacing;
|
|
30
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Equivalent to the camera index as a String
|
|
36
|
+
*/
|
|
37
|
+
@Nullable
|
|
38
|
+
private String currentDeviceId;
|
|
39
|
+
|
|
31
40
|
private final Context context;
|
|
32
41
|
private final CameraEnumerator cameraEnumerator;
|
|
33
|
-
private
|
|
42
|
+
private ReadableMap constraints;
|
|
34
43
|
|
|
35
44
|
/**
|
|
36
45
|
* The {@link CameraEventsHandler} used with
|
|
37
|
-
* {@link CameraEnumerator#createCapturer}.
|
|
38
|
-
* implementation does not do anything but logging unspecific to the camera
|
|
39
|
-
* device's name anyway.
|
|
46
|
+
* {@link CameraEnumerator#createCapturer}.
|
|
40
47
|
*/
|
|
41
|
-
private final CameraEventsHandler cameraEventsHandler = new CameraEventsHandler()
|
|
48
|
+
private final CameraEventsHandler cameraEventsHandler = new CameraEventsHandler() {
|
|
49
|
+
|
|
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,137 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
48
64
|
this.constraints = constraints;
|
|
49
65
|
}
|
|
50
66
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
67
|
+
@Nullable
|
|
68
|
+
@Override
|
|
69
|
+
public String getDeviceId() {
|
|
70
|
+
return currentDeviceId;
|
|
71
|
+
}
|
|
56
72
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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);
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
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
|
+
|
|
132
|
+
// Otherwise, use facingMode (defaulting to front/user facing).
|
|
133
|
+
if (cameraName == null) {
|
|
134
|
+
cameraIndex = -1;
|
|
135
|
+
final boolean isFrontFacing = facingMode == null || facingMode.equals("user");
|
|
136
|
+
for (String name : deviceNames) {
|
|
137
|
+
cameraIndex++;
|
|
138
|
+
if (cameraEnumerator.isFrontFacing(name) == isFrontFacing) {
|
|
139
|
+
cameraName = name;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (cameraName == null) {
|
|
146
|
+
if (onFinishedCallback != null) {
|
|
147
|
+
onFinishedCallback.accept(new Exception("OverconstrainedError: could not find camera with deviceId: " + deviceId + " or facingMode: " + facingMode));
|
|
76
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
|
+
}
|
|
77
163
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
164
|
+
CameraVideoCapturer capturer = (CameraVideoCapturer) videoCapturer;
|
|
165
|
+
Runnable changeFormatIfNeededAndFinish = () -> {
|
|
166
|
+
saveConstraints.run();
|
|
167
|
+
if (targetWidth != oldTargetWidth ||
|
|
168
|
+
targetHeight != oldTargetHeight ||
|
|
169
|
+
targetFps != oldTargetFps) {
|
|
170
|
+
updateActualSize(finalCameraIndex, finalCameraName, videoCapturer);
|
|
171
|
+
capturer.changeCaptureFormat(targetWidth, targetHeight, targetFps);
|
|
172
|
+
}
|
|
173
|
+
if (onFinishedCallback != null) {
|
|
174
|
+
onFinishedCallback.accept(null);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
if (shouldSwitchCamera) {
|
|
179
|
+
capturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() {
|
|
180
|
+
@Override
|
|
181
|
+
public void onCameraSwitchDone(boolean isFrontCamera) {
|
|
182
|
+
CameraCaptureController.this.isFrontFacing = isFrontCamera;
|
|
183
|
+
changeFormatIfNeededAndFinish.run();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@Override
|
|
187
|
+
public void onCameraSwitchError(String s) {
|
|
188
|
+
Exception e = new Exception("Error switching camera: " + s);
|
|
189
|
+
Log.e(TAG, "OnCameraSwitchError", e);
|
|
190
|
+
if (onFinishedCallback != null) {
|
|
191
|
+
onFinishedCallback.accept(e);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}, cameraName);
|
|
195
|
+
} else {
|
|
196
|
+
// No camera switch needed, just change format if needed.
|
|
197
|
+
changeFormatIfNeededAndFinish.run();
|
|
81
198
|
}
|
|
82
199
|
}
|
|
83
200
|
|
|
@@ -86,19 +203,21 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
86
203
|
String deviceId = ReactBridgeUtil.getMapStrValue(this.constraints, "deviceId");
|
|
87
204
|
String facingMode = ReactBridgeUtil.getMapStrValue(this.constraints, "facingMode");
|
|
88
205
|
|
|
89
|
-
|
|
206
|
+
CreateCapturerResult result = createVideoCapturer(deviceId, facingMode);
|
|
90
207
|
if(result == null) {
|
|
91
208
|
return null;
|
|
92
209
|
}
|
|
93
210
|
|
|
94
|
-
|
|
95
|
-
|
|
211
|
+
updateActualSize(result.cameraIndex, result.cameraName, result.videoCapturer);
|
|
212
|
+
|
|
213
|
+
return result.videoCapturer;
|
|
214
|
+
}
|
|
96
215
|
|
|
216
|
+
private void updateActualSize(int cameraIndex, String cameraName, VideoCapturer videoCapturer) {
|
|
97
217
|
// Find actual capture format.
|
|
98
218
|
Size actualSize = null;
|
|
99
219
|
if (videoCapturer instanceof Camera1Capturer) {
|
|
100
|
-
|
|
101
|
-
actualSize = Camera1Helper.findClosestCaptureFormat(cameraId, targetWidth, targetHeight);
|
|
220
|
+
actualSize = Camera1Helper.findClosestCaptureFormat(cameraIndex, targetWidth, targetHeight);
|
|
102
221
|
} else if (videoCapturer instanceof Camera2Capturer) {
|
|
103
222
|
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
|
|
104
223
|
actualSize = Camera2Helper.findClosestCaptureFormat(cameraManager, cameraName, targetWidth, targetHeight);
|
|
@@ -108,37 +227,6 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
108
227
|
actualWidth = actualSize.width;
|
|
109
228
|
actualHeight = actualSize.height;
|
|
110
229
|
}
|
|
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
230
|
}
|
|
143
231
|
|
|
144
232
|
/**
|
|
@@ -155,14 +243,15 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
155
243
|
* {@code deviceId} constraint, or null.
|
|
156
244
|
*/
|
|
157
245
|
@Nullable
|
|
158
|
-
private
|
|
246
|
+
private CreateCapturerResult createVideoCapturer(String deviceId, String facingMode) {
|
|
159
247
|
String[] deviceNames = cameraEnumerator.getDeviceNames();
|
|
160
248
|
List<String> failedDevices = new ArrayList<>();
|
|
161
249
|
|
|
162
250
|
String cameraName = null;
|
|
251
|
+
int cameraIndex = -1;
|
|
163
252
|
try {
|
|
164
|
-
|
|
165
|
-
cameraName = deviceNames[
|
|
253
|
+
cameraIndex = Integer.parseInt(deviceId);
|
|
254
|
+
cameraName = deviceNames[cameraIndex];
|
|
166
255
|
} catch (Exception e) {
|
|
167
256
|
Log.d(TAG, "failed to find device with id: " + deviceId);
|
|
168
257
|
}
|
|
@@ -174,7 +263,8 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
174
263
|
if (videoCapturer != null) {
|
|
175
264
|
Log.d(TAG, message + " succeeded");
|
|
176
265
|
this.isFrontFacing = cameraEnumerator.isFrontFacing(cameraName);
|
|
177
|
-
|
|
266
|
+
this.currentDeviceId = String.valueOf(cameraIndex);
|
|
267
|
+
return new CreateCapturerResult(cameraIndex, cameraName, videoCapturer);
|
|
178
268
|
} else {
|
|
179
269
|
// fallback to facingMode
|
|
180
270
|
Log.d(TAG, message + " failed");
|
|
@@ -183,8 +273,10 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
183
273
|
}
|
|
184
274
|
|
|
185
275
|
// Otherwise, use facingMode (defaulting to front/user facing).
|
|
186
|
-
final boolean isFrontFacing = facingMode == null ||
|
|
276
|
+
final boolean isFrontFacing = facingMode == null || facingMode.equals("user");
|
|
277
|
+
cameraIndex = -1;
|
|
187
278
|
for (String name : deviceNames) {
|
|
279
|
+
cameraIndex++;
|
|
188
280
|
if (failedDevices.contains(name)) {
|
|
189
281
|
continue;
|
|
190
282
|
}
|
|
@@ -196,22 +288,26 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
196
288
|
if (videoCapturer != null) {
|
|
197
289
|
Log.d(TAG, message + " succeeded");
|
|
198
290
|
this.isFrontFacing = cameraEnumerator.isFrontFacing(name);
|
|
199
|
-
|
|
291
|
+
this.currentDeviceId = String.valueOf(cameraIndex);
|
|
292
|
+
return new CreateCapturerResult(cameraIndex, name, videoCapturer);
|
|
200
293
|
} else {
|
|
201
294
|
Log.d(TAG, message + " failed");
|
|
202
295
|
failedDevices.add(name);
|
|
203
296
|
}
|
|
204
297
|
}
|
|
205
298
|
|
|
299
|
+
cameraIndex = -1;
|
|
206
300
|
// Fallback to any available camera.
|
|
207
301
|
for (String name : deviceNames) {
|
|
302
|
+
cameraIndex++;
|
|
208
303
|
if (!failedDevices.contains(name)) {
|
|
209
304
|
VideoCapturer videoCapturer = cameraEnumerator.createCapturer(name, cameraEventsHandler);
|
|
210
305
|
String message = "Create fallback camera " + name;
|
|
211
306
|
if (videoCapturer != null) {
|
|
212
307
|
Log.d(TAG, message + " succeeded");
|
|
213
308
|
this.isFrontFacing = cameraEnumerator.isFrontFacing(name);
|
|
214
|
-
|
|
309
|
+
this.currentDeviceId = String.valueOf(cameraIndex);
|
|
310
|
+
return new CreateCapturerResult(cameraIndex, name, videoCapturer);
|
|
215
311
|
} else {
|
|
216
312
|
Log.d(TAG, message + " failed");
|
|
217
313
|
failedDevices.add(name);
|
|
@@ -219,8 +315,21 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
219
315
|
}
|
|
220
316
|
}
|
|
221
317
|
|
|
318
|
+
currentDeviceId = null;
|
|
222
319
|
Log.w(TAG, "Unable to identify a suitable camera.");
|
|
223
320
|
|
|
224
321
|
return null;
|
|
225
322
|
}
|
|
323
|
+
|
|
324
|
+
private static class CreateCapturerResult {
|
|
325
|
+
public final int cameraIndex;
|
|
326
|
+
public final String cameraName;
|
|
327
|
+
public final VideoCapturer videoCapturer;
|
|
328
|
+
|
|
329
|
+
public CreateCapturerResult(int cameraIndex, String cameraName, VideoCapturer videoCapturer) {
|
|
330
|
+
this.cameraIndex = cameraIndex;
|
|
331
|
+
this.cameraName = cameraName;
|
|
332
|
+
this.videoCapturer = videoCapturer;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
226
335
|
}
|
|
@@ -6,6 +6,7 @@ import android.content.Intent;
|
|
|
6
6
|
import android.media.projection.MediaProjectionManager;
|
|
7
7
|
import android.util.DisplayMetrics;
|
|
8
8
|
import android.util.Log;
|
|
9
|
+
import androidx.core.util.Consumer;
|
|
9
10
|
|
|
10
11
|
import com.facebook.react.bridge.Arguments;
|
|
11
12
|
import com.facebook.react.bridge.BaseActivityEventListener;
|
|
@@ -233,11 +234,22 @@ class GetUserMediaImpl {
|
|
|
233
234
|
}
|
|
234
235
|
}
|
|
235
236
|
|
|
236
|
-
void
|
|
237
|
+
void applyConstraints(String trackId, ReadableMap constraints, Promise promise) {
|
|
237
238
|
TrackPrivate track = tracks.get(trackId);
|
|
238
|
-
if (track != null && track.videoCaptureController instanceof
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
if (track != null && track.videoCaptureController instanceof AbstractVideoCaptureController) {
|
|
240
|
+
AbstractVideoCaptureController captureController = (AbstractVideoCaptureController) track.videoCaptureController;
|
|
241
|
+
captureController.applyConstraints(constraints, new Consumer<Exception>() {
|
|
242
|
+
public void accept(Exception e) {
|
|
243
|
+
if(e != null) {
|
|
244
|
+
promise.reject(e);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
promise.resolve(captureController.getSettings());
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
} else {
|
|
252
|
+
promise.reject(new Exception("Camera track not found!"));
|
|
241
253
|
}
|
|
242
254
|
}
|
|
243
255
|
|
|
@@ -327,10 +339,13 @@ class GetUserMediaImpl {
|
|
|
327
339
|
if (track instanceof VideoTrack) {
|
|
328
340
|
TrackPrivate tp = this.tracks.get(trackId);
|
|
329
341
|
AbstractVideoCaptureController vcc = tp.videoCaptureController;
|
|
342
|
+
trackInfo.putMap("settings", vcc.getSettings());
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (track instanceof AudioTrack) {
|
|
330
346
|
WritableMap settings = Arguments.createMap();
|
|
331
|
-
settings.
|
|
332
|
-
settings.
|
|
333
|
-
settings.putInt("frameRate", vcc.getFrameRate());
|
|
347
|
+
settings.putString("deviceId", "audio-1");
|
|
348
|
+
settings.putString("groupId", "");
|
|
334
349
|
trackInfo.putMap("settings", settings);
|
|
335
350
|
}
|
|
336
351
|
|
|
@@ -60,6 +60,11 @@ public class ScreenCaptureController extends AbstractVideoCaptureController {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
@Override
|
|
64
|
+
public String getDeviceId() {
|
|
65
|
+
return "screen-capture";
|
|
66
|
+
}
|
|
67
|
+
|
|
63
68
|
@Override
|
|
64
69
|
public void dispose() {
|
|
65
70
|
MediaProjectionService.abort(context);
|
|
@@ -882,11 +882,13 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
882
882
|
}
|
|
883
883
|
|
|
884
884
|
@ReactMethod
|
|
885
|
-
public void
|
|
885
|
+
public void mediaStreamTrackApplyConstraints(String id, ReadableMap constraints, Promise promise) {
|
|
886
886
|
ThreadUtils.runOnExecutor(() -> {
|
|
887
887
|
MediaStreamTrack track = getLocalTrack(id);
|
|
888
888
|
if (track != null) {
|
|
889
|
-
getUserMediaImpl.
|
|
889
|
+
getUserMediaImpl.applyConstraints(id, constraints, promise);
|
|
890
|
+
} else {
|
|
891
|
+
promise.reject(new Exception("mediaStreamTrackApplyConstraints() could not find track " + id));
|
|
890
892
|
}
|
|
891
893
|
});
|
|
892
894
|
}
|
|
@@ -6,9 +6,12 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
6
6
|
@interface CaptureController : NSObject
|
|
7
7
|
|
|
8
8
|
@property(nonatomic, strong) id<CapturerEventsDelegate> eventsDelegate;
|
|
9
|
+
@property(nonatomic, copy, nullable) NSString* deviceId;
|
|
9
10
|
|
|
10
11
|
- (void)startCapture;
|
|
11
12
|
- (void)stopCapture;
|
|
13
|
+
- (NSDictionary *)getSettings;
|
|
14
|
+
- (void)applyConstraints:(NSDictionary *)constraints error:(NSError **)outError;
|
|
12
15
|
|
|
13
16
|
@end
|
|
14
17
|
|
|
@@ -12,6 +12,19 @@
|
|
|
12
12
|
// subclasses needs to override
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
- (NSDictionary *) getSettings {
|
|
16
|
+
// subclasses needs to override
|
|
17
|
+
return @{
|
|
18
|
+
@"deviceId": self.deviceId
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
- (void)applyConstraints:(NSDictionary *)constraints error:(NSError **)outError {
|
|
23
|
+
*outError = [NSError errorWithDomain:@"react-native-webrtc"
|
|
24
|
+
code:0
|
|
25
|
+
userInfo:@{ NSLocalizedDescriptionKey: @"This video track does not support applyConstraints."}];
|
|
26
|
+
}
|
|
27
|
+
|
|
15
28
|
@end
|
|
16
29
|
|
|
17
30
|
#endif
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// I420Converter.h
|
|
3
|
+
// VideoSampleCaptureRender
|
|
4
|
+
//
|
|
5
|
+
// Adapted from: https://github.com/twilio/video-ios-affectiva/blob/ed2e864324c40ad25e5a06cc2b05298b03caed09/EmoCall/I420Converter.h
|
|
6
|
+
// Created by Boisy Pitre on 5/21/16.
|
|
7
|
+
// Copyright © 2016 Twilio. All rights reserved.
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
#import <UIKit/UIKit.h>
|
|
11
|
+
#import <Accelerate/Accelerate.h>
|
|
12
|
+
#import <WebRTC/WebRTC.h>
|
|
13
|
+
|
|
14
|
+
@interface I420Converter : NSObject
|
|
15
|
+
|
|
16
|
+
- (vImage_Error)prepareForAccelerateConversion;
|
|
17
|
+
- (void)unprepareForAccelerateConversion;
|
|
18
|
+
- (CVPixelBufferRef)convertI420ToPixelBuffer:(RTCI420Buffer *)buffer;
|
|
19
|
+
- (void)createPixelBufferPoolWithWidth:(size_t)width height:(size_t)height;
|
|
20
|
+
|
|
21
|
+
@end
|