react-native-webrtc 1.89.3 → 1.94.0
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/.prettierignore +9 -0
- package/.prettierrc.json +10 -0
- package/README.md +4 -1
- package/android/libs/.placeholder +0 -0
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +0 -5
- package/android/src/main/java/com/oney/WebRTCModule/LibraryLoader.java +21 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +301 -324
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +9 -84
- package/apple/.placeholder +0 -0
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +3 -0
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +4 -1
- package/ios/RCTWebRTC/VideoCaptureController.h +2 -2
- package/ios/RCTWebRTC/VideoCaptureController.m +131 -48
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +56 -26
- package/metro.config.js +3 -4
- package/metro.config.macos.js +7 -8
- package/package.json +21 -12
- package/react-native.config.js +5 -6
- package/{EventEmitter.js → src/EventEmitter.js} +1 -1
- package/{MediaDevices.js → src/MediaDevices.js} +6 -12
- package/src/MediaStream.js +128 -0
- package/src/MediaStreamError.js +12 -0
- package/src/MediaStreamErrorEvent.js +11 -0
- package/src/MediaStreamEvent.js +11 -0
- package/src/MediaStreamTrack.js +104 -0
- package/src/MediaStreamTrackEvent.js +11 -0
- package/src/MessageEvent.js +10 -0
- package/{Permissions.js → src/Permissions.js} +26 -23
- package/src/RTCDataChannel.js +143 -0
- package/src/RTCDataChannelEvent.js +11 -0
- package/src/RTCEvent.js +8 -0
- package/src/RTCIceCandidate.js +20 -0
- package/src/RTCIceCandidateEvent.js +15 -0
- package/src/RTCPeerConnection.js +349 -0
- package/src/RTCSessionDescription.js +22 -0
- package/{RTCUtil.js → src/RTCUtil.js} +56 -57
- package/src/RTCView.js +60 -0
- package/src/ScreenCapturePickerView.js +4 -0
- package/{getDisplayMedia.js → src/getDisplayMedia.js} +8 -11
- package/src/getUserMedia.js +98 -0
- package/src/index.js +44 -0
- package/tools/build-webrtc.py +60 -46
- package/tools/downloadBitcode.sh +4 -16
- package/tools/downloadWebRTC.js +100 -0
- package/MediaStream.js +0 -138
- package/MediaStreamError.js +0 -14
- package/MediaStreamErrorEvent.js +0 -12
- package/MediaStreamEvent.js +0 -12
- package/MediaStreamTrack.js +0 -118
- package/MediaStreamTrackEvent.js +0 -12
- package/MessageEvent.js +0 -11
- package/RTCDataChannel.js +0 -161
- package/RTCDataChannelEvent.js +0 -12
- package/RTCEvent.js +0 -9
- package/RTCIceCandidate.js +0 -21
- package/RTCIceCandidateEvent.js +0 -16
- package/RTCPeerConnection.js +0 -390
- package/RTCSessionDescription.js +0 -23
- package/RTCView.js +0 -70
- package/ScreenCapturePickerView.js +0 -7
- package/android/libs/libjingle_peerconnection.so.jar +0 -0
- package/android/libs/libwebrtc.jar +0 -0
- package/apple/WebRTC.xcframework.tgz +0 -0
- package/getUserMedia.js +0 -98
- package/index.js +0 -47
- 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/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package com.oney.WebRTCModule;
|
|
2
2
|
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
3
4
|
import androidx.annotation.Nullable;
|
|
4
5
|
|
|
5
6
|
import android.util.Log;
|
|
@@ -39,7 +40,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
39
40
|
private final SparseArray<PeerConnectionObserver> mPeerConnectionObservers;
|
|
40
41
|
final Map<String, MediaStream> localStreams;
|
|
41
42
|
|
|
42
|
-
private GetUserMediaImpl getUserMediaImpl;
|
|
43
|
+
private final GetUserMediaImpl getUserMediaImpl;
|
|
43
44
|
|
|
44
45
|
public static class Options {
|
|
45
46
|
private VideoEncoderFactory videoEncoderFactory = null;
|
|
@@ -81,15 +82,6 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
81
82
|
mPeerConnectionObservers = new SparseArray<>();
|
|
82
83
|
localStreams = new HashMap<>();
|
|
83
84
|
|
|
84
|
-
ThreadUtils.runOnExecutor(() -> initAsync(options));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Invoked asynchronously to initialize this {@code WebRTCModule} instance.
|
|
89
|
-
*/
|
|
90
|
-
private void initAsync(Options options) {
|
|
91
|
-
ReactApplicationContext reactContext = getReactApplicationContext();
|
|
92
|
-
|
|
93
85
|
AudioDeviceModule adm = null;
|
|
94
86
|
VideoEncoderFactory encoderFactory = null;
|
|
95
87
|
VideoDecoderFactory decoderFactory = null;
|
|
@@ -106,6 +98,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
106
98
|
|
|
107
99
|
PeerConnectionFactory.initialize(
|
|
108
100
|
PeerConnectionFactory.InitializationOptions.builder(reactContext)
|
|
101
|
+
.setNativeLibraryLoader(new LibraryLoader())
|
|
109
102
|
.setInjectableLogger(injectableLogger, loggingSeverity)
|
|
110
103
|
.createInitializationOptions());
|
|
111
104
|
|
|
@@ -140,6 +133,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
140
133
|
getUserMediaImpl = new GetUserMediaImpl(this, reactContext);
|
|
141
134
|
}
|
|
142
135
|
|
|
136
|
+
@NonNull
|
|
143
137
|
@Override
|
|
144
138
|
public String getName() {
|
|
145
139
|
return "WebRTCModule";
|
|
@@ -212,6 +206,10 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
212
206
|
}
|
|
213
207
|
List<PeerConnection.IceServer> iceServers = createIceServers(iceServersArray);
|
|
214
208
|
PeerConnection.RTCConfiguration conf = new PeerConnection.RTCConfiguration(iceServers);
|
|
209
|
+
|
|
210
|
+
// Required for perfect negotiation.
|
|
211
|
+
conf.enableImplicitRollback = true;
|
|
212
|
+
|
|
215
213
|
if (map == null) {
|
|
216
214
|
return conf;
|
|
217
215
|
}
|
|
@@ -415,19 +413,30 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
415
413
|
}
|
|
416
414
|
|
|
417
415
|
MediaStream getStreamForReactTag(String streamReactTag) {
|
|
418
|
-
|
|
416
|
+
// This function _only_ gets called from WebRTCView, in the UI thread.
|
|
417
|
+
// Hence make sure we run this code in the executor or we run at the risk
|
|
418
|
+
// of being out of sync.
|
|
419
|
+
try {
|
|
420
|
+
return (MediaStream) ThreadUtils.submitToExecutor((Callable<Object>) () -> {
|
|
421
|
+
MediaStream stream = localStreams.get(streamReactTag);
|
|
419
422
|
|
|
420
|
-
if (stream == null) {
|
|
421
|
-
for (int i = 0, size = mPeerConnectionObservers.size(); i < size; i++) {
|
|
422
|
-
PeerConnectionObserver pco = mPeerConnectionObservers.valueAt(i);
|
|
423
|
-
stream = pco.remoteStreams.get(streamReactTag);
|
|
424
423
|
if (stream != null) {
|
|
425
|
-
|
|
424
|
+
return stream;
|
|
425
|
+
}
|
|
426
|
+
|
|
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
|
+
}
|
|
426
433
|
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
434
|
|
|
430
|
-
|
|
435
|
+
return null;
|
|
436
|
+
}).get();
|
|
437
|
+
} catch (ExecutionException | InterruptedException e) {
|
|
438
|
+
return null;
|
|
439
|
+
}
|
|
431
440
|
}
|
|
432
441
|
|
|
433
442
|
private MediaStreamTrack getTrack(String trackId) {
|
|
@@ -450,22 +459,6 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
450
459
|
return getUserMediaImpl.getTrack(trackId);
|
|
451
460
|
}
|
|
452
461
|
|
|
453
|
-
private static MediaStreamTrack getLocalTrack(
|
|
454
|
-
MediaStream localStream,
|
|
455
|
-
String trackId) {
|
|
456
|
-
for (AudioTrack track : localStream.audioTracks) {
|
|
457
|
-
if (track.id().equals(trackId)) {
|
|
458
|
-
return track;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
for (VideoTrack track : localStream.videoTracks) {
|
|
462
|
-
if (track.id().equals(trackId)) {
|
|
463
|
-
return track;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
return null;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
462
|
/**
|
|
470
463
|
* Turns an "options" <tt>ReadableMap</tt> into a <tt>MediaConstraints</tt> object.
|
|
471
464
|
*
|
|
@@ -510,192 +503,167 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
510
503
|
|
|
511
504
|
@ReactMethod
|
|
512
505
|
public void mediaStreamCreate(String id) {
|
|
513
|
-
ThreadUtils.runOnExecutor(() ->
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
MediaStream mediaStream = mFactory.createLocalMediaStream(id);
|
|
518
|
-
localStreams.put(id, mediaStream);
|
|
506
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
507
|
+
MediaStream mediaStream = mFactory.createLocalMediaStream(id);
|
|
508
|
+
localStreams.put(id, mediaStream);
|
|
509
|
+
});
|
|
519
510
|
}
|
|
520
511
|
|
|
521
512
|
@ReactMethod
|
|
522
513
|
public void mediaStreamAddTrack(String streamId, String trackId) {
|
|
523
|
-
ThreadUtils.runOnExecutor(() ->
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
private void mediaStreamAddTrackAsync(String streamId, String trackId) {
|
|
528
|
-
MediaStream stream = localStreams.get(streamId);
|
|
529
|
-
MediaStreamTrack track = getTrack(trackId);
|
|
514
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
515
|
+
MediaStream stream = localStreams.get(streamId);
|
|
516
|
+
MediaStreamTrack track = getTrack(trackId);
|
|
530
517
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
518
|
+
if (stream == null || track == null) {
|
|
519
|
+
Log.d(TAG, "mediaStreamAddTrack() stream || track is null");
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
535
522
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
523
|
+
String kind = track.kind();
|
|
524
|
+
if ("audio".equals(kind)) {
|
|
525
|
+
stream.addTrack((AudioTrack)track);
|
|
526
|
+
} else if ("video".equals(kind)) {
|
|
527
|
+
stream.addTrack((VideoTrack)track);
|
|
528
|
+
}
|
|
529
|
+
});
|
|
542
530
|
}
|
|
543
531
|
|
|
544
532
|
@ReactMethod
|
|
545
533
|
public void mediaStreamRemoveTrack(String streamId, String trackId) {
|
|
546
|
-
ThreadUtils.runOnExecutor(() ->
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
private void mediaStreamRemoveTrackAsync(String streamId, String trackId) {
|
|
551
|
-
MediaStream stream = localStreams.get(streamId);
|
|
552
|
-
MediaStreamTrack track = getTrack(trackId);
|
|
534
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
535
|
+
MediaStream stream = localStreams.get(streamId);
|
|
536
|
+
MediaStreamTrack track = getTrack(trackId);
|
|
553
537
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
538
|
+
if (stream == null || track == null) {
|
|
539
|
+
Log.d(TAG, "mediaStreamRemoveTrack() stream || track is null");
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
558
542
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
543
|
+
String kind = track.kind();
|
|
544
|
+
if ("audio".equals(kind)) {
|
|
545
|
+
stream.removeTrack((AudioTrack)track);
|
|
546
|
+
} else if ("video".equals(kind)) {
|
|
547
|
+
stream.removeTrack((VideoTrack)track);
|
|
548
|
+
}
|
|
549
|
+
});
|
|
565
550
|
}
|
|
566
551
|
|
|
567
552
|
@ReactMethod
|
|
568
553
|
public void mediaStreamRelease(String id) {
|
|
569
|
-
ThreadUtils.runOnExecutor(() ->
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
Log.d(TAG, "mediaStreamRelease() stream is null");
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
554
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
555
|
+
MediaStream stream = localStreams.get(id);
|
|
556
|
+
if (stream == null) {
|
|
557
|
+
Log.d(TAG, "mediaStreamRelease() stream is null");
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
578
560
|
|
|
579
|
-
|
|
561
|
+
localStreams.remove(id);
|
|
580
562
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
563
|
+
// MediaStream.dispose() may be called without an exception only if
|
|
564
|
+
// it's no longer added to any PeerConnection.
|
|
565
|
+
for (int i = 0, size = mPeerConnectionObservers.size(); i < size; i++) {
|
|
566
|
+
mPeerConnectionObservers.valueAt(i).removeStream(stream);
|
|
567
|
+
}
|
|
586
568
|
|
|
587
|
-
|
|
569
|
+
stream.dispose();
|
|
570
|
+
});
|
|
588
571
|
}
|
|
589
572
|
|
|
590
573
|
@ReactMethod
|
|
591
574
|
public void mediaStreamTrackRelease(String id) {
|
|
592
|
-
ThreadUtils.runOnExecutor(() ->
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
}
|
|
602
|
-
track.setEnabled(false);
|
|
603
|
-
getUserMediaImpl.disposeTrack(id);
|
|
575
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
576
|
+
MediaStreamTrack track = getLocalTrack(id);
|
|
577
|
+
if (track == null) {
|
|
578
|
+
Log.d(TAG, "mediaStreamTrackRelease() track is null");
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
track.setEnabled(false);
|
|
582
|
+
getUserMediaImpl.disposeTrack(id);
|
|
583
|
+
});
|
|
604
584
|
}
|
|
605
585
|
|
|
606
586
|
@ReactMethod
|
|
607
587
|
public void mediaStreamTrackSetEnabled(String id, boolean enabled) {
|
|
608
|
-
ThreadUtils.runOnExecutor(() ->
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
track.setEnabled(enabled);
|
|
621
|
-
getUserMediaImpl.mediaStreamTrackSetEnabled(id, enabled);
|
|
588
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
589
|
+
MediaStreamTrack track = getTrack(id);
|
|
590
|
+
if (track == null) {
|
|
591
|
+
Log.d(TAG, "mediaStreamTrackSetEnabled() track is null");
|
|
592
|
+
return;
|
|
593
|
+
} else if (track.enabled() == enabled) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
track.setEnabled(enabled);
|
|
597
|
+
getUserMediaImpl.mediaStreamTrackSetEnabled(id, enabled);
|
|
598
|
+
});
|
|
622
599
|
}
|
|
623
600
|
|
|
624
601
|
@ReactMethod
|
|
625
602
|
public void mediaStreamTrackSwitchCamera(String id) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
603
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
604
|
+
MediaStreamTrack track = getLocalTrack(id);
|
|
605
|
+
if (track != null) {
|
|
606
|
+
getUserMediaImpl.switchCamera(id);
|
|
607
|
+
}
|
|
608
|
+
});
|
|
630
609
|
}
|
|
631
610
|
|
|
632
611
|
@ReactMethod
|
|
633
612
|
public void peerConnectionSetConfiguration(ReadableMap configuration,
|
|
634
613
|
int id) {
|
|
635
|
-
ThreadUtils.runOnExecutor(() ->
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
Log.d(TAG, "peerConnectionSetConfiguration() peerConnection is null");
|
|
644
|
-
return;
|
|
645
|
-
}
|
|
646
|
-
peerConnection.setConfiguration(parseRTCConfiguration(configuration));
|
|
614
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
615
|
+
PeerConnection peerConnection = getPeerConnection(id);
|
|
616
|
+
if (peerConnection == null) {
|
|
617
|
+
Log.d(TAG, "peerConnectionSetConfiguration() peerConnection is null");
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
peerConnection.setConfiguration(parseRTCConfiguration(configuration));
|
|
621
|
+
});
|
|
647
622
|
}
|
|
648
623
|
|
|
649
624
|
@ReactMethod
|
|
650
625
|
public void peerConnectionAddStream(String streamId, int id) {
|
|
651
|
-
ThreadUtils.runOnExecutor(() ->
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
if (pco == null || !pco.addStream(mediaStream)) {
|
|
663
|
-
Log.e(TAG, "peerConnectionAddStream() failed");
|
|
664
|
-
}
|
|
626
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
627
|
+
MediaStream mediaStream = localStreams.get(streamId);
|
|
628
|
+
if (mediaStream == null) {
|
|
629
|
+
Log.d(TAG, "peerConnectionAddStream() mediaStream is null");
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
633
|
+
if (pco == null || !pco.addStream(mediaStream)) {
|
|
634
|
+
Log.e(TAG, "peerConnectionAddStream() failed");
|
|
635
|
+
}
|
|
636
|
+
});
|
|
665
637
|
}
|
|
666
638
|
|
|
667
639
|
@ReactMethod
|
|
668
640
|
public void peerConnectionRemoveStream(String streamId, int id) {
|
|
669
|
-
ThreadUtils.runOnExecutor(() ->
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
if (pco == null || !pco.removeStream(mediaStream)) {
|
|
681
|
-
Log.e(TAG, "peerConnectionRemoveStream() failed");
|
|
682
|
-
}
|
|
641
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
642
|
+
MediaStream mediaStream = localStreams.get(streamId);
|
|
643
|
+
if (mediaStream == null) {
|
|
644
|
+
Log.d(TAG, "peerConnectionRemoveStream() mediaStream is null");
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
648
|
+
if (pco == null || !pco.removeStream(mediaStream)) {
|
|
649
|
+
Log.e(TAG, "peerConnectionRemoveStream() failed");
|
|
650
|
+
}
|
|
651
|
+
});
|
|
683
652
|
}
|
|
684
653
|
|
|
685
654
|
@ReactMethod
|
|
686
655
|
public void peerConnectionCreateOffer(int id,
|
|
687
656
|
ReadableMap options,
|
|
688
657
|
Callback callback) {
|
|
689
|
-
ThreadUtils.runOnExecutor(() ->
|
|
690
|
-
|
|
691
|
-
}
|
|
658
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
659
|
+
PeerConnection peerConnection = getPeerConnection(id);
|
|
692
660
|
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
661
|
+
if (peerConnection == null) {
|
|
662
|
+
Log.d(TAG, "peerConnectionCreateOffer() peerConnection is null");
|
|
663
|
+
callback.invoke(false, "peerConnection is null");
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
697
666
|
|
|
698
|
-
if (peerConnection != null) {
|
|
699
667
|
peerConnection.createOffer(new SdpObserver() {
|
|
700
668
|
@Override
|
|
701
669
|
public void onCreateFailure(String s) {
|
|
@@ -716,26 +684,22 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
716
684
|
@Override
|
|
717
685
|
public void onSetSuccess() {}
|
|
718
686
|
}, constraintsForOptions(options));
|
|
719
|
-
}
|
|
720
|
-
Log.d(TAG, "peerConnectionCreateOffer() peerConnection is null");
|
|
721
|
-
callback.invoke(false, "peerConnection is null");
|
|
722
|
-
}
|
|
687
|
+
});
|
|
723
688
|
}
|
|
724
689
|
|
|
725
690
|
@ReactMethod
|
|
726
691
|
public void peerConnectionCreateAnswer(int id,
|
|
727
692
|
ReadableMap options,
|
|
728
693
|
Callback callback) {
|
|
729
|
-
ThreadUtils.runOnExecutor(() ->
|
|
730
|
-
|
|
731
|
-
}
|
|
694
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
695
|
+
PeerConnection peerConnection = getPeerConnection(id);
|
|
732
696
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
697
|
+
if (peerConnection == null) {
|
|
698
|
+
Log.d(TAG, "peerConnectionCreateAnswer() peerConnection is null");
|
|
699
|
+
callback.invoke(false, "peerConnection is null");
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
737
702
|
|
|
738
|
-
if (peerConnection != null) {
|
|
739
703
|
peerConnection.createAnswer(new SdpObserver() {
|
|
740
704
|
@Override
|
|
741
705
|
public void onCreateFailure(String s) {
|
|
@@ -756,117 +720,115 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
756
720
|
@Override
|
|
757
721
|
public void onSetSuccess() {}
|
|
758
722
|
}, constraintsForOptions(options));
|
|
759
|
-
}
|
|
760
|
-
Log.d(TAG, "peerConnectionCreateAnswer() peerConnection is null");
|
|
761
|
-
callback.invoke(false, "peerConnection is null");
|
|
762
|
-
}
|
|
723
|
+
});
|
|
763
724
|
}
|
|
764
725
|
|
|
765
726
|
@ReactMethod
|
|
766
|
-
public void peerConnectionSetLocalDescription(
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
ThreadUtils.runOnExecutor(() ->
|
|
770
|
-
|
|
771
|
-
|
|
727
|
+
public void peerConnectionSetLocalDescription(int pcId,
|
|
728
|
+
ReadableMap desc,
|
|
729
|
+
Promise promise) {
|
|
730
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
731
|
+
PeerConnection peerConnection = getPeerConnection(pcId);
|
|
732
|
+
if (peerConnection == null) {
|
|
733
|
+
Log.d(TAG, "peerConnectionSetLocalDescription() peerConnection is null");
|
|
734
|
+
promise.reject(new Exception("PeerConnection not found"));
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
772
737
|
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
if (peerConnection == null) {
|
|
778
|
-
Log.d(TAG, "peerConnectionSetLocalDescription() peerConnection is null");
|
|
779
|
-
callback.invoke(false, "peerConnection is null");
|
|
780
|
-
return;
|
|
781
|
-
}
|
|
738
|
+
final SdpObserver observer = new SdpObserver() {
|
|
739
|
+
@Override
|
|
740
|
+
public void onCreateSuccess(SessionDescription sdp) {
|
|
741
|
+
}
|
|
782
742
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
743
|
+
@Override
|
|
744
|
+
public void onSetSuccess() {
|
|
745
|
+
SessionDescription newSdp = peerConnection.getLocalDescription();
|
|
746
|
+
WritableMap newSdpMap = Arguments.createMap();
|
|
747
|
+
newSdpMap.putString("type", newSdp.type.canonicalForm());
|
|
748
|
+
newSdpMap.putString("sdp", newSdp.description);
|
|
749
|
+
promise.resolve(newSdpMap);
|
|
750
|
+
}
|
|
787
751
|
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
}
|
|
752
|
+
@Override
|
|
753
|
+
public void onCreateFailure(String s) {
|
|
754
|
+
}
|
|
792
755
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
newSdpMap.putString("sdp", newSdp.description);
|
|
799
|
-
callback.invoke(true, newSdpMap);
|
|
800
|
-
}
|
|
756
|
+
@Override
|
|
757
|
+
public void onSetFailure(String s) {
|
|
758
|
+
promise.reject("E_OPERATION_ERROR", s);
|
|
759
|
+
}
|
|
760
|
+
};
|
|
801
761
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
762
|
+
if (desc != null) {
|
|
763
|
+
SessionDescription sdp = new SessionDescription(
|
|
764
|
+
SessionDescription.Type.fromCanonicalForm(Objects.requireNonNull(desc.getString("type"))),
|
|
765
|
+
desc.getString("sdp")
|
|
766
|
+
);
|
|
805
767
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
768
|
+
peerConnection.setLocalDescription(observer, sdp);
|
|
769
|
+
} else {
|
|
770
|
+
peerConnection.setLocalDescription(observer);
|
|
809
771
|
}
|
|
810
|
-
}
|
|
772
|
+
});
|
|
811
773
|
}
|
|
812
774
|
|
|
813
775
|
@ReactMethod
|
|
814
776
|
public void peerConnectionSetRemoteDescription(ReadableMap sdpMap,
|
|
815
777
|
int id,
|
|
816
778
|
Callback callback) {
|
|
817
|
-
ThreadUtils.runOnExecutor(() ->
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
PeerConnection peerConnection = getPeerConnection(id);
|
|
825
|
-
if (peerConnection == null) {
|
|
826
|
-
Log.d(TAG, "peerConnectionSetRemoteDescription() peerConnection is null");
|
|
827
|
-
callback.invoke(false, "peerConnection is null");
|
|
828
|
-
return;
|
|
829
|
-
}
|
|
779
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
780
|
+
PeerConnection peerConnection = getPeerConnection(id);
|
|
781
|
+
if (peerConnection == null) {
|
|
782
|
+
Log.d(TAG, "peerConnectionSetRemoteDescription() peerConnection is null");
|
|
783
|
+
callback.invoke(false, "peerConnection is null");
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
830
786
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
787
|
+
SessionDescription sdp = new SessionDescription(
|
|
788
|
+
SessionDescription.Type.fromCanonicalForm(sdpMap.getString("type")),
|
|
789
|
+
sdpMap.getString("sdp")
|
|
790
|
+
);
|
|
835
791
|
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
792
|
+
peerConnection.setRemoteDescription(new SdpObserver() {
|
|
793
|
+
@Override
|
|
794
|
+
public void onCreateSuccess(final SessionDescription sdp) {
|
|
795
|
+
}
|
|
840
796
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
797
|
+
@Override
|
|
798
|
+
public void onSetSuccess() {
|
|
799
|
+
SessionDescription newSdp = peerConnection.getRemoteDescription();
|
|
800
|
+
WritableMap newSdpMap = Arguments.createMap();
|
|
801
|
+
newSdpMap.putString("type", newSdp.type.canonicalForm());
|
|
802
|
+
newSdpMap.putString("sdp", newSdp.description);
|
|
803
|
+
callback.invoke(true, newSdpMap);
|
|
804
|
+
}
|
|
849
805
|
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
806
|
+
@Override
|
|
807
|
+
public void onCreateFailure(String s) {
|
|
808
|
+
}
|
|
853
809
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
810
|
+
@Override
|
|
811
|
+
public void onSetFailure(String s) {
|
|
812
|
+
callback.invoke(false, s);
|
|
813
|
+
}
|
|
814
|
+
}, sdp);
|
|
815
|
+
});
|
|
859
816
|
}
|
|
860
817
|
|
|
861
818
|
@ReactMethod
|
|
862
|
-
public void peerConnectionAddICECandidate(
|
|
863
|
-
|
|
864
|
-
|
|
819
|
+
public void peerConnectionAddICECandidate(int pcId,
|
|
820
|
+
ReadableMap candidateMap,
|
|
821
|
+
Promise promise) {
|
|
865
822
|
ThreadUtils.runOnExecutor(() -> {
|
|
866
|
-
PeerConnection peerConnection = getPeerConnection(
|
|
823
|
+
PeerConnection peerConnection = getPeerConnection(pcId);
|
|
867
824
|
if (peerConnection == null) {
|
|
868
825
|
Log.d(TAG, "peerConnectionAddICECandidate() peerConnection is null");
|
|
869
|
-
|
|
826
|
+
promise.reject(new Exception("PeerConnection not found"));
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
if (!(candidateMap.hasKey("sdpMid") && candidateMap.hasKey("sdpMLineIndex") && candidateMap.hasKey("sdpMid"))) {
|
|
831
|
+
promise.reject("E_TYPE_ERROR", "Invalid argument");
|
|
870
832
|
return;
|
|
871
833
|
}
|
|
872
834
|
|
|
@@ -876,47 +838,61 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
876
838
|
candidateMap.getString("candidate")
|
|
877
839
|
);
|
|
878
840
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
841
|
+
peerConnection.addIceCandidate(candidate, new AddIceObserver() {
|
|
842
|
+
@Override
|
|
843
|
+
public void onAddSuccess() {
|
|
844
|
+
WritableMap newSdpMap = Arguments.createMap();
|
|
845
|
+
SessionDescription newSdp = peerConnection.getRemoteDescription();
|
|
846
|
+
newSdpMap.putString("type", newSdp.type.canonicalForm());
|
|
847
|
+
newSdpMap.putString("sdp", newSdp.description);
|
|
848
|
+
promise.resolve(newSdpMap);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
@Override
|
|
852
|
+
public void onAddFailure(String s) {
|
|
853
|
+
promise.reject("E_OPERATION_ERROR", s);
|
|
854
|
+
}
|
|
855
|
+
});
|
|
887
856
|
});
|
|
888
857
|
}
|
|
889
858
|
|
|
890
859
|
@ReactMethod
|
|
891
860
|
public void peerConnectionGetStats(int peerConnectionId, Promise promise) {
|
|
892
|
-
ThreadUtils.runOnExecutor(() ->
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
promise.reject(new Exception("PeerConnection ID not found"));
|
|
902
|
-
} else {
|
|
903
|
-
pco.getStats(promise);
|
|
904
|
-
}
|
|
861
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
862
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
|
|
863
|
+
if (pco == null || pco.getPeerConnection() == null) {
|
|
864
|
+
Log.d(TAG, "peerConnectionGetStats() peerConnection is null");
|
|
865
|
+
promise.reject(new Exception("PeerConnection ID not found"));
|
|
866
|
+
} else {
|
|
867
|
+
pco.getStats(promise);
|
|
868
|
+
}
|
|
869
|
+
});
|
|
905
870
|
}
|
|
906
871
|
|
|
907
872
|
@ReactMethod
|
|
908
873
|
public void peerConnectionClose(int id) {
|
|
909
|
-
ThreadUtils.runOnExecutor(() ->
|
|
874
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
875
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
876
|
+
if (pco == null || pco.getPeerConnection() == null) {
|
|
877
|
+
Log.d(TAG, "peerConnectionClose() peerConnection is null");
|
|
878
|
+
} else {
|
|
879
|
+
pco.close();
|
|
880
|
+
mPeerConnectionObservers.remove(id);
|
|
881
|
+
}
|
|
882
|
+
});
|
|
910
883
|
}
|
|
911
884
|
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
885
|
+
@ReactMethod
|
|
886
|
+
public void peerConnectionRestartIce(int pcId) {
|
|
887
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
888
|
+
PeerConnection peerConnection = getPeerConnection(pcId);
|
|
889
|
+
if (peerConnection == null) {
|
|
890
|
+
Log.w(TAG, "peerConnectionRestartIce() peerConnection is null");
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
peerConnection.restartIce();
|
|
895
|
+
});
|
|
920
896
|
}
|
|
921
897
|
|
|
922
898
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
@@ -938,20 +914,17 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
938
914
|
|
|
939
915
|
@ReactMethod
|
|
940
916
|
public void dataChannelClose(int peerConnectionId, String reactTag) {
|
|
941
|
-
ThreadUtils.runOnExecutor(() ->
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
if (pco == null || pco.getPeerConnection() == null) {
|
|
950
|
-
Log.d(TAG, "dataChannelClose() peerConnection is null");
|
|
951
|
-
return;
|
|
952
|
-
}
|
|
917
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
918
|
+
// Forward to PeerConnectionObserver which deals with DataChannels
|
|
919
|
+
// because DataChannel is owned by PeerConnection.
|
|
920
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
|
|
921
|
+
if (pco == null || pco.getPeerConnection() == null) {
|
|
922
|
+
Log.d(TAG, "dataChannelClose() peerConnection is null");
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
953
925
|
|
|
954
|
-
|
|
926
|
+
pco.dataChannelClose(reactTag);
|
|
927
|
+
});
|
|
955
928
|
}
|
|
956
929
|
|
|
957
930
|
@ReactMethod
|
|
@@ -972,22 +945,26 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
972
945
|
String reactTag,
|
|
973
946
|
String data,
|
|
974
947
|
String type) {
|
|
975
|
-
ThreadUtils.runOnExecutor(() ->
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
// Forward to PeerConnectionObserver which deals with DataChannels
|
|
984
|
-
// because DataChannel is owned by PeerConnection.
|
|
985
|
-
PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
|
|
986
|
-
if (pco == null || pco.getPeerConnection() == null) {
|
|
987
|
-
Log.d(TAG, "dataChannelSend() peerConnection is null");
|
|
988
|
-
return;
|
|
989
|
-
}
|
|
948
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
949
|
+
// Forward to PeerConnectionObserver which deals with DataChannels
|
|
950
|
+
// because DataChannel is owned by PeerConnection.
|
|
951
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
|
|
952
|
+
if (pco == null || pco.getPeerConnection() == null) {
|
|
953
|
+
Log.d(TAG, "dataChannelSend() peerConnection is null");
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
990
956
|
|
|
991
|
-
|
|
957
|
+
pco.dataChannelSend(reactTag, data, type);
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
@ReactMethod
|
|
962
|
+
public void addListener(String eventName) {
|
|
963
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
@ReactMethod
|
|
967
|
+
public void removeListeners(Integer count) {
|
|
968
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
992
969
|
}
|
|
993
970
|
}
|