react-native-webrtc 106.0.4 → 106.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.
- package/.clang-format +11 -0
- package/.github/workflows/android_ci.yml +29 -0
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/ios_ci.yml +50 -0
- package/LICENSE +2 -1
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +11 -1
- package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +7 -15
- package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +4 -13
- package/android/src/main/java/com/oney/WebRTCModule/DataChannelWrapper.java +12 -16
- package/android/src/main/java/com/oney/WebRTCModule/DisplayUtils.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/EglUtils.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +37 -47
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +123 -116
- package/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +60 -61
- package/android/src/main/java/com/oney/WebRTCModule/ReactBridgeUtil.java +1 -2
- package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +12 -9
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +116 -121
- package/android/src/main/java/com/oney/WebRTCModule/StringUtils.java +8 -14
- package/android/src/main/java/com/oney/WebRTCModule/ThreadUtils.java +1 -2
- package/android/src/main/java/com/oney/WebRTCModule/TrackCapturerEventsEmitter.java +34 -0
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +5 -9
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +383 -378
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModulePackage.java +4 -10
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +74 -98
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/ProcessorProvider.java +10 -9
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +2 -6
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessorFactoryInterface.java +4 -5
- package/ios/RCTWebRTC/CaptureController.h +4 -8
- package/ios/RCTWebRTC/CaptureController.m +0 -7
- package/ios/RCTWebRTC/CapturerEventsDelegate.h +12 -0
- package/ios/RCTWebRTC/DataChannelWrapper.h +9 -13
- package/ios/RCTWebRTC/DataChannelWrapper.m +4 -5
- package/ios/RCTWebRTC/RCTConvert+WebRTC.h +2 -2
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +166 -171
- package/ios/RCTWebRTC/RTCMediaStreamTrack+React.h +1 -1
- package/ios/RCTWebRTC/RTCMediaStreamTrack+React.m +1 -1
- package/ios/RCTWebRTC/RTCVideoViewManager.h +0 -8
- package/ios/RCTWebRTC/RTCVideoViewManager.m +207 -239
- package/ios/RCTWebRTC/ScreenCaptureController.h +3 -9
- package/ios/RCTWebRTC/ScreenCaptureController.m +20 -15
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.h +0 -7
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +26 -34
- package/ios/RCTWebRTC/ScreenCapturer.h +4 -8
- package/ios/RCTWebRTC/ScreenCapturer.m +57 -55
- package/ios/RCTWebRTC/SerializeUtils.h +16 -16
- package/ios/RCTWebRTC/SerializeUtils.m +98 -99
- package/ios/RCTWebRTC/SocketConnection.h +1 -8
- package/ios/RCTWebRTC/SocketConnection.m +31 -38
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.h +14 -0
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +37 -0
- package/ios/RCTWebRTC/VideoCaptureController.h +6 -7
- package/ios/RCTWebRTC/VideoCaptureController.m +54 -53
- package/ios/RCTWebRTC/WebRTCModule+Permissions.m +14 -13
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.h +3 -3
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +105 -100
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +8 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +218 -173
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +7 -14
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +625 -595
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +128 -139
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.h +4 -5
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +26 -35
- package/ios/RCTWebRTC/WebRTCModule.h +14 -20
- package/ios/RCTWebRTC/WebRTCModule.m +69 -83
- package/ios/RCTWebRTC.xcodeproj/project.pbxproj +10 -1
- package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/EventEmitter.js +1 -1
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +25 -0
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +169 -162
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
- package/lib/module/EventEmitter.js +1 -1
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +21 -0
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +169 -162
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtpTransceiver.js +1 -1
- package/lib/module/RTCRtpTransceiver.js.map +1 -1
- package/lib/typescript/MediaStreamTrack.d.ts +1 -0
- package/lib/typescript/RTCPeerConnection.d.ts +5 -4
- package/package.json +3 -2
- package/src/EventEmitter.ts +1 -0
- package/src/MediaStreamTrack.ts +23 -0
- package/src/RTCPeerConnection.ts +168 -174
- package/src/RTCRtpTransceiver.ts +1 -1
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
package/.clang-format
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: Android CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [ master ]
|
|
5
|
+
pull_request:
|
|
6
|
+
branches: [ master ]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
android-compile:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v3
|
|
13
|
+
|
|
14
|
+
- uses: actions/setup-node@v3
|
|
15
|
+
with:
|
|
16
|
+
node-version: '16.x'
|
|
17
|
+
cache: 'npm'
|
|
18
|
+
cache-dependency-path: '**/package-lock.json'
|
|
19
|
+
|
|
20
|
+
- name: Install node modules
|
|
21
|
+
run: npm install
|
|
22
|
+
|
|
23
|
+
- name: Install example node modules
|
|
24
|
+
run: npm install
|
|
25
|
+
working-directory: ./examples/GumTestApp/
|
|
26
|
+
|
|
27
|
+
- name: Compile Android Example
|
|
28
|
+
run: ./gradlew assembleDebug
|
|
29
|
+
working-directory: ./examples/GumTestApp/android
|
package/.github/workflows/ci.yml
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name: iOS CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [ master ]
|
|
5
|
+
pull_request:
|
|
6
|
+
branches: [ master ]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
ios-compile:
|
|
10
|
+
runs-on: macos-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v3
|
|
13
|
+
|
|
14
|
+
- uses: actions/setup-node@v3
|
|
15
|
+
with:
|
|
16
|
+
node-version: '16.x'
|
|
17
|
+
cache: 'npm'
|
|
18
|
+
cache-dependency-path: '**/package-lock.json'
|
|
19
|
+
|
|
20
|
+
- name: Cache cocoapods
|
|
21
|
+
uses: actions/cache@v3
|
|
22
|
+
with:
|
|
23
|
+
path: ./examples/GumTestApp/ios/Pods
|
|
24
|
+
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
|
|
25
|
+
restore-keys: |
|
|
26
|
+
${{ runner.os }}-pods-
|
|
27
|
+
|
|
28
|
+
- name: Install node modules
|
|
29
|
+
run: npm install
|
|
30
|
+
|
|
31
|
+
- name: Install example node modules
|
|
32
|
+
working-directory: ./examples/GumTestApp/
|
|
33
|
+
run: npm install
|
|
34
|
+
|
|
35
|
+
- name: Pod install
|
|
36
|
+
working-directory: ./examples/GumTestApp/ios
|
|
37
|
+
run: pod install
|
|
38
|
+
|
|
39
|
+
- name: Compile iOS Example
|
|
40
|
+
working-directory: ./examples/GumTestApp/ios
|
|
41
|
+
run: |
|
|
42
|
+
set -o pipefail && \
|
|
43
|
+
xcodebuild -workspace GumTestApp.xcworkspace/ \
|
|
44
|
+
-scheme GumTestApp \
|
|
45
|
+
-destination generic/platform=iOS \
|
|
46
|
+
CODE_SIGN_IDENTITY="" \
|
|
47
|
+
CODE_SIGNING_REQUIRED=NO \
|
|
48
|
+
CODE_SIGN_ENTITLEMENTS="" \
|
|
49
|
+
CODE_SIGNING_ALLOWED="NO" clean build \
|
|
50
|
+
| xcpretty
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2017-present React Native WebRTC Community
|
|
4
|
+
Copyright (c) 2015-2017 Howard Yang
|
|
4
5
|
|
|
5
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
7
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -3,7 +3,6 @@ package com.oney.WebRTCModule;
|
|
|
3
3
|
import org.webrtc.VideoCapturer;
|
|
4
4
|
|
|
5
5
|
public abstract class AbstractVideoCaptureController {
|
|
6
|
-
|
|
7
6
|
private final int width;
|
|
8
7
|
private final int height;
|
|
9
8
|
private final int fps;
|
|
@@ -13,6 +12,8 @@ public abstract class AbstractVideoCaptureController {
|
|
|
13
12
|
*/
|
|
14
13
|
protected VideoCapturer videoCapturer;
|
|
15
14
|
|
|
15
|
+
protected CapturerEventsListener capturerEventsListener;
|
|
16
|
+
|
|
16
17
|
public AbstractVideoCaptureController(int width, int height, int fps) {
|
|
17
18
|
this.width = width;
|
|
18
19
|
this.height = height;
|
|
@@ -65,5 +66,14 @@ public abstract class AbstractVideoCaptureController {
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
public void setCapturerEventsListener(CapturerEventsListener listener) {
|
|
70
|
+
this.capturerEventsListener = listener;
|
|
71
|
+
}
|
|
72
|
+
|
|
68
73
|
protected abstract VideoCapturer createVideoCapturer();
|
|
74
|
+
|
|
75
|
+
public interface CapturerEventsListener {
|
|
76
|
+
/** Called when the capturer is ended and in an irrecoverable state. */
|
|
77
|
+
public void onCapturerEnded();
|
|
78
|
+
}
|
|
69
79
|
}
|
|
@@ -15,8 +15,7 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
15
15
|
/**
|
|
16
16
|
* The {@link Log} tag with which {@code CameraCaptureController} is to log.
|
|
17
17
|
*/
|
|
18
|
-
private static final String TAG
|
|
19
|
-
= CameraCaptureController.class.getSimpleName();
|
|
18
|
+
private static final String TAG = CameraCaptureController.class.getSimpleName();
|
|
20
19
|
|
|
21
20
|
private boolean isFrontFacing;
|
|
22
21
|
|
|
@@ -32,10 +31,7 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
32
31
|
private final CameraEventsHandler cameraEventsHandler = new CameraEventsHandler();
|
|
33
32
|
|
|
34
33
|
public CameraCaptureController(CameraEnumerator cameraEnumerator, ReadableMap constraints) {
|
|
35
|
-
super(
|
|
36
|
-
constraints.getInt("width"),
|
|
37
|
-
constraints.getInt("height"),
|
|
38
|
-
constraints.getInt("frameRate"));
|
|
34
|
+
super(constraints.getInt("width"), constraints.getInt("height"), constraints.getInt("frameRate"));
|
|
39
35
|
|
|
40
36
|
this.cameraEnumerator = cameraEnumerator;
|
|
41
37
|
this.constraints = constraints;
|
|
@@ -95,7 +91,7 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
95
91
|
@Override
|
|
96
92
|
public void onCameraSwitchDone(boolean b) {
|
|
97
93
|
if (b != desiredFrontFacing) {
|
|
98
|
-
int newTries = tries-1;
|
|
94
|
+
int newTries = tries - 1;
|
|
99
95
|
if (newTries > 0) {
|
|
100
96
|
switchCamera(desiredFrontFacing, newTries);
|
|
101
97
|
}
|
|
@@ -138,8 +134,7 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
138
134
|
|
|
139
135
|
// If deviceId is specified, then it takes precedence over facingMode.
|
|
140
136
|
if (cameraName != null) {
|
|
141
|
-
VideoCapturer videoCapturer
|
|
142
|
-
= cameraEnumerator.createCapturer(cameraName, cameraEventsHandler);
|
|
137
|
+
VideoCapturer videoCapturer = cameraEnumerator.createCapturer(cameraName, cameraEventsHandler);
|
|
143
138
|
String message = "Create user-specified camera " + cameraName;
|
|
144
139
|
if (videoCapturer != null) {
|
|
145
140
|
Log.d(TAG, message + " succeeded");
|
|
@@ -153,8 +148,7 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
153
148
|
}
|
|
154
149
|
|
|
155
150
|
// Otherwise, use facingMode (defaulting to front/user facing).
|
|
156
|
-
final boolean isFrontFacing
|
|
157
|
-
= facingMode == null || !facingMode.equals("environment");
|
|
151
|
+
final boolean isFrontFacing = facingMode == null || !facingMode.equals("environment");
|
|
158
152
|
for (String name : deviceNames) {
|
|
159
153
|
if (failedDevices.contains(name)) {
|
|
160
154
|
continue;
|
|
@@ -162,8 +156,7 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
162
156
|
if (cameraEnumerator.isFrontFacing(name) != isFrontFacing) {
|
|
163
157
|
continue;
|
|
164
158
|
}
|
|
165
|
-
VideoCapturer videoCapturer
|
|
166
|
-
= cameraEnumerator.createCapturer(name, cameraEventsHandler);
|
|
159
|
+
VideoCapturer videoCapturer = cameraEnumerator.createCapturer(name, cameraEventsHandler);
|
|
167
160
|
String message = "Create camera " + name;
|
|
168
161
|
if (videoCapturer != null) {
|
|
169
162
|
Log.d(TAG, message + " succeeded");
|
|
@@ -178,8 +171,7 @@ public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
|
178
171
|
// Fallback to any available camera.
|
|
179
172
|
for (String name : deviceNames) {
|
|
180
173
|
if (!failedDevices.contains(name)) {
|
|
181
|
-
VideoCapturer videoCapturer
|
|
182
|
-
= cameraEnumerator.createCapturer(name, cameraEventsHandler);
|
|
174
|
+
VideoCapturer videoCapturer = cameraEnumerator.createCapturer(name, cameraEventsHandler);
|
|
183
175
|
String message = "Create fallback camera " + name;
|
|
184
176
|
if (videoCapturer != null) {
|
|
185
177
|
Log.d(TAG, message + " succeeded");
|
|
@@ -13,7 +13,7 @@ class CameraEventsHandler implements CameraVideoCapturer.CameraEventsHandler {
|
|
|
13
13
|
// Callback invoked when camera closed.
|
|
14
14
|
@Override
|
|
15
15
|
public void onCameraClosed() {
|
|
16
|
-
Log.d(TAG, "CameraEventsHandler.
|
|
16
|
+
Log.d(TAG, "CameraEventsHandler.onCameraClosed");
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// Called when camera is disconnected.
|
|
@@ -26,28 +26,19 @@ class CameraEventsHandler implements CameraVideoCapturer.CameraEventsHandler {
|
|
|
26
26
|
// camera exception happens on camera thread.
|
|
27
27
|
@Override
|
|
28
28
|
public void onCameraError(String errorDescription) {
|
|
29
|
-
Log.d(
|
|
30
|
-
TAG,
|
|
31
|
-
"CameraEventsHandler.onCameraError: errorDescription="
|
|
32
|
-
+ errorDescription);
|
|
29
|
+
Log.d(TAG, "CameraEventsHandler.onCameraError: errorDescription=" + errorDescription);
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
// Invoked when camera stops receiving frames
|
|
36
33
|
@Override
|
|
37
34
|
public void onCameraFreezed(String errorDescription) {
|
|
38
|
-
Log.d(
|
|
39
|
-
TAG,
|
|
40
|
-
"CameraEventsHandler.onCameraFreezed: errorDescription="
|
|
41
|
-
+ errorDescription);
|
|
35
|
+
Log.d(TAG, "CameraEventsHandler.onCameraFreezed: errorDescription=" + errorDescription);
|
|
42
36
|
}
|
|
43
37
|
|
|
44
38
|
// Callback invoked when camera is opening.
|
|
45
39
|
@Override
|
|
46
40
|
public void onCameraOpening(String cameraName) {
|
|
47
|
-
Log.d(
|
|
48
|
-
TAG,
|
|
49
|
-
"CameraEventsHandler.onCameraOpening: cameraName="
|
|
50
|
-
+ cameraName);
|
|
41
|
+
Log.d(TAG, "CameraEventsHandler.onCameraOpening: cameraName=" + cameraName);
|
|
51
42
|
}
|
|
52
43
|
|
|
53
44
|
// Callback invoked when first camera frame is available after camera is opened.
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
package com.oney.WebRTCModule;
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import android.util.Base64;
|
|
4
4
|
|
|
5
5
|
import androidx.annotation.Nullable;
|
|
6
|
-
import android.util.Base64;
|
|
7
6
|
|
|
8
7
|
import com.facebook.react.bridge.Arguments;
|
|
9
8
|
import com.facebook.react.bridge.WritableMap;
|
|
10
9
|
|
|
11
10
|
import org.webrtc.DataChannel;
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
import java.nio.charset.StandardCharsets;
|
|
14
13
|
|
|
14
|
+
class DataChannelWrapper implements DataChannel.Observer {
|
|
15
15
|
private final String reactTag;
|
|
16
16
|
private final DataChannel mDataChannel;
|
|
17
17
|
private final int peerConnectionId;
|
|
18
18
|
private final WebRTCModule webRTCModule;
|
|
19
19
|
|
|
20
|
-
DataChannelWrapper(
|
|
21
|
-
WebRTCModule webRTCModule,
|
|
22
|
-
int peerConnectionId,
|
|
23
|
-
String reactTag,
|
|
24
|
-
DataChannel dataChannel) {
|
|
20
|
+
DataChannelWrapper(WebRTCModule webRTCModule, int peerConnectionId, String reactTag, DataChannel dataChannel) {
|
|
25
21
|
this.webRTCModule = webRTCModule;
|
|
26
22
|
this.peerConnectionId = peerConnectionId;
|
|
27
23
|
this.reactTag = reactTag;
|
|
@@ -39,14 +35,14 @@ class DataChannelWrapper implements DataChannel.Observer {
|
|
|
39
35
|
@Nullable
|
|
40
36
|
public String dataChannelStateString(DataChannel.State dataChannelState) {
|
|
41
37
|
switch (dataChannelState) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
case CONNECTING:
|
|
39
|
+
return "connecting";
|
|
40
|
+
case OPEN:
|
|
41
|
+
return "open";
|
|
42
|
+
case CLOSING:
|
|
43
|
+
return "closing";
|
|
44
|
+
case CLOSED:
|
|
45
|
+
return "closed";
|
|
50
46
|
}
|
|
51
47
|
return null;
|
|
52
48
|
}
|
|
@@ -9,7 +9,7 @@ public class DisplayUtils {
|
|
|
9
9
|
public static DisplayMetrics getDisplayMetrics(Activity activity) {
|
|
10
10
|
DisplayMetrics displayMetrics = new DisplayMetrics();
|
|
11
11
|
WindowManager windowManager =
|
|
12
|
-
|
|
12
|
+
(WindowManager) activity.getApplication().getSystemService(Context.WINDOW_SERVICE);
|
|
13
13
|
windowManager.getDefaultDisplay().getRealMetrics(displayMetrics);
|
|
14
14
|
return displayMetrics;
|
|
15
15
|
}
|
|
@@ -17,18 +17,17 @@ import com.facebook.react.bridge.ReadableMap;
|
|
|
17
17
|
import com.facebook.react.bridge.UiThreadUtil;
|
|
18
18
|
import com.facebook.react.bridge.WritableArray;
|
|
19
19
|
import com.facebook.react.bridge.WritableMap;
|
|
20
|
-
|
|
21
20
|
import com.oney.WebRTCModule.videoEffects.ProcessorProvider;
|
|
22
21
|
import com.oney.WebRTCModule.videoEffects.VideoEffectProcessor;
|
|
23
22
|
import com.oney.WebRTCModule.videoEffects.VideoFrameProcessor;
|
|
24
23
|
|
|
24
|
+
import org.webrtc.*;
|
|
25
|
+
|
|
25
26
|
import java.util.ArrayList;
|
|
26
27
|
import java.util.HashMap;
|
|
27
28
|
import java.util.Map;
|
|
28
29
|
import java.util.UUID;
|
|
29
30
|
|
|
30
|
-
import org.webrtc.*;
|
|
31
|
-
|
|
32
31
|
/**
|
|
33
32
|
* The implementation of {@code getUserMedia} extracted into a separate file in
|
|
34
33
|
* order to reduce complexity and to (somewhat) separate concerns.
|
|
@@ -65,8 +64,8 @@ class GetUserMediaImpl {
|
|
|
65
64
|
try {
|
|
66
65
|
camera2supported = Camera2Enumerator.isSupported(reactContext);
|
|
67
66
|
} catch (Throwable tr) {
|
|
68
|
-
// Some devices will crash here with: Fatal Exception: java.lang.AssertionError: Supported FPS ranges cannot
|
|
69
|
-
// Make sure we don't.
|
|
67
|
+
// Some devices will crash here with: Fatal Exception: java.lang.AssertionError: Supported FPS ranges cannot
|
|
68
|
+
// be null. Make sure we don't.
|
|
70
69
|
Log.w(TAG, "Error checking for Camera2 API support.", tr);
|
|
71
70
|
}
|
|
72
71
|
|
|
@@ -105,17 +104,15 @@ class GetUserMediaImpl {
|
|
|
105
104
|
PeerConnectionFactory pcFactory = webRTCModule.mFactory;
|
|
106
105
|
MediaConstraints peerConstraints = webRTCModule.constraintsForOptions(audioConstraintsMap);
|
|
107
106
|
|
|
108
|
-
//PeerConnectionFactory.createAudioSource will throw an error when mandatory constraints contain nulls.
|
|
109
|
-
//so, let's check for nulls
|
|
107
|
+
// PeerConnectionFactory.createAudioSource will throw an error when mandatory constraints contain nulls.
|
|
108
|
+
// so, let's check for nulls
|
|
110
109
|
checkMandatoryConstraints(peerConstraints);
|
|
111
110
|
|
|
112
111
|
AudioSource audioSource = pcFactory.createAudioSource(peerConstraints);
|
|
113
112
|
AudioTrack track = pcFactory.createAudioTrack(id, audioSource);
|
|
114
|
-
|
|
113
|
+
|
|
115
114
|
// surfaceTextureHelper is initialized for videoTrack only, so its null here.
|
|
116
|
-
tracks.put(
|
|
117
|
-
id,
|
|
118
|
-
new TrackPrivate(track, audioSource, /* videoCapturer */ null, /* surfaceTextureHelper */ null));
|
|
115
|
+
tracks.put(id, new TrackPrivate(track, audioSource, /* videoCapturer */ null, /* surfaceTextureHelper */ null));
|
|
119
116
|
|
|
120
117
|
return track;
|
|
121
118
|
}
|
|
@@ -127,8 +124,7 @@ class GetUserMediaImpl {
|
|
|
127
124
|
if (constraint.getValue() != null) {
|
|
128
125
|
valid.add(constraint);
|
|
129
126
|
} else {
|
|
130
|
-
Log.d(TAG, String.format("constraint %s is null, ignoring it",
|
|
131
|
-
constraint.getKey()));
|
|
127
|
+
Log.d(TAG, String.format("constraint %s is null, ignoring it", constraint.getKey()));
|
|
132
128
|
}
|
|
133
129
|
}
|
|
134
130
|
|
|
@@ -182,11 +178,7 @@ class GetUserMediaImpl {
|
|
|
182
178
|
* if audio permission was not granted, there will be no "audio" key in
|
|
183
179
|
* the constraints map.
|
|
184
180
|
*/
|
|
185
|
-
void getUserMedia(
|
|
186
|
-
final ReadableMap constraints,
|
|
187
|
-
final Callback successCallback,
|
|
188
|
-
final Callback errorCallback) {
|
|
189
|
-
|
|
181
|
+
void getUserMedia(final ReadableMap constraints, final Callback successCallback, final Callback errorCallback) {
|
|
190
182
|
AudioTrack audioTrack = null;
|
|
191
183
|
VideoTrack videoTrack = null;
|
|
192
184
|
|
|
@@ -199,9 +191,8 @@ class GetUserMediaImpl {
|
|
|
199
191
|
|
|
200
192
|
Log.d(TAG, "getUserMedia(video): " + videoConstraintsMap);
|
|
201
193
|
|
|
202
|
-
CameraCaptureController cameraCaptureController =
|
|
203
|
-
|
|
204
|
-
videoConstraintsMap);
|
|
194
|
+
CameraCaptureController cameraCaptureController =
|
|
195
|
+
new CameraCaptureController(cameraEnumerator, videoConstraintsMap);
|
|
205
196
|
|
|
206
197
|
videoTrack = createVideoTrack(cameraCaptureController);
|
|
207
198
|
}
|
|
@@ -213,7 +204,7 @@ class GetUserMediaImpl {
|
|
|
213
204
|
return;
|
|
214
205
|
}
|
|
215
206
|
|
|
216
|
-
createStream(new MediaStreamTrack[]{audioTrack, videoTrack}, (streamId, tracksInfo) -> {
|
|
207
|
+
createStream(new MediaStreamTrack[] {audioTrack, videoTrack}, (streamId, tracksInfo) -> {
|
|
217
208
|
WritableArray tracksInfoWritableArray = Arguments.createArray();
|
|
218
209
|
|
|
219
210
|
for (WritableMap trackInfo : tracksInfo) {
|
|
@@ -265,15 +256,15 @@ class GetUserMediaImpl {
|
|
|
265
256
|
this.displayMediaPromise = promise;
|
|
266
257
|
|
|
267
258
|
MediaProjectionManager mediaProjectionManager =
|
|
268
|
-
|
|
269
|
-
|
|
259
|
+
(MediaProjectionManager) currentActivity.getApplication().getSystemService(
|
|
260
|
+
Context.MEDIA_PROJECTION_SERVICE);
|
|
270
261
|
|
|
271
262
|
if (mediaProjectionManager != null) {
|
|
272
263
|
UiThreadUtil.runOnUiThread(new Runnable() {
|
|
273
264
|
@Override
|
|
274
265
|
public void run() {
|
|
275
266
|
currentActivity.startActivityForResult(
|
|
276
|
-
|
|
267
|
+
mediaProjectionManager.createScreenCaptureIntent(), PERMISSION_REQUEST_CODE);
|
|
277
268
|
}
|
|
278
269
|
});
|
|
279
270
|
|
|
@@ -288,7 +279,7 @@ class GetUserMediaImpl {
|
|
|
288
279
|
if (track == null) {
|
|
289
280
|
displayMediaPromise.reject(new RuntimeException("ScreenTrack is null."));
|
|
290
281
|
} else {
|
|
291
|
-
createStream(new MediaStreamTrack[]{track}, (streamId, tracksInfo) -> {
|
|
282
|
+
createStream(new MediaStreamTrack[] {track}, (streamId, tracksInfo) -> {
|
|
292
283
|
WritableMap data = Arguments.createMap();
|
|
293
284
|
|
|
294
285
|
data.putString("streamId", streamId);
|
|
@@ -307,7 +298,7 @@ class GetUserMediaImpl {
|
|
|
307
298
|
displayMediaPromise = null;
|
|
308
299
|
}
|
|
309
300
|
|
|
310
|
-
|
|
301
|
+
void createStream(MediaStreamTrack[] tracks, BiConsumer<String, ArrayList<WritableMap>> successCallback) {
|
|
311
302
|
String streamId = UUID.randomUUID().toString();
|
|
312
303
|
MediaStream mediaStream = webRTCModule.mFactory.createLocalMediaStream(streamId);
|
|
313
304
|
|
|
@@ -357,12 +348,12 @@ class GetUserMediaImpl {
|
|
|
357
348
|
DisplayMetrics displayMetrics = DisplayUtils.getDisplayMetrics(reactContext.getCurrentActivity());
|
|
358
349
|
int width = displayMetrics.widthPixels;
|
|
359
350
|
int height = displayMetrics.heightPixels;
|
|
360
|
-
ScreenCaptureController screenCaptureController
|
|
361
|
-
|
|
351
|
+
ScreenCaptureController screenCaptureController = new ScreenCaptureController(
|
|
352
|
+
reactContext.getCurrentActivity(), width, height, mediaProjectionPermissionResultData);
|
|
362
353
|
return createVideoTrack(screenCaptureController);
|
|
363
354
|
}
|
|
364
355
|
|
|
365
|
-
|
|
356
|
+
VideoTrack createVideoTrack(AbstractVideoCaptureController videoCaptureController) {
|
|
366
357
|
videoCaptureController.initializeVideoCapturer();
|
|
367
358
|
|
|
368
359
|
VideoCapturer videoCapturer = videoCaptureController.videoCapturer;
|
|
@@ -372,18 +363,21 @@ class GetUserMediaImpl {
|
|
|
372
363
|
|
|
373
364
|
PeerConnectionFactory pcFactory = webRTCModule.mFactory;
|
|
374
365
|
EglBase.Context eglContext = EglUtils.getRootEglBaseContext();
|
|
375
|
-
SurfaceTextureHelper surfaceTextureHelper =
|
|
376
|
-
SurfaceTextureHelper.create("CaptureThread", eglContext);
|
|
366
|
+
SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglContext);
|
|
377
367
|
|
|
378
368
|
if (surfaceTextureHelper == null) {
|
|
379
369
|
Log.d(TAG, "Error creating SurfaceTextureHelper");
|
|
380
370
|
return null;
|
|
381
371
|
}
|
|
382
372
|
|
|
373
|
+
String id = UUID.randomUUID().toString();
|
|
374
|
+
|
|
375
|
+
TrackCapturerEventsEmitter eventsEmitter = new TrackCapturerEventsEmitter(webRTCModule, id);
|
|
376
|
+
videoCaptureController.setCapturerEventsListener(eventsEmitter);
|
|
377
|
+
|
|
383
378
|
VideoSource videoSource = pcFactory.createVideoSource(videoCapturer.isScreencast());
|
|
384
379
|
videoCapturer.initialize(surfaceTextureHelper, reactContext, videoSource.getCapturerObserver());
|
|
385
380
|
|
|
386
|
-
String id = UUID.randomUUID().toString();
|
|
387
381
|
VideoTrack track = pcFactory.createVideoTrack(id, videoSource);
|
|
388
382
|
|
|
389
383
|
track.setEnabled(true);
|
|
@@ -415,14 +409,13 @@ class GetUserMediaImpl {
|
|
|
415
409
|
return;
|
|
416
410
|
}
|
|
417
411
|
|
|
418
|
-
VideoEffectProcessor videoEffectProcessor =
|
|
419
|
-
surfaceTextureHelper);
|
|
412
|
+
VideoEffectProcessor videoEffectProcessor =
|
|
413
|
+
new VideoEffectProcessor(videoFrameProcessor, surfaceTextureHelper);
|
|
420
414
|
videoSource.setVideoProcessor(videoEffectProcessor);
|
|
421
415
|
|
|
422
416
|
} else {
|
|
423
417
|
videoSource.setVideoProcessor(null);
|
|
424
418
|
}
|
|
425
|
-
|
|
426
419
|
}
|
|
427
420
|
}
|
|
428
421
|
|
|
@@ -443,7 +436,7 @@ class GetUserMediaImpl {
|
|
|
443
436
|
* if {@link #track} is a {@link VideoTrack}.
|
|
444
437
|
*/
|
|
445
438
|
public final AbstractVideoCaptureController videoCaptureController;
|
|
446
|
-
|
|
439
|
+
|
|
447
440
|
private final SurfaceTextureHelper surfaceTextureHelper;
|
|
448
441
|
|
|
449
442
|
/**
|
|
@@ -461,11 +454,8 @@ class GetUserMediaImpl {
|
|
|
461
454
|
* specified {@code mediaSource} was created if the specified
|
|
462
455
|
* {@code track} is a {@link VideoTrack}
|
|
463
456
|
*/
|
|
464
|
-
public TrackPrivate(
|
|
465
|
-
|
|
466
|
-
MediaSource mediaSource,
|
|
467
|
-
AbstractVideoCaptureController videoCaptureController,
|
|
468
|
-
SurfaceTextureHelper surfaceTextureHelper) {
|
|
457
|
+
public TrackPrivate(MediaStreamTrack track, MediaSource mediaSource,
|
|
458
|
+
AbstractVideoCaptureController videoCaptureController, SurfaceTextureHelper surfaceTextureHelper) {
|
|
469
459
|
this.track = track;
|
|
470
460
|
this.mediaSource = mediaSource;
|
|
471
461
|
this.videoCaptureController = videoCaptureController;
|
|
@@ -480,18 +470,18 @@ class GetUserMediaImpl {
|
|
|
480
470
|
videoCaptureController.dispose();
|
|
481
471
|
}
|
|
482
472
|
}
|
|
483
|
-
|
|
473
|
+
|
|
484
474
|
/*
|
|
485
475
|
* As per webrtc library documentation - The caller still has ownership of {@code
|
|
486
476
|
* surfaceTextureHelper} and is responsible for making sure surfaceTextureHelper.dispose() is
|
|
487
477
|
* called. This also means that the caller can reuse the SurfaceTextureHelper to initialize a new
|
|
488
478
|
* VideoCapturer once the previous VideoCapturer has been disposed. */
|
|
489
|
-
|
|
490
|
-
if(surfaceTextureHelper != null) {
|
|
479
|
+
|
|
480
|
+
if (surfaceTextureHelper != null) {
|
|
491
481
|
surfaceTextureHelper.stopListening();
|
|
492
482
|
surfaceTextureHelper.dispose();
|
|
493
483
|
}
|
|
494
|
-
|
|
484
|
+
|
|
495
485
|
mediaSource.dispose();
|
|
496
486
|
track.dispose();
|
|
497
487
|
disposed = true;
|
|
@@ -499,7 +489,7 @@ class GetUserMediaImpl {
|
|
|
499
489
|
}
|
|
500
490
|
}
|
|
501
491
|
|
|
502
|
-
|
|
492
|
+
public interface BiConsumer<T, U> {
|
|
503
493
|
void accept(T t, U u);
|
|
504
494
|
}
|
|
505
495
|
}
|