react-native-webrtc 106.0.5 → 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/LICENSE +2 -1
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +0 -1
- package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +7 -15
- package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +3 -12
- 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 +29 -43
- 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 +11 -13
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +116 -119
- 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 +3 -4
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +5 -9
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +335 -350
- 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 +2 -9
- package/ios/RCTWebRTC/CaptureController.m +0 -7
- 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 +205 -214
- package/ios/RCTWebRTC/ScreenCaptureController.h +2 -9
- package/ios/RCTWebRTC/ScreenCaptureController.m +10 -16
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.h +0 -7
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +26 -34
- package/ios/RCTWebRTC/ScreenCapturer.h +1 -8
- package/ios/RCTWebRTC/ScreenCapturer.m +56 -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 +4 -4
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +5 -6
- 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 +3 -2
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +196 -226
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +7 -14
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +625 -603
- 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 +13 -20
- package/ios/RCTWebRTC/WebRTCModule.m +69 -84
- package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/RTCPeerConnection.js +79 -56
- 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/RTCPeerConnection.js +79 -56
- 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/RTCPeerConnection.d.ts +4 -4
- package/package.json +3 -2
- package/src/RTCPeerConnection.ts +70 -63
- 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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
package com.oney.WebRTCModule;
|
|
2
2
|
|
|
3
|
-
import androidx.annotation.NonNull;
|
|
4
|
-
import androidx.annotation.Nullable;
|
|
5
|
-
|
|
6
3
|
import android.util.Log;
|
|
7
4
|
import android.util.SparseArray;
|
|
8
5
|
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
import androidx.annotation.Nullable;
|
|
8
|
+
|
|
9
9
|
import com.facebook.react.bridge.Arguments;
|
|
10
10
|
import com.facebook.react.bridge.Callback;
|
|
11
11
|
import com.facebook.react.bridge.Promise;
|
|
@@ -16,11 +16,15 @@ import com.facebook.react.bridge.ReadableArray;
|
|
|
16
16
|
import com.facebook.react.bridge.ReadableMap;
|
|
17
17
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
18
18
|
import com.facebook.react.bridge.ReadableType;
|
|
19
|
-
import com.facebook.react.bridge.WritableMap;
|
|
20
19
|
import com.facebook.react.bridge.WritableArray;
|
|
20
|
+
import com.facebook.react.bridge.WritableMap;
|
|
21
21
|
import com.facebook.react.module.annotations.ReactModule;
|
|
22
22
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
23
23
|
|
|
24
|
+
import org.webrtc.*;
|
|
25
|
+
import org.webrtc.audio.AudioDeviceModule;
|
|
26
|
+
import org.webrtc.audio.JavaAudioDeviceModule;
|
|
27
|
+
|
|
24
28
|
import java.util.ArrayList;
|
|
25
29
|
import java.util.HashMap;
|
|
26
30
|
import java.util.List;
|
|
@@ -29,10 +33,6 @@ import java.util.Objects;
|
|
|
29
33
|
import java.util.concurrent.Callable;
|
|
30
34
|
import java.util.concurrent.ExecutionException;
|
|
31
35
|
|
|
32
|
-
import org.webrtc.*;
|
|
33
|
-
import org.webrtc.audio.AudioDeviceModule;
|
|
34
|
-
import org.webrtc.audio.JavaAudioDeviceModule;
|
|
35
|
-
|
|
36
36
|
@ReactModule(name = "WebRTCModule")
|
|
37
37
|
public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
38
38
|
static final String TAG = WebRTCModule.class.getCanonicalName();
|
|
@@ -101,11 +101,10 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
101
101
|
loggingSeverity = options.loggingSeverity;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
PeerConnectionFactory.initialize(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
.createInitializationOptions());
|
|
104
|
+
PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions.builder(reactContext)
|
|
105
|
+
.setNativeLibraryLoader(new LibraryLoader())
|
|
106
|
+
.setInjectableLogger(injectableLogger, loggingSeverity)
|
|
107
|
+
.createInitializationOptions());
|
|
109
108
|
|
|
110
109
|
if (injectableLogger == null && loggingSeverity != null) {
|
|
111
110
|
Logging.enableLogToDebugOutput(loggingSeverity);
|
|
@@ -116,11 +115,9 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
116
115
|
EglBase.Context eglContext = EglUtils.getRootEglBaseContext();
|
|
117
116
|
|
|
118
117
|
if (eglContext != null) {
|
|
119
|
-
encoderFactory
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
/* enableIntelVp8Encoder */ true,
|
|
123
|
-
/* enableH264HighProfile */ false);
|
|
118
|
+
encoderFactory = new DefaultVideoEncoderFactory(eglContext,
|
|
119
|
+
/* enableIntelVp8Encoder */ true,
|
|
120
|
+
/* enableH264HighProfile */ false);
|
|
124
121
|
decoderFactory = new DefaultVideoDecoderFactory(eglContext);
|
|
125
122
|
} else {
|
|
126
123
|
encoderFactory = new SoftwareVideoEncoderFactory();
|
|
@@ -129,17 +126,14 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
129
126
|
}
|
|
130
127
|
|
|
131
128
|
if (adm == null) {
|
|
132
|
-
adm = JavaAudioDeviceModule.builder(reactContext)
|
|
133
|
-
.setEnableVolumeLogger(false)
|
|
134
|
-
.createAudioDeviceModule();
|
|
129
|
+
adm = JavaAudioDeviceModule.builder(reactContext).setEnableVolumeLogger(false).createAudioDeviceModule();
|
|
135
130
|
}
|
|
136
131
|
|
|
137
|
-
mFactory
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
.createPeerConnectionFactory();
|
|
132
|
+
mFactory = PeerConnectionFactory.builder()
|
|
133
|
+
.setAudioDeviceModule(adm)
|
|
134
|
+
.setVideoEncoderFactory(encoderFactory)
|
|
135
|
+
.setVideoDecoderFactory(decoderFactory)
|
|
136
|
+
.createPeerConnectionFactory();
|
|
143
137
|
|
|
144
138
|
// Saving the encoder and decoder factories to get codec info later when needed
|
|
145
139
|
mVideoEncoderFactory = encoderFactory;
|
|
@@ -161,8 +155,8 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
161
155
|
|
|
162
156
|
void sendEvent(String eventName, @Nullable ReadableMap params) {
|
|
163
157
|
getReactApplicationContext()
|
|
164
|
-
|
|
165
|
-
|
|
158
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
159
|
+
.emit(eventName, params);
|
|
166
160
|
}
|
|
167
161
|
|
|
168
162
|
private PeerConnection.IceServer createIceServer(String url) {
|
|
@@ -170,10 +164,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
170
164
|
}
|
|
171
165
|
|
|
172
166
|
private PeerConnection.IceServer createIceServer(String url, String username, String credential) {
|
|
173
|
-
return PeerConnection.IceServer.builder(url)
|
|
174
|
-
.setUsername(username)
|
|
175
|
-
.setPassword(credential)
|
|
176
|
-
.createIceServer();
|
|
167
|
+
return PeerConnection.IceServer.builder(url).setUsername(username).setPassword(credential).createIceServer();
|
|
177
168
|
}
|
|
178
169
|
|
|
179
170
|
private List<PeerConnection.IceServer> createIceServers(ReadableArray iceServersArray) {
|
|
@@ -186,7 +177,9 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
186
177
|
switch (iceServerMap.getType("urls")) {
|
|
187
178
|
case String:
|
|
188
179
|
if (hasUsernameAndCredential) {
|
|
189
|
-
iceServers.add(createIceServer(iceServerMap.getString("urls"),
|
|
180
|
+
iceServers.add(createIceServer(iceServerMap.getString("urls"),
|
|
181
|
+
iceServerMap.getString("username"),
|
|
182
|
+
iceServerMap.getString("credential")));
|
|
190
183
|
} else {
|
|
191
184
|
iceServers.add(createIceServer(iceServerMap.getString("urls")));
|
|
192
185
|
}
|
|
@@ -196,7 +189,8 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
196
189
|
for (int j = 0; j < urls.size(); j++) {
|
|
197
190
|
String url = urls.getString(j);
|
|
198
191
|
if (hasUsernameAndCredential) {
|
|
199
|
-
iceServers.add(createIceServer(
|
|
192
|
+
iceServers.add(createIceServer(
|
|
193
|
+
url, iceServerMap.getString("username"), iceServerMap.getString("credential")));
|
|
200
194
|
} else {
|
|
201
195
|
iceServers.add(createIceServer(url));
|
|
202
196
|
}
|
|
@@ -230,53 +224,51 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
230
224
|
final String v = map.getString("iceTransportPolicy");
|
|
231
225
|
if (v != null) {
|
|
232
226
|
switch (v) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
227
|
+
case "all": // public
|
|
228
|
+
conf.iceTransportsType = PeerConnection.IceTransportsType.ALL;
|
|
229
|
+
break;
|
|
230
|
+
case "relay": // public
|
|
231
|
+
conf.iceTransportsType = PeerConnection.IceTransportsType.RELAY;
|
|
232
|
+
break;
|
|
233
|
+
case "nohost":
|
|
234
|
+
conf.iceTransportsType = PeerConnection.IceTransportsType.NOHOST;
|
|
235
|
+
break;
|
|
236
|
+
case "none":
|
|
237
|
+
conf.iceTransportsType = PeerConnection.IceTransportsType.NONE;
|
|
238
|
+
break;
|
|
245
239
|
}
|
|
246
240
|
}
|
|
247
241
|
}
|
|
248
242
|
|
|
249
243
|
// bundlePolicy (public api)
|
|
250
|
-
if (map.hasKey("bundlePolicy")
|
|
251
|
-
&& map.getType("bundlePolicy") == ReadableType.String) {
|
|
244
|
+
if (map.hasKey("bundlePolicy") && map.getType("bundlePolicy") == ReadableType.String) {
|
|
252
245
|
final String v = map.getString("bundlePolicy");
|
|
253
246
|
if (v != null) {
|
|
254
247
|
switch (v) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
248
|
+
case "balanced": // public
|
|
249
|
+
conf.bundlePolicy = PeerConnection.BundlePolicy.BALANCED;
|
|
250
|
+
break;
|
|
251
|
+
case "max-compat": // public
|
|
252
|
+
conf.bundlePolicy = PeerConnection.BundlePolicy.MAXCOMPAT;
|
|
253
|
+
break;
|
|
254
|
+
case "max-bundle": // public
|
|
255
|
+
conf.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
|
|
256
|
+
break;
|
|
264
257
|
}
|
|
265
258
|
}
|
|
266
259
|
}
|
|
267
260
|
|
|
268
261
|
// rtcpMuxPolicy (public api)
|
|
269
|
-
if (map.hasKey("rtcpMuxPolicy")
|
|
270
|
-
&& map.getType("rtcpMuxPolicy") == ReadableType.String) {
|
|
262
|
+
if (map.hasKey("rtcpMuxPolicy") && map.getType("rtcpMuxPolicy") == ReadableType.String) {
|
|
271
263
|
final String v = map.getString("rtcpMuxPolicy");
|
|
272
264
|
if (v != null) {
|
|
273
265
|
switch (v) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
266
|
+
case "negotiate": // public
|
|
267
|
+
conf.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.NEGOTIATE;
|
|
268
|
+
break;
|
|
269
|
+
case "require": // public
|
|
270
|
+
conf.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
|
|
271
|
+
break;
|
|
280
272
|
}
|
|
281
273
|
}
|
|
282
274
|
}
|
|
@@ -285,8 +277,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
285
277
|
// FIXME: certificates of type sequence<RTCCertificate> (public api)
|
|
286
278
|
|
|
287
279
|
// iceCandidatePoolSize of type unsigned short, defaulting to 0
|
|
288
|
-
if (map.hasKey("iceCandidatePoolSize")
|
|
289
|
-
&& map.getType("iceCandidatePoolSize") == ReadableType.Number) {
|
|
280
|
+
if (map.hasKey("iceCandidatePoolSize") && map.getType("iceCandidatePoolSize") == ReadableType.Number) {
|
|
290
281
|
final int v = map.getInt("iceCandidatePoolSize");
|
|
291
282
|
if (v > 0) {
|
|
292
283
|
conf.iceCandidatePoolSize = v;
|
|
@@ -296,65 +287,61 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
296
287
|
// === below is private api in webrtc ===
|
|
297
288
|
|
|
298
289
|
// tcpCandidatePolicy (private api)
|
|
299
|
-
if (map.hasKey("tcpCandidatePolicy")
|
|
300
|
-
&& map.getType("tcpCandidatePolicy") == ReadableType.String) {
|
|
290
|
+
if (map.hasKey("tcpCandidatePolicy") && map.getType("tcpCandidatePolicy") == ReadableType.String) {
|
|
301
291
|
final String v = map.getString("tcpCandidatePolicy");
|
|
302
292
|
if (v != null) {
|
|
303
293
|
switch (v) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
294
|
+
case "enabled":
|
|
295
|
+
conf.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.ENABLED;
|
|
296
|
+
break;
|
|
297
|
+
case "disabled":
|
|
298
|
+
conf.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED;
|
|
299
|
+
break;
|
|
310
300
|
}
|
|
311
301
|
}
|
|
312
302
|
}
|
|
313
303
|
|
|
314
304
|
// candidateNetworkPolicy (private api)
|
|
315
|
-
if (map.hasKey("candidateNetworkPolicy")
|
|
316
|
-
&& map.getType("candidateNetworkPolicy") == ReadableType.String) {
|
|
305
|
+
if (map.hasKey("candidateNetworkPolicy") && map.getType("candidateNetworkPolicy") == ReadableType.String) {
|
|
317
306
|
final String v = map.getString("candidateNetworkPolicy");
|
|
318
307
|
if (v != null) {
|
|
319
308
|
switch (v) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
309
|
+
case "all":
|
|
310
|
+
conf.candidateNetworkPolicy = PeerConnection.CandidateNetworkPolicy.ALL;
|
|
311
|
+
break;
|
|
312
|
+
case "low_cost":
|
|
313
|
+
conf.candidateNetworkPolicy = PeerConnection.CandidateNetworkPolicy.LOW_COST;
|
|
314
|
+
break;
|
|
326
315
|
}
|
|
327
316
|
}
|
|
328
317
|
}
|
|
329
318
|
|
|
330
319
|
// KeyType (private api)
|
|
331
|
-
if (map.hasKey("keyType")
|
|
332
|
-
&& map.getType("keyType") == ReadableType.String) {
|
|
320
|
+
if (map.hasKey("keyType") && map.getType("keyType") == ReadableType.String) {
|
|
333
321
|
final String v = map.getString("keyType");
|
|
334
322
|
if (v != null) {
|
|
335
323
|
switch (v) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
324
|
+
case "RSA":
|
|
325
|
+
conf.keyType = PeerConnection.KeyType.RSA;
|
|
326
|
+
break;
|
|
327
|
+
case "ECDSA":
|
|
328
|
+
conf.keyType = PeerConnection.KeyType.ECDSA;
|
|
329
|
+
break;
|
|
342
330
|
}
|
|
343
331
|
}
|
|
344
332
|
}
|
|
345
333
|
|
|
346
334
|
// continualGatheringPolicy (private api)
|
|
347
|
-
if (map.hasKey("continualGatheringPolicy")
|
|
348
|
-
&& map.getType("continualGatheringPolicy") == ReadableType.String) {
|
|
335
|
+
if (map.hasKey("continualGatheringPolicy") && map.getType("continualGatheringPolicy") == ReadableType.String) {
|
|
349
336
|
final String v = map.getString("continualGatheringPolicy");
|
|
350
337
|
if (v != null) {
|
|
351
338
|
switch (v) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
339
|
+
case "gather_once":
|
|
340
|
+
conf.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_ONCE;
|
|
341
|
+
break;
|
|
342
|
+
case "gather_continually":
|
|
343
|
+
conf.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
|
|
344
|
+
break;
|
|
358
345
|
}
|
|
359
346
|
}
|
|
360
347
|
}
|
|
@@ -390,8 +377,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
390
377
|
}
|
|
391
378
|
|
|
392
379
|
// pruneTurnPorts (private api)
|
|
393
|
-
if (map.hasKey("pruneTurnPorts")
|
|
394
|
-
&& map.getType("pruneTurnPorts") == ReadableType.Boolean) {
|
|
380
|
+
if (map.hasKey("pruneTurnPorts") && map.getType("pruneTurnPorts") == ReadableType.Boolean) {
|
|
395
381
|
final boolean v = map.getBoolean("pruneTurnPorts");
|
|
396
382
|
conf.pruneTurnPorts = v;
|
|
397
383
|
}
|
|
@@ -411,12 +397,14 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
411
397
|
PeerConnection.RTCConfiguration rtcConfiguration = parseRTCConfiguration(configuration);
|
|
412
398
|
|
|
413
399
|
try {
|
|
414
|
-
ThreadUtils
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
400
|
+
ThreadUtils
|
|
401
|
+
.submitToExecutor(() -> {
|
|
402
|
+
PeerConnectionObserver observer = new PeerConnectionObserver(this, id);
|
|
403
|
+
PeerConnection peerConnection = mFactory.createPeerConnection(rtcConfiguration, observer);
|
|
404
|
+
observer.setPeerConnection(peerConnection);
|
|
405
|
+
mPeerConnectionObservers.put(id, observer);
|
|
406
|
+
})
|
|
407
|
+
.get();
|
|
420
408
|
} catch (ExecutionException | InterruptedException e) {
|
|
421
409
|
e.printStackTrace();
|
|
422
410
|
throw new RuntimeException(e);
|
|
@@ -428,23 +416,25 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
428
416
|
// Hence make sure we run this code in the executor or we run at the risk
|
|
429
417
|
// of being out of sync.
|
|
430
418
|
try {
|
|
431
|
-
return (MediaStream) ThreadUtils
|
|
432
|
-
|
|
419
|
+
return (MediaStream) ThreadUtils
|
|
420
|
+
.submitToExecutor((Callable<Object>) () -> {
|
|
421
|
+
MediaStream stream = localStreams.get(streamReactTag);
|
|
433
422
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
423
|
+
if (stream != null) {
|
|
424
|
+
return stream;
|
|
425
|
+
}
|
|
437
426
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
427
|
+
for (int i = 0, size = mPeerConnectionObservers.size(); i < size; i++) {
|
|
428
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.valueAt(i);
|
|
429
|
+
stream = pco.remoteStreams.get(streamReactTag);
|
|
430
|
+
if (stream != null) {
|
|
431
|
+
return stream;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
445
434
|
|
|
446
|
-
|
|
447
|
-
|
|
435
|
+
return null;
|
|
436
|
+
})
|
|
437
|
+
.get();
|
|
448
438
|
} catch (ExecutionException | InterruptedException e) {
|
|
449
439
|
return null;
|
|
450
440
|
}
|
|
@@ -474,7 +464,8 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
474
464
|
return getUserMediaImpl.createVideoTrack(videoCaptureController);
|
|
475
465
|
}
|
|
476
466
|
|
|
477
|
-
public void createStream(
|
|
467
|
+
public void createStream(
|
|
468
|
+
MediaStreamTrack[] tracks, GetUserMediaImpl.BiConsumer<String, ArrayList<WritableMap>> successCallback) {
|
|
478
469
|
getUserMediaImpl.createStream(tracks, successCallback);
|
|
479
470
|
}
|
|
480
471
|
|
|
@@ -501,46 +492,46 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
501
492
|
return mediaConstraints;
|
|
502
493
|
}
|
|
503
494
|
|
|
504
|
-
|
|
505
|
-
|
|
506
495
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
507
496
|
public WritableMap peerConnectionAddTransceiver(int id, ReadableMap options) {
|
|
508
497
|
try {
|
|
509
|
-
return (WritableMap) ThreadUtils
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
498
|
+
return (WritableMap) ThreadUtils
|
|
499
|
+
.submitToExecutor((Callable<Object>) () -> {
|
|
500
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
501
|
+
if (pco == null) {
|
|
502
|
+
Log.d(TAG, "peerConnectionAddTransceiver() peerConnection is null");
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
515
505
|
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
} else {
|
|
528
|
-
// This should technically never happen as the JS side checks for that.
|
|
529
|
-
Log.d(TAG, "peerConnectionAddTransceiver() no type nor trackId provided in options");
|
|
530
|
-
return null;
|
|
531
|
-
}
|
|
506
|
+
RtpTransceiver transceiver = null;
|
|
507
|
+
if (options.hasKey("type")) {
|
|
508
|
+
String kind = options.getString("type");
|
|
509
|
+
transceiver = pco.addTransceiver(SerializeUtils.parseMediaType(kind),
|
|
510
|
+
SerializeUtils.parseTransceiverOptions(options.getMap("init")));
|
|
511
|
+
} else if (options.hasKey("trackId")) {
|
|
512
|
+
String trackId = options.getString("trackId");
|
|
513
|
+
MediaStreamTrack track = getTrack(trackId);
|
|
514
|
+
transceiver = pco.addTransceiver(
|
|
515
|
+
track, SerializeUtils.parseTransceiverOptions(options.getMap("init")));
|
|
532
516
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
517
|
+
} else {
|
|
518
|
+
// This should technically never happen as the JS side checks for that.
|
|
519
|
+
Log.d(TAG, "peerConnectionAddTransceiver() no type nor trackId provided in options");
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (transceiver == null) {
|
|
524
|
+
Log.d(TAG, "peerConnectionAddTransceiver() Error adding transceiver");
|
|
525
|
+
return null;
|
|
526
|
+
}
|
|
527
|
+
WritableMap params = Arguments.createMap();
|
|
528
|
+
// We need to get a unique order at which the transceiver was created
|
|
529
|
+
// to reorder the cached array of transceivers on the JS layer.
|
|
530
|
+
params.putInt("transceiverOrder", pco.getNextTransceiverId());
|
|
531
|
+
params.putMap("transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
|
|
532
|
+
return params;
|
|
533
|
+
})
|
|
534
|
+
.get();
|
|
544
535
|
} catch (InterruptedException | ExecutionException e) {
|
|
545
536
|
Log.d(TAG, "peerConnectionAddTransceiver() " + e.getMessage());
|
|
546
537
|
return null;
|
|
@@ -548,45 +539,45 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
548
539
|
}
|
|
549
540
|
|
|
550
541
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
551
|
-
public WritableMap peerConnectionAddTrack(int id,
|
|
552
|
-
String trackId,
|
|
553
|
-
ReadableMap options) {
|
|
542
|
+
public WritableMap peerConnectionAddTrack(int id, String trackId, ReadableMap options) {
|
|
554
543
|
try {
|
|
555
|
-
return (WritableMap) ThreadUtils
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
544
|
+
return (WritableMap) ThreadUtils
|
|
545
|
+
.submitToExecutor((Callable<Object>) () -> {
|
|
546
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
547
|
+
if (pco == null) {
|
|
548
|
+
Log.d(TAG, "peerConnectionAddTrack() peerConnection is null");
|
|
549
|
+
return null;
|
|
550
|
+
}
|
|
561
551
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
552
|
+
MediaStreamTrack track = getLocalTrack(trackId);
|
|
553
|
+
if (track == null) {
|
|
554
|
+
Log.w(TAG, "peerConnectionAddTrack() couldn't find track " + trackId);
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
567
557
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
558
|
+
List<String> streamIds = new ArrayList<>();
|
|
559
|
+
if (options.hasKey("streamIds")) {
|
|
560
|
+
ReadableArray rawStreamIds = options.getArray("streamIds");
|
|
561
|
+
if (rawStreamIds != null) {
|
|
562
|
+
for (int i = 0; i < rawStreamIds.size(); i++) {
|
|
563
|
+
streamIds.add(rawStreamIds.getString(i));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
574
566
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}).get();
|
|
567
|
+
RtpSender sender = pco.getPeerConnection().addTrack(track, streamIds);
|
|
568
|
+
|
|
569
|
+
// Need to get the corresponding transceiver as well
|
|
570
|
+
RtpTransceiver transceiver = pco.getTransceiver(sender.id());
|
|
571
|
+
|
|
572
|
+
// We need the transceiver creation order to reorder the transceivers array
|
|
573
|
+
// in the JS layer.
|
|
574
|
+
WritableMap params = Arguments.createMap();
|
|
575
|
+
params.putInt("transceiverOrder", pco.getNextTransceiverId());
|
|
576
|
+
params.putMap("transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
|
|
577
|
+
params.putMap("sender", SerializeUtils.serializeSender(id, sender));
|
|
578
|
+
return params;
|
|
579
|
+
})
|
|
580
|
+
.get();
|
|
590
581
|
} catch (InterruptedException | ExecutionException e) {
|
|
591
582
|
Log.d(TAG, "peerConnectionAddTrack() " + e.getMessage());
|
|
592
583
|
return null;
|
|
@@ -596,20 +587,22 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
596
587
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
597
588
|
public boolean peerConnectionRemoveTrack(int id, String senderId) {
|
|
598
589
|
try {
|
|
599
|
-
return (boolean) ThreadUtils
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
590
|
+
return (boolean) ThreadUtils
|
|
591
|
+
.submitToExecutor((Callable<Object>) () -> {
|
|
592
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
593
|
+
if (pco == null) {
|
|
594
|
+
Log.d(TAG, "peerConnectionRemoveTrack() peerConnection is null");
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
RtpSender sender = pco.getSender(senderId);
|
|
598
|
+
if (sender == null) {
|
|
599
|
+
Log.w(TAG, "peerConnectionRemoveTrack() sender is null");
|
|
600
|
+
return false;
|
|
601
|
+
}
|
|
610
602
|
|
|
611
|
-
|
|
612
|
-
|
|
603
|
+
return pco.getPeerConnection().removeTrack(sender);
|
|
604
|
+
})
|
|
605
|
+
.get();
|
|
613
606
|
} catch (InterruptedException | ExecutionException e) {
|
|
614
607
|
Log.d(TAG, "peerConnectionRemoveTrack() " + e.getMessage());
|
|
615
608
|
return false;
|
|
@@ -618,7 +611,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
618
611
|
|
|
619
612
|
@ReactMethod
|
|
620
613
|
public void senderSetParameters(int id, String senderId, ReadableMap options, Promise promise) {
|
|
621
|
-
ThreadUtils.runOnExecutor(() ->{
|
|
614
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
622
615
|
try {
|
|
623
616
|
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
624
617
|
if (pco == null) {
|
|
@@ -672,10 +665,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
672
665
|
}
|
|
673
666
|
|
|
674
667
|
@ReactMethod
|
|
675
|
-
public void senderReplaceTrack(int id,
|
|
676
|
-
String senderId,
|
|
677
|
-
String trackId,
|
|
678
|
-
Promise promise) {
|
|
668
|
+
public void senderReplaceTrack(int id, String senderId, String trackId, Promise promise) {
|
|
679
669
|
ThreadUtils.runOnExecutor(() -> {
|
|
680
670
|
try {
|
|
681
671
|
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
@@ -703,11 +693,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
703
693
|
}
|
|
704
694
|
|
|
705
695
|
@ReactMethod
|
|
706
|
-
public void transceiverSetDirection(int id,
|
|
707
|
-
String senderId,
|
|
708
|
-
String direction,
|
|
709
|
-
Promise promise) {
|
|
710
|
-
|
|
696
|
+
public void transceiverSetDirection(int id, String senderId, String direction, Promise promise) {
|
|
711
697
|
ThreadUtils.runOnExecutor(() -> {
|
|
712
698
|
WritableMap identifier = Arguments.createMap();
|
|
713
699
|
WritableMap params = Arguments.createMap();
|
|
@@ -721,7 +707,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
721
707
|
return;
|
|
722
708
|
}
|
|
723
709
|
RtpTransceiver transceiver = pco.getTransceiver(senderId);
|
|
724
|
-
if (transceiver == null){
|
|
710
|
+
if (transceiver == null) {
|
|
725
711
|
Log.d(TAG, "transceiverSetDirection() transceiver is null");
|
|
726
712
|
promise.reject(new Exception("Could not get sender"));
|
|
727
713
|
return;
|
|
@@ -743,17 +729,13 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
743
729
|
}
|
|
744
730
|
|
|
745
731
|
@ReactMethod
|
|
746
|
-
public void getUserMedia(ReadableMap constraints,
|
|
747
|
-
|
|
748
|
-
Callback errorCallback) {
|
|
749
|
-
ThreadUtils.runOnExecutor(() ->
|
|
750
|
-
getUserMediaImpl.getUserMedia(constraints, successCallback, errorCallback));
|
|
732
|
+
public void getUserMedia(ReadableMap constraints, Callback successCallback, Callback errorCallback) {
|
|
733
|
+
ThreadUtils.runOnExecutor(() -> getUserMediaImpl.getUserMedia(constraints, successCallback, errorCallback));
|
|
751
734
|
}
|
|
752
735
|
|
|
753
736
|
@ReactMethod
|
|
754
737
|
public void enumerateDevices(Callback callback) {
|
|
755
|
-
ThreadUtils.runOnExecutor(() ->
|
|
756
|
-
callback.invoke(getUserMediaImpl.enumerateDevices()));
|
|
738
|
+
ThreadUtils.runOnExecutor(() -> callback.invoke(getUserMediaImpl.enumerateDevices()));
|
|
757
739
|
}
|
|
758
740
|
|
|
759
741
|
@ReactMethod
|
|
@@ -777,9 +759,9 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
777
759
|
|
|
778
760
|
String kind = track.kind();
|
|
779
761
|
if ("audio".equals(kind)) {
|
|
780
|
-
stream.addTrack((AudioTrack)track);
|
|
762
|
+
stream.addTrack((AudioTrack) track);
|
|
781
763
|
} else if ("video".equals(kind)) {
|
|
782
|
-
stream.addTrack((VideoTrack)track);
|
|
764
|
+
stream.addTrack((VideoTrack) track);
|
|
783
765
|
}
|
|
784
766
|
});
|
|
785
767
|
}
|
|
@@ -797,9 +779,9 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
797
779
|
|
|
798
780
|
String kind = track.kind();
|
|
799
781
|
if ("audio".equals(kind)) {
|
|
800
|
-
stream.removeTrack((AudioTrack)track);
|
|
782
|
+
stream.removeTrack((AudioTrack) track);
|
|
801
783
|
} else if ("video".equals(kind)) {
|
|
802
|
-
stream.removeTrack((VideoTrack)track);
|
|
784
|
+
stream.removeTrack((VideoTrack) track);
|
|
803
785
|
}
|
|
804
786
|
});
|
|
805
787
|
}
|
|
@@ -862,7 +844,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
862
844
|
private ReadableArray getTransceiversInfo(PeerConnection peerConnection) {
|
|
863
845
|
WritableArray transceiverUpdates = Arguments.createArray();
|
|
864
846
|
|
|
865
|
-
for (RtpTransceiver transceiver: peerConnection.getTransceivers()) {
|
|
847
|
+
for (RtpTransceiver transceiver : peerConnection.getTransceivers()) {
|
|
866
848
|
RtpTransceiver.RtpTransceiverDirection direction = transceiver.getCurrentDirection();
|
|
867
849
|
if (direction == null) continue;
|
|
868
850
|
String directionSerialized = SerializeUtils.serializeDirection(direction);
|
|
@@ -870,12 +852,11 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
870
852
|
transceiverUpdate.putString("transceiverId", transceiver.getSender().id());
|
|
871
853
|
transceiverUpdate.putString("mid", transceiver.getMid());
|
|
872
854
|
transceiverUpdate.putString("currentDirection", directionSerialized);
|
|
855
|
+
transceiverUpdate.putBoolean("isStopped", transceiver.isStopped());
|
|
873
856
|
transceiverUpdate.putMap("senderRtpParameters",
|
|
874
|
-
|
|
875
|
-
transceiver.getSender().getParameters()));
|
|
857
|
+
SerializeUtils.serializeRtpParameters(transceiver.getSender().getParameters()));
|
|
876
858
|
transceiverUpdate.putMap("receiverRtpParameters",
|
|
877
|
-
|
|
878
|
-
transceiver.getReceiver().getParameters()));
|
|
859
|
+
SerializeUtils.serializeRtpParameters(transceiver.getReceiver().getParameters()));
|
|
879
860
|
transceiverUpdates.pushMap(transceiverUpdate);
|
|
880
861
|
}
|
|
881
862
|
return transceiverUpdates;
|
|
@@ -883,14 +864,11 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
883
864
|
|
|
884
865
|
@ReactMethod
|
|
885
866
|
public void mediaStreamTrackSetVideoEffect(String id, String name) {
|
|
886
|
-
ThreadUtils.runOnExecutor(() -> {
|
|
887
|
-
getUserMediaImpl.setVideoEffect(id, name);
|
|
888
|
-
});
|
|
867
|
+
ThreadUtils.runOnExecutor(() -> { getUserMediaImpl.setVideoEffect(id, name); });
|
|
889
868
|
}
|
|
890
869
|
|
|
891
870
|
@ReactMethod
|
|
892
|
-
public void peerConnectionSetConfiguration(ReadableMap configuration,
|
|
893
|
-
int id) {
|
|
871
|
+
public void peerConnectionSetConfiguration(ReadableMap configuration, int id) {
|
|
894
872
|
ThreadUtils.runOnExecutor(() -> {
|
|
895
873
|
PeerConnection peerConnection = getPeerConnection(id);
|
|
896
874
|
if (peerConnection == null) {
|
|
@@ -902,33 +880,36 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
902
880
|
}
|
|
903
881
|
|
|
904
882
|
@ReactMethod
|
|
905
|
-
public void peerConnectionCreateOffer(int id,
|
|
906
|
-
ReadableMap options,
|
|
907
|
-
Callback callback) {
|
|
883
|
+
public void peerConnectionCreateOffer(int id, ReadableMap options, Promise promise) {
|
|
908
884
|
ThreadUtils.runOnExecutor(() -> {
|
|
909
885
|
PeerConnection peerConnection = getPeerConnection(id);
|
|
910
886
|
|
|
911
887
|
if (peerConnection == null) {
|
|
912
888
|
Log.d(TAG, "peerConnectionCreateOffer() peerConnection is null");
|
|
913
|
-
|
|
889
|
+
promise.reject(new Exception("PeerConnection not found"));
|
|
914
890
|
return;
|
|
915
891
|
}
|
|
916
892
|
|
|
917
|
-
|
|
893
|
+
final SdpObserver observer = new SdpObserver() {
|
|
918
894
|
@Override
|
|
919
895
|
public void onCreateFailure(String s) {
|
|
920
|
-
|
|
896
|
+
ThreadUtils.runOnExecutor(() -> { promise.reject("E_OPERATION_ERROR", s); });
|
|
921
897
|
}
|
|
922
898
|
|
|
923
899
|
@Override
|
|
924
900
|
public void onCreateSuccess(SessionDescription sdp) {
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
901
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
902
|
+
WritableMap params = Arguments.createMap();
|
|
903
|
+
WritableMap sdpInfo = Arguments.createMap();
|
|
904
|
+
|
|
905
|
+
sdpInfo.putString("sdp", sdp.description);
|
|
906
|
+
sdpInfo.putString("type", sdp.type.canonicalForm());
|
|
907
|
+
|
|
908
|
+
params.putArray("transceiversInfo", getTransceiversInfo(peerConnection));
|
|
909
|
+
params.putMap("sdpInfo", sdpInfo);
|
|
910
|
+
|
|
911
|
+
promise.resolve(params);
|
|
912
|
+
});
|
|
932
913
|
}
|
|
933
914
|
|
|
934
915
|
@Override
|
|
@@ -936,38 +917,43 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
936
917
|
|
|
937
918
|
@Override
|
|
938
919
|
public void onSetSuccess() {}
|
|
939
|
-
}
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
peerConnection.createOffer(observer, constraintsForOptions(options));
|
|
940
923
|
});
|
|
941
924
|
}
|
|
942
925
|
|
|
943
926
|
@ReactMethod
|
|
944
|
-
public void peerConnectionCreateAnswer(int id,
|
|
945
|
-
ReadableMap options,
|
|
946
|
-
Callback callback) {
|
|
927
|
+
public void peerConnectionCreateAnswer(int id, ReadableMap options, Promise promise) {
|
|
947
928
|
ThreadUtils.runOnExecutor(() -> {
|
|
948
929
|
PeerConnection peerConnection = getPeerConnection(id);
|
|
949
930
|
|
|
950
931
|
if (peerConnection == null) {
|
|
951
932
|
Log.d(TAG, "peerConnectionCreateAnswer() peerConnection is null");
|
|
952
|
-
|
|
933
|
+
promise.reject(new Exception("PeerConnection not found"));
|
|
953
934
|
return;
|
|
954
935
|
}
|
|
955
936
|
|
|
956
|
-
|
|
937
|
+
final SdpObserver observer = new SdpObserver() {
|
|
957
938
|
@Override
|
|
958
939
|
public void onCreateFailure(String s) {
|
|
959
|
-
|
|
940
|
+
ThreadUtils.runOnExecutor(() -> { promise.reject("E_OPERATION_ERROR", s); });
|
|
960
941
|
}
|
|
961
942
|
|
|
962
943
|
@Override
|
|
963
944
|
public void onCreateSuccess(SessionDescription sdp) {
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
945
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
946
|
+
WritableMap params = Arguments.createMap();
|
|
947
|
+
WritableMap sdpInfo = Arguments.createMap();
|
|
948
|
+
|
|
949
|
+
sdpInfo.putString("sdp", sdp.description);
|
|
950
|
+
sdpInfo.putString("type", sdp.type.canonicalForm());
|
|
951
|
+
|
|
952
|
+
params.putArray("transceiversInfo", getTransceiversInfo(peerConnection));
|
|
953
|
+
params.putMap("sdpInfo", sdpInfo);
|
|
954
|
+
|
|
955
|
+
promise.resolve(params);
|
|
956
|
+
});
|
|
971
957
|
}
|
|
972
958
|
|
|
973
959
|
@Override
|
|
@@ -975,14 +961,14 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
975
961
|
|
|
976
962
|
@Override
|
|
977
963
|
public void onSetSuccess() {}
|
|
978
|
-
}
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
peerConnection.createAnswer(observer, constraintsForOptions(options));
|
|
979
967
|
});
|
|
980
968
|
}
|
|
981
969
|
|
|
982
970
|
@ReactMethod
|
|
983
|
-
public void peerConnectionSetLocalDescription(int pcId,
|
|
984
|
-
ReadableMap desc,
|
|
985
|
-
Promise promise) {
|
|
971
|
+
public void peerConnectionSetLocalDescription(int pcId, ReadableMap desc, Promise promise) {
|
|
986
972
|
ThreadUtils.runOnExecutor(() -> {
|
|
987
973
|
PeerConnection peerConnection = getPeerConnection(pcId);
|
|
988
974
|
if (peerConnection == null) {
|
|
@@ -993,8 +979,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
993
979
|
|
|
994
980
|
final SdpObserver observer = new SdpObserver() {
|
|
995
981
|
@Override
|
|
996
|
-
public void onCreateSuccess(SessionDescription sdp) {
|
|
997
|
-
}
|
|
982
|
+
public void onCreateSuccess(SessionDescription sdp) {}
|
|
998
983
|
|
|
999
984
|
@Override
|
|
1000
985
|
public void onSetSuccess() {
|
|
@@ -1017,22 +1002,18 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1017
1002
|
}
|
|
1018
1003
|
|
|
1019
1004
|
@Override
|
|
1020
|
-
public void onCreateFailure(String s) {
|
|
1021
|
-
}
|
|
1005
|
+
public void onCreateFailure(String s) {}
|
|
1022
1006
|
|
|
1023
1007
|
@Override
|
|
1024
1008
|
public void onSetFailure(String s) {
|
|
1025
|
-
ThreadUtils.runOnExecutor(() -> {
|
|
1026
|
-
promise.reject("E_OPERATION_ERROR", s);
|
|
1027
|
-
});
|
|
1009
|
+
ThreadUtils.runOnExecutor(() -> { promise.reject("E_OPERATION_ERROR", s); });
|
|
1028
1010
|
}
|
|
1029
1011
|
};
|
|
1030
1012
|
|
|
1031
1013
|
if (desc != null) {
|
|
1032
1014
|
SessionDescription sdp = new SessionDescription(
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
);
|
|
1015
|
+
SessionDescription.Type.fromCanonicalForm(Objects.requireNonNull(desc.getString("type"))),
|
|
1016
|
+
desc.getString("sdp"));
|
|
1036
1017
|
|
|
1037
1018
|
peerConnection.setLocalDescription(observer, sdp);
|
|
1038
1019
|
} else {
|
|
@@ -1042,13 +1023,11 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1042
1023
|
}
|
|
1043
1024
|
|
|
1044
1025
|
@ReactMethod
|
|
1045
|
-
public void peerConnectionSetRemoteDescription(int id,
|
|
1046
|
-
ReadableMap desc,
|
|
1047
|
-
Promise promise) {
|
|
1026
|
+
public void peerConnectionSetRemoteDescription(int id, ReadableMap desc, Promise promise) {
|
|
1048
1027
|
ThreadUtils.runOnExecutor(() -> {
|
|
1049
1028
|
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
1050
1029
|
PeerConnection peerConnection = pco.getPeerConnection();
|
|
1051
|
-
|
|
1030
|
+
|
|
1052
1031
|
if (peerConnection == null) {
|
|
1053
1032
|
Log.d(TAG, "peerConnectionSetRemoteDescription() peerConnection is null");
|
|
1054
1033
|
promise.reject(new Exception("PeerConnection not found"));
|
|
@@ -1056,19 +1035,16 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1056
1035
|
}
|
|
1057
1036
|
|
|
1058
1037
|
SessionDescription sdp = new SessionDescription(
|
|
1059
|
-
|
|
1060
|
-
desc.getString("sdp")
|
|
1061
|
-
);
|
|
1038
|
+
SessionDescription.Type.fromCanonicalForm(desc.getString("type")), desc.getString("sdp"));
|
|
1062
1039
|
|
|
1063
1040
|
List<String> receiversIds = new ArrayList<>();
|
|
1064
|
-
for(RtpTransceiver transceiver: peerConnection.getTransceivers()) {
|
|
1041
|
+
for (RtpTransceiver transceiver : peerConnection.getTransceivers()) {
|
|
1065
1042
|
receiversIds.add(transceiver.getReceiver().id());
|
|
1066
1043
|
}
|
|
1067
1044
|
|
|
1068
1045
|
final SdpObserver observer = new SdpObserver() {
|
|
1069
1046
|
@Override
|
|
1070
|
-
public void onCreateSuccess(final SessionDescription sdp) {
|
|
1071
|
-
}
|
|
1047
|
+
public void onCreateSuccess(final SessionDescription sdp) {}
|
|
1072
1048
|
|
|
1073
1049
|
@Override
|
|
1074
1050
|
public void onSetSuccess() {
|
|
@@ -1087,11 +1063,12 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1087
1063
|
params.putMap("sdpInfo", newSdpMap);
|
|
1088
1064
|
|
|
1089
1065
|
WritableArray newTransceivers = Arguments.createArray();
|
|
1090
|
-
for(RtpTransceiver transceiver: peerConnection.getTransceivers()) {
|
|
1091
|
-
if(!receiversIds.contains(transceiver.getReceiver().id())) {
|
|
1066
|
+
for (RtpTransceiver transceiver : peerConnection.getTransceivers()) {
|
|
1067
|
+
if (!receiversIds.contains(transceiver.getReceiver().id())) {
|
|
1092
1068
|
WritableMap newTransceiver = Arguments.createMap();
|
|
1093
1069
|
newTransceiver.putInt("transceiverOrder", pco.getNextTransceiverId());
|
|
1094
|
-
newTransceiver.putMap(
|
|
1070
|
+
newTransceiver.putMap(
|
|
1071
|
+
"transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
|
|
1095
1072
|
newTransceivers.pushMap(newTransceiver);
|
|
1096
1073
|
}
|
|
1097
1074
|
}
|
|
@@ -1103,14 +1080,11 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1103
1080
|
}
|
|
1104
1081
|
|
|
1105
1082
|
@Override
|
|
1106
|
-
public void onCreateFailure(String s) {
|
|
1107
|
-
}
|
|
1083
|
+
public void onCreateFailure(String s) {}
|
|
1108
1084
|
|
|
1109
1085
|
@Override
|
|
1110
1086
|
public void onSetFailure(String s) {
|
|
1111
|
-
ThreadUtils.runOnExecutor(() -> {
|
|
1112
|
-
promise.reject("E_OPERATION_ERROR", s);
|
|
1113
|
-
});
|
|
1087
|
+
ThreadUtils.runOnExecutor(() -> { promise.reject("E_OPERATION_ERROR", s); });
|
|
1114
1088
|
}
|
|
1115
1089
|
};
|
|
1116
1090
|
|
|
@@ -1118,40 +1092,42 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1118
1092
|
});
|
|
1119
1093
|
}
|
|
1120
1094
|
|
|
1121
|
-
|
|
1122
1095
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
1123
1096
|
public WritableMap receiverGetCapabilities() {
|
|
1124
1097
|
try {
|
|
1125
|
-
return (WritableMap) ThreadUtils
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1098
|
+
return (WritableMap) ThreadUtils
|
|
1099
|
+
.submitToExecutor((Callable<Object>) () -> {
|
|
1100
|
+
VideoCodecInfo[] videoCodecInfos = mVideoDecoderFactory.getSupportedCodecs();
|
|
1101
|
+
WritableMap params = Arguments.createMap();
|
|
1102
|
+
WritableArray codecs = Arguments.createArray();
|
|
1103
|
+
for (VideoCodecInfo codecInfo : videoCodecInfos) {
|
|
1104
|
+
codecs.pushMap(SerializeUtils.serializeVideoCodecInfo(codecInfo));
|
|
1105
|
+
}
|
|
1106
|
+
params.putArray("codecs", codecs);
|
|
1107
|
+
return params;
|
|
1108
|
+
})
|
|
1109
|
+
.get();
|
|
1135
1110
|
} catch (ExecutionException | InterruptedException e) {
|
|
1136
1111
|
Log.d(TAG, "receiverGetCapabilities() " + e.getMessage());
|
|
1137
1112
|
return null;
|
|
1138
1113
|
}
|
|
1139
1114
|
}
|
|
1140
1115
|
|
|
1141
|
-
|
|
1142
1116
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
1143
1117
|
public WritableMap senderGetCapabilities() {
|
|
1144
1118
|
try {
|
|
1145
|
-
return (WritableMap) ThreadUtils
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1119
|
+
return (WritableMap) ThreadUtils
|
|
1120
|
+
.submitToExecutor((Callable<Object>) () -> {
|
|
1121
|
+
VideoCodecInfo[] videoCodecInfos = mVideoEncoderFactory.getSupportedCodecs();
|
|
1122
|
+
WritableMap params = Arguments.createMap();
|
|
1123
|
+
WritableArray codecs = Arguments.createArray();
|
|
1124
|
+
for (VideoCodecInfo codecInfo : videoCodecInfos) {
|
|
1125
|
+
codecs.pushMap(SerializeUtils.serializeVideoCodecInfo(codecInfo));
|
|
1126
|
+
}
|
|
1127
|
+
params.putArray("codecs", codecs);
|
|
1128
|
+
return params;
|
|
1129
|
+
})
|
|
1130
|
+
.get();
|
|
1155
1131
|
} catch (ExecutionException | InterruptedException e) {
|
|
1156
1132
|
Log.d(TAG, "senderGetCapabilities() " + e.getMessage());
|
|
1157
1133
|
return null;
|
|
@@ -1184,9 +1160,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1184
1160
|
}
|
|
1185
1161
|
|
|
1186
1162
|
@ReactMethod
|
|
1187
|
-
public void peerConnectionAddICECandidate(int pcId,
|
|
1188
|
-
ReadableMap candidateMap,
|
|
1189
|
-
Promise promise) {
|
|
1163
|
+
public void peerConnectionAddICECandidate(int pcId, ReadableMap candidateMap, Promise promise) {
|
|
1190
1164
|
ThreadUtils.runOnExecutor(() -> {
|
|
1191
1165
|
PeerConnection peerConnection = getPeerConnection(pcId);
|
|
1192
1166
|
if (peerConnection == null) {
|
|
@@ -1195,30 +1169,31 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1195
1169
|
return;
|
|
1196
1170
|
}
|
|
1197
1171
|
|
|
1198
|
-
if (!(candidateMap.hasKey("sdpMid") && candidateMap.hasKey("sdpMLineIndex")
|
|
1172
|
+
if (!(candidateMap.hasKey("sdpMid") && candidateMap.hasKey("sdpMLineIndex")
|
|
1173
|
+
&& candidateMap.hasKey("sdpMid"))) {
|
|
1199
1174
|
promise.reject("E_TYPE_ERROR", "Invalid argument");
|
|
1200
1175
|
return;
|
|
1201
1176
|
}
|
|
1202
1177
|
|
|
1203
|
-
IceCandidate candidate = new IceCandidate(
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
candidateMap.getString("candidate")
|
|
1207
|
-
);
|
|
1178
|
+
IceCandidate candidate = new IceCandidate(candidateMap.getString("sdpMid"),
|
|
1179
|
+
candidateMap.getInt("sdpMLineIndex"),
|
|
1180
|
+
candidateMap.getString("candidate"));
|
|
1208
1181
|
|
|
1209
1182
|
peerConnection.addIceCandidate(candidate, new AddIceObserver() {
|
|
1210
1183
|
@Override
|
|
1211
1184
|
public void onAddSuccess() {
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1185
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
1186
|
+
WritableMap newSdpMap = Arguments.createMap();
|
|
1187
|
+
SessionDescription newSdp = peerConnection.getRemoteDescription();
|
|
1188
|
+
newSdpMap.putString("type", newSdp.type.canonicalForm());
|
|
1189
|
+
newSdpMap.putString("sdp", newSdp.description);
|
|
1190
|
+
promise.resolve(newSdpMap);
|
|
1191
|
+
});
|
|
1217
1192
|
}
|
|
1218
1193
|
|
|
1219
1194
|
@Override
|
|
1220
1195
|
public void onAddFailure(String s) {
|
|
1221
|
-
promise.reject("E_OPERATION_ERROR", s);
|
|
1196
|
+
ThreadUtils.runOnExecutor(() -> { promise.reject("E_OPERATION_ERROR", s); });
|
|
1222
1197
|
}
|
|
1223
1198
|
});
|
|
1224
1199
|
});
|
|
@@ -1243,10 +1218,21 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1243
1218
|
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
1244
1219
|
if (pco == null || pco.getPeerConnection() == null) {
|
|
1245
1220
|
Log.d(TAG, "peerConnectionClose() peerConnection is null");
|
|
1246
|
-
|
|
1247
|
-
pco.close();
|
|
1248
|
-
mPeerConnectionObservers.remove(id);
|
|
1221
|
+
return;
|
|
1249
1222
|
}
|
|
1223
|
+
pco.close();
|
|
1224
|
+
});
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
@ReactMethod
|
|
1228
|
+
public void peerConnectionDispose(int id) {
|
|
1229
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
1230
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
1231
|
+
if (pco == null || pco.getPeerConnection() == null) {
|
|
1232
|
+
Log.d(TAG, "peerConnectionDispose() peerConnection is null");
|
|
1233
|
+
}
|
|
1234
|
+
pco.dispose();
|
|
1235
|
+
mPeerConnectionObservers.remove(id);
|
|
1250
1236
|
});
|
|
1251
1237
|
}
|
|
1252
1238
|
|
|
@@ -1266,15 +1252,17 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1266
1252
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
1267
1253
|
public WritableMap createDataChannel(int peerConnectionId, String label, ReadableMap config) {
|
|
1268
1254
|
try {
|
|
1269
|
-
return (WritableMap) ThreadUtils
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1255
|
+
return (WritableMap) ThreadUtils
|
|
1256
|
+
.submitToExecutor((Callable<Object>) () -> {
|
|
1257
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
|
|
1258
|
+
if (pco == null || pco.getPeerConnection() == null) {
|
|
1259
|
+
Log.d(TAG, "createDataChannel() peerConnection is null");
|
|
1260
|
+
return null;
|
|
1261
|
+
} else {
|
|
1262
|
+
return pco.createDataChannel(label, config);
|
|
1263
|
+
}
|
|
1264
|
+
})
|
|
1265
|
+
.get();
|
|
1278
1266
|
} catch (ExecutionException | InterruptedException e) {
|
|
1279
1267
|
return null;
|
|
1280
1268
|
}
|
|
@@ -1309,10 +1297,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1309
1297
|
}
|
|
1310
1298
|
|
|
1311
1299
|
@ReactMethod
|
|
1312
|
-
public void dataChannelSend(int peerConnectionId,
|
|
1313
|
-
String reactTag,
|
|
1314
|
-
String data,
|
|
1315
|
-
String type) {
|
|
1300
|
+
public void dataChannelSend(int peerConnectionId, String reactTag, String data, String type) {
|
|
1316
1301
|
ThreadUtils.runOnExecutor(() -> {
|
|
1317
1302
|
// Forward to PeerConnectionObserver which deals with DataChannels
|
|
1318
1303
|
// because DataChannel is owned by PeerConnection.
|