react-native-webrtc 106.0.0-beta.5 → 106.0.0-beta.7
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/README.md +2 -2
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +18 -24
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +59 -68
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +10 -0
- package/ios/RCTWebRTC/SerializeUtils.m +4 -2
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +73 -60
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +23 -22
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +1 -1
- package/ios/RCTWebRTC/WebRTCModule.h +0 -8
- package/ios/RCTWebRTC/WebRTCModule.m +1 -20
- package/lib/commonjs/MediaStreamTrack.js +24 -7
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCIceCandidate.js +14 -4
- package/lib/commonjs/RTCIceCandidate.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +129 -132
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtpSender.js +6 -5
- package/lib/commonjs/RTCRtpSender.js.map +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js +11 -49
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
- package/lib/commonjs/RTCView.js +0 -55
- package/lib/commonjs/RTCView.js.map +1 -1
- package/lib/commonjs/index.js +3 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +25 -8
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCIceCandidate.js +14 -4
- package/lib/module/RTCIceCandidate.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +129 -130
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtpSender.js +6 -5
- package/lib/module/RTCRtpSender.js.map +1 -1
- package/lib/module/RTCRtpTransceiver.js +11 -44
- package/lib/module/RTCRtpTransceiver.js.map +1 -1
- package/lib/module/RTCView.js +0 -49
- package/lib/module/RTCView.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/MediaStreamTrack.d.ts +11 -3
- package/lib/typescript/RTCIceCandidate.d.ts +5 -1
- package/lib/typescript/RTCPeerConnection.d.ts +5 -5
- package/lib/typescript/RTCRtpTransceiver.d.ts +2 -8
- package/lib/typescript/RTCView.d.ts +53 -46
- package/package.json +2 -2
- package/src/MediaStreamTrack.ts +23 -7
- package/src/RTCIceCandidate.ts +8 -5
- package/src/RTCPeerConnection.ts +133 -126
- package/src/RTCRtpSender.ts +6 -7
- package/src/RTCRtpTransceiver.ts +15 -45
- package/src/RTCView.ts +53 -49
- package/src/index.ts +2 -0
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ Which will allow you to use [(almost)](https://github.com/react-native-webrtc/r
|
|
|
34
34
|
* Supported architectures
|
|
35
35
|
* Android: armeabi-v7a, arm64-v8a, x86, x86_64
|
|
36
36
|
* iOS: arm64, x86_64
|
|
37
|
-
* macOS:
|
|
37
|
+
* macOS: (temporarily disabled)
|
|
38
38
|
|
|
39
39
|
## Getting Started
|
|
40
40
|
|
|
@@ -65,4 +65,4 @@ Everyone is welcome and every little helps.
|
|
|
65
65
|
## Related Projects
|
|
66
66
|
|
|
67
67
|
Looking for extra functionality coverage?
|
|
68
|
-
The [react-native-webrtc](https://github.com/react-native-webrtc) organization provides a number of packages which are more than useful when developing Real Time Communication applications.
|
|
68
|
+
The [react-native-webrtc](https://github.com/react-native-webrtc) organization provides a number of packages which are more than useful when developing Real Time Communication applications.
|
|
@@ -331,7 +331,7 @@ class GetUserMediaImpl {
|
|
|
331
331
|
trackInfo.putString("id", trackId);
|
|
332
332
|
trackInfo.putString("kind", track.kind());
|
|
333
333
|
trackInfo.putString("label", trackId);
|
|
334
|
-
trackInfo.putString("readyState", track.state().toString());
|
|
334
|
+
trackInfo.putString("readyState", track.state().toString().toLowerCase());
|
|
335
335
|
trackInfo.putBoolean("remote", false);
|
|
336
336
|
|
|
337
337
|
if (track instanceof VideoTrack) {
|
|
@@ -243,7 +243,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
243
243
|
public void onIceCandidate(final IceCandidate candidate) {
|
|
244
244
|
Log.d(TAG, "onIceCandidate");
|
|
245
245
|
WritableMap params = Arguments.createMap();
|
|
246
|
-
params.putInt("
|
|
246
|
+
params.putInt("pcId", id);
|
|
247
247
|
WritableMap candidateParams = Arguments.createMap();
|
|
248
248
|
candidateParams.putInt("sdpMLineIndex", candidate.sdpMLineIndex);
|
|
249
249
|
candidateParams.putString("sdpMid", candidate.sdpMid);
|
|
@@ -266,7 +266,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
266
266
|
@Override
|
|
267
267
|
public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) {
|
|
268
268
|
WritableMap params = Arguments.createMap();
|
|
269
|
-
params.putInt("
|
|
269
|
+
params.putInt("pcId", id);
|
|
270
270
|
params.putString("iceConnectionState", iceConnectionStateString(iceConnectionState));
|
|
271
271
|
webRTCModule.sendEvent("peerConnectionIceConnectionChanged", params);
|
|
272
272
|
}
|
|
@@ -274,7 +274,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
274
274
|
@Override
|
|
275
275
|
public void onConnectionChange(PeerConnection.PeerConnectionState peerConnectionState) {
|
|
276
276
|
WritableMap params = Arguments.createMap();
|
|
277
|
-
params.putInt("
|
|
277
|
+
params.putInt("pcId", id);
|
|
278
278
|
params.putString("connectionState", peerConnectionStateString(peerConnectionState));
|
|
279
279
|
|
|
280
280
|
webRTCModule.sendEvent("peerConnectionStateChanged", params);
|
|
@@ -288,7 +288,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
288
288
|
public void onIceGatheringChange(PeerConnection.IceGatheringState iceGatheringState) {
|
|
289
289
|
Log.d(TAG, "onIceGatheringChange" + iceGatheringState.name());
|
|
290
290
|
WritableMap params = Arguments.createMap();
|
|
291
|
-
params.putInt("
|
|
291
|
+
params.putInt("pcId", id);
|
|
292
292
|
params.putString("iceGatheringState", iceGatheringStateString(iceGatheringState));
|
|
293
293
|
if (iceGatheringState == PeerConnection.IceGatheringState.COMPLETE) {
|
|
294
294
|
SessionDescription newSdp = peerConnection.getLocalDescription();
|
|
@@ -323,7 +323,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
323
323
|
info.putString("readyState", dcw.dataChannelStateString(dataChannel.state()));
|
|
324
324
|
|
|
325
325
|
WritableMap params = Arguments.createMap();
|
|
326
|
-
params.putInt("
|
|
326
|
+
params.putInt("pcId", id);
|
|
327
327
|
params.putMap("dataChannel", info);
|
|
328
328
|
|
|
329
329
|
webRTCModule.sendEvent("peerConnectionDidOpenDataChannel", params);
|
|
@@ -332,14 +332,14 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
332
332
|
@Override
|
|
333
333
|
public void onRenegotiationNeeded() {
|
|
334
334
|
WritableMap params = Arguments.createMap();
|
|
335
|
-
params.putInt("
|
|
335
|
+
params.putInt("pcId", id);
|
|
336
336
|
webRTCModule.sendEvent("peerConnectionOnRenegotiationNeeded", params);
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
@Override
|
|
340
340
|
public void onSignalingChange(PeerConnection.SignalingState signalingState) {
|
|
341
341
|
WritableMap params = Arguments.createMap();
|
|
342
|
-
params.putInt("
|
|
342
|
+
params.putInt("pcId", id);
|
|
343
343
|
params.putString("signalingState", signalingStateString(signalingState));
|
|
344
344
|
webRTCModule.sendEvent("peerConnectionSignalingStateChanged", params);
|
|
345
345
|
}
|
|
@@ -367,17 +367,17 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
367
367
|
|
|
368
368
|
final MediaStreamTrack track = receiver.track();
|
|
369
369
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
370
|
+
// We need to fire this event for an existing track sometimes, like
|
|
371
|
+
// when the transceiver direction (on the sending side) switches from
|
|
372
|
+
// sendrecv to recvonly and then back.
|
|
373
|
+
final boolean existingTrack = remoteTracks.containsKey(track.id());
|
|
376
374
|
|
|
377
|
-
if (
|
|
378
|
-
|
|
375
|
+
if (!existingTrack) {
|
|
376
|
+
if (track.kind().equals(MediaStreamTrack.VIDEO_TRACK_KIND)){
|
|
377
|
+
videoTrackAdapters.addAdapter((VideoTrack) track);
|
|
378
|
+
}
|
|
379
|
+
remoteTracks.put(track.id(), track);
|
|
379
380
|
}
|
|
380
|
-
remoteTracks.put(track.id(), track);
|
|
381
381
|
|
|
382
382
|
WritableMap params = Arguments.createMap();
|
|
383
383
|
WritableArray streams = Arguments.createArray();
|
|
@@ -402,8 +402,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
402
402
|
params.putMap("receiver", SerializeUtils.serializeReceiver(id, receiver));
|
|
403
403
|
params.putInt("transceiverOrder", getNextTransceiverId());
|
|
404
404
|
params.putMap("transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
|
|
405
|
-
|
|
406
|
-
params.putInt("id", this.id);
|
|
405
|
+
params.putInt("pcId", this.id);
|
|
407
406
|
|
|
408
407
|
webRTCModule.sendEvent("peerConnectionOnTrack", params);
|
|
409
408
|
});
|
|
@@ -424,18 +423,13 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
424
423
|
*/
|
|
425
424
|
@Override
|
|
426
425
|
public void onRemoveTrack(RtpReceiver receiver){
|
|
427
|
-
// According to the W3C spec, we need to send out
|
|
428
|
-
// the track Id so that we can remove it from the MediaStream objects stored
|
|
429
|
-
// at the JS layer, which are the same stream objects passed down to
|
|
430
|
-
// the `track` event.
|
|
431
426
|
ThreadUtils.runOnExecutor(() -> {
|
|
432
427
|
MediaStreamTrack track = receiver.track();
|
|
433
428
|
WritableMap params = Arguments.createMap();
|
|
434
|
-
params.putInt("
|
|
429
|
+
params.putInt("pcId", this.id);
|
|
435
430
|
params.putString("trackId", track.id());
|
|
436
431
|
|
|
437
432
|
webRTCModule.sendEvent("peerConnectionOnRemoveTrack", params);
|
|
438
|
-
|
|
439
433
|
});
|
|
440
434
|
};
|
|
441
435
|
|
|
@@ -115,7 +115,7 @@ public class VideoTrackAdapter {
|
|
|
115
115
|
|
|
116
116
|
private void emitMuteEvent(boolean muted) {
|
|
117
117
|
WritableMap params = Arguments.createMap();
|
|
118
|
-
params.putInt("
|
|
118
|
+
params.putInt("pcId", peerConnectionId);
|
|
119
119
|
params.putString("trackId", trackId);
|
|
120
120
|
params.putBoolean("muted", muted);
|
|
121
121
|
|
|
@@ -107,6 +107,10 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
107
107
|
.setInjectableLogger(injectableLogger, loggingSeverity)
|
|
108
108
|
.createInitializationOptions());
|
|
109
109
|
|
|
110
|
+
if (injectableLogger == null && loggingSeverity != null) {
|
|
111
|
+
Logging.enableLogToDebugOutput(loggingSeverity);
|
|
112
|
+
}
|
|
113
|
+
|
|
110
114
|
if (encoderFactory == null || decoderFactory == null) {
|
|
111
115
|
// Initialize EGL context required for HW acceleration.
|
|
112
116
|
EglBase.Context eglContext = EglUtils.getRootEglBaseContext();
|
|
@@ -161,16 +165,6 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
161
165
|
.emit(eventName, params);
|
|
162
166
|
}
|
|
163
167
|
|
|
164
|
-
void sendError(String eventName, String funcName, @Nullable String message, @Nullable ReadableMap info) {
|
|
165
|
-
WritableMap errorInfo = Arguments.createMap();
|
|
166
|
-
errorInfo.putString("func", funcName);
|
|
167
|
-
if (info != null)
|
|
168
|
-
errorInfo.putMap("info", info);
|
|
169
|
-
if (message != null)
|
|
170
|
-
errorInfo.putString("message", message);
|
|
171
|
-
sendEvent(eventName, errorInfo);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
168
|
private PeerConnection.IceServer createIceServer(String url) {
|
|
175
169
|
return PeerConnection.IceServer.builder(url).createIceServer();
|
|
176
170
|
}
|
|
@@ -591,6 +585,29 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
591
585
|
}
|
|
592
586
|
}
|
|
593
587
|
|
|
588
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
589
|
+
public boolean peerConnectionRemoveTrack(int id, String senderId) {
|
|
590
|
+
try {
|
|
591
|
+
return (boolean) ThreadUtils.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
|
+
}
|
|
602
|
+
|
|
603
|
+
return pco.getPeerConnection().removeTrack(sender);
|
|
604
|
+
}).get();
|
|
605
|
+
} catch (InterruptedException | ExecutionException e) {
|
|
606
|
+
Log.d(TAG, "peerConnectionRemoveTrack() " + e.getMessage());
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
594
611
|
@ReactMethod
|
|
595
612
|
public void senderSetParameters(int id, String senderId, ReadableMap options, Promise promise) {
|
|
596
613
|
ThreadUtils.runOnExecutor(() ->{
|
|
@@ -621,62 +638,27 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
621
638
|
}
|
|
622
639
|
|
|
623
640
|
@ReactMethod
|
|
624
|
-
public void
|
|
625
|
-
ThreadUtils.runOnExecutor(() -> {
|
|
626
|
-
WritableMap identifier = Arguments.createMap();
|
|
627
|
-
identifier.putInt("peerConnectionId", id);
|
|
628
|
-
identifier.putString("senderId", senderId);
|
|
629
|
-
try {
|
|
630
|
-
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
631
|
-
if (pco == null) {
|
|
632
|
-
Log.d(TAG, "peerConnectionRemoveTrack() peerConnection is null");
|
|
633
|
-
sendError("peerConnectionOnError", "removeTrack", "Peer Connection is not initialized", null);
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
RtpSender sender = pco.getSender(senderId);
|
|
637
|
-
if (sender == null) {
|
|
638
|
-
Log.w(TAG, "peerConnectionRemoveTrack() sender is null");
|
|
639
|
-
sendError("peerConnectionOnError", "removeTrack", "Sender is null", null);
|
|
640
|
-
return;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
boolean successful = pco.getPeerConnection().removeTrack(sender);
|
|
644
|
-
if (successful) {
|
|
645
|
-
sendEvent("peerConnectionOnRemoveTrackSuccessful", identifier);
|
|
646
|
-
return;
|
|
647
|
-
}
|
|
648
|
-
sendError("peerConnectionOnError", "removeTrack", "Internal Error", identifier);
|
|
649
|
-
} catch (Exception e) {
|
|
650
|
-
Log.d(TAG, "peerConnectionRemoveTrack() " + e.getMessage());
|
|
651
|
-
sendError("peerConnectionOnError", "removeTrack", e.getMessage(), identifier);
|
|
652
|
-
}
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
@ReactMethod
|
|
657
|
-
public void transceiverStop(int id,
|
|
658
|
-
String senderId) {
|
|
641
|
+
public void transceiverStop(int id, String senderId, Promise promise) {
|
|
659
642
|
ThreadUtils.runOnExecutor(() -> {
|
|
660
|
-
WritableMap identifier = Arguments.createMap();
|
|
661
|
-
identifier.putInt("peerConnectionId", id);
|
|
662
|
-
identifier.putString("transceiverId", senderId);
|
|
663
643
|
try {
|
|
664
644
|
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
665
645
|
if (pco == null) {
|
|
666
646
|
Log.d(TAG, "transceiverStop() peerConnectionObserver is null");
|
|
667
|
-
|
|
668
|
-
// hasn't really been initialized, this call from the web API should technically
|
|
669
|
-
// not happen unless both peer connection and transceivers are initialized properly
|
|
670
|
-
// That is why constructors or create methods should always be synchronous.
|
|
647
|
+
promise.reject(new Exception("Peer Connection is not initialized"));
|
|
671
648
|
return;
|
|
672
649
|
}
|
|
673
650
|
RtpTransceiver transceiver = pco.getTransceiver(senderId);
|
|
651
|
+
if (transceiver == null) {
|
|
652
|
+
Log.w(TAG, "transceiverStop() transceiver is null");
|
|
653
|
+
promise.reject(new Exception("Could not get transceiver"));
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
674
656
|
|
|
675
657
|
transceiver.stopStandard();
|
|
676
|
-
|
|
658
|
+
promise.resolve(true);
|
|
677
659
|
} catch (Exception e) {
|
|
678
660
|
Log.d(TAG, "transceiverStop(): " + e.getMessage());
|
|
679
|
-
|
|
661
|
+
promise.reject(e);
|
|
680
662
|
}
|
|
681
663
|
});
|
|
682
664
|
}
|
|
@@ -715,7 +697,8 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
715
697
|
@ReactMethod
|
|
716
698
|
public void transceiverSetDirection(int id,
|
|
717
699
|
String senderId,
|
|
718
|
-
String direction
|
|
700
|
+
String direction,
|
|
701
|
+
Promise promise) {
|
|
719
702
|
|
|
720
703
|
ThreadUtils.runOnExecutor(() -> {
|
|
721
704
|
WritableMap identifier = Arguments.createMap();
|
|
@@ -726,24 +709,22 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
726
709
|
PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
|
|
727
710
|
if (pco == null) {
|
|
728
711
|
Log.d(TAG, "transceiverSetDirection() peerConnectionObserver is null");
|
|
729
|
-
|
|
730
|
-
// hasn't really been initialized, this call from the web API should technically
|
|
731
|
-
// not happen unless both peer connection and sender are initialized
|
|
712
|
+
promise.reject(new Exception("Peer Connection is not initialized"));
|
|
732
713
|
return;
|
|
733
714
|
}
|
|
734
715
|
RtpTransceiver transceiver = pco.getTransceiver(senderId);
|
|
735
716
|
if (transceiver == null){
|
|
736
717
|
Log.d(TAG, "transceiverSetDirection() transceiver is null");
|
|
718
|
+
promise.reject(new Exception("Could not get sender"));
|
|
737
719
|
return;
|
|
738
720
|
}
|
|
739
721
|
|
|
740
|
-
RtpTransceiver.RtpTransceiverDirection oldDirection = transceiver.getDirection();
|
|
741
|
-
params.putString("oldDirection", SerializeUtils.serializeDirection(oldDirection));
|
|
742
722
|
transceiver.setDirection(SerializeUtils.parseDirection(direction));
|
|
723
|
+
|
|
724
|
+
promise.resolve(true);
|
|
743
725
|
} catch (Exception e) {
|
|
744
726
|
Log.d(TAG, "transceiverSetDirection(): " + e.getMessage());
|
|
745
|
-
|
|
746
|
-
sendError("transceiverOnError", "setDirection", e.getMessage(), params);
|
|
727
|
+
promise.reject(e);
|
|
747
728
|
}
|
|
748
729
|
});
|
|
749
730
|
}
|
|
@@ -1014,11 +995,16 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1014
995
|
|
|
1015
996
|
@Override
|
|
1016
997
|
public void onSetSuccess() {
|
|
1017
|
-
SessionDescription newSdp = peerConnection.getLocalDescription();
|
|
1018
998
|
WritableMap newSdpMap = Arguments.createMap();
|
|
1019
999
|
WritableMap params = Arguments.createMap();
|
|
1020
|
-
|
|
1021
|
-
|
|
1000
|
+
|
|
1001
|
+
SessionDescription newSdp = peerConnection.getLocalDescription();
|
|
1002
|
+
// Can happen when doing a rollback.
|
|
1003
|
+
if (newSdp != null) {
|
|
1004
|
+
newSdpMap.putString("type", newSdp.type.canonicalForm());
|
|
1005
|
+
newSdpMap.putString("sdp", newSdp.description);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1022
1008
|
params.putMap("sdpInfo", newSdpMap);
|
|
1023
1009
|
params.putArray("transceiversInfo", getTransceiversInfo(pcId));
|
|
1024
1010
|
promise.resolve(params);
|
|
@@ -1077,11 +1063,16 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1077
1063
|
|
|
1078
1064
|
@Override
|
|
1079
1065
|
public void onSetSuccess() {
|
|
1080
|
-
SessionDescription newSdp = peerConnection.getRemoteDescription();
|
|
1081
1066
|
WritableMap newSdpMap = Arguments.createMap();
|
|
1082
1067
|
WritableMap params = Arguments.createMap();
|
|
1083
|
-
|
|
1084
|
-
|
|
1068
|
+
|
|
1069
|
+
SessionDescription newSdp = peerConnection.getRemoteDescription();
|
|
1070
|
+
// Be defensive for the rollback cases.
|
|
1071
|
+
if (newSdp != null) {
|
|
1072
|
+
newSdpMap.putString("type", newSdp.type.canonicalForm());
|
|
1073
|
+
newSdpMap.putString("sdp", newSdp.description);
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1085
1076
|
params.putArray("transceiversInfo", getTransceiversInfo(id));
|
|
1086
1077
|
params.putMap("sdpInfo", newSdpMap);
|
|
1087
1078
|
|
|
@@ -45,6 +45,16 @@
|
|
|
45
45
|
RCTLogConvertError(json, @".candidate must not be null");
|
|
46
46
|
return nil;
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
if (json[@"sdpMid"] == nil) {
|
|
50
|
+
RCTLogConvertError(json, @".sdpMid must not be null");
|
|
51
|
+
return nil;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (json[@"sdpMLineIndex"] == nil) {
|
|
55
|
+
RCTLogConvertError(json, @".sdpMLineIndex must not be null");
|
|
56
|
+
return nil;
|
|
57
|
+
}
|
|
48
58
|
|
|
49
59
|
NSString *sdp = json[@"candidate"];
|
|
50
60
|
RCTLogTrace(@"%@ <- candidate", sdp);
|
|
@@ -160,9 +160,11 @@
|
|
|
160
160
|
NSString *readyState;
|
|
161
161
|
switch (track.readyState) {
|
|
162
162
|
case RTCMediaStreamTrackStateLive:
|
|
163
|
-
readyState = @"
|
|
163
|
+
readyState = @"live";
|
|
164
|
+
break;
|
|
164
165
|
case RTCMediaStreamTrackStateEnded:
|
|
165
|
-
readyState = @"
|
|
166
|
+
readyState = @"ended";
|
|
167
|
+
break;
|
|
166
168
|
}
|
|
167
169
|
|
|
168
170
|
return @{
|
|
@@ -215,14 +215,17 @@ RCT_EXPORT_METHOD(peerConnectionSetLocalDescription:(nonnull NSNumber *)objectID
|
|
|
215
215
|
reject(@"E_OPERATION_ERROR", error.localizedDescription, nil);
|
|
216
216
|
} else {
|
|
217
217
|
RTCPeerConnection *strongPc = weakPc;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
218
|
+
NSMutableDictionary *sdpInfo = [NSMutableDictionary new];
|
|
219
|
+
RTCSessionDescription *localDesc = strongPc.localDescription;
|
|
220
|
+
if (localDesc) {
|
|
221
|
+
sdpInfo[@"type"] = [RTCSessionDescription stringForType:localDesc.type];
|
|
222
|
+
sdpInfo[@"sdp"] = localDesc.sdp;
|
|
223
|
+
}
|
|
224
|
+
id data = @{
|
|
225
|
+
@"sdpInfo": sdpInfo,
|
|
223
226
|
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID]
|
|
224
227
|
};
|
|
225
|
-
resolve(
|
|
228
|
+
resolve(data);
|
|
226
229
|
}
|
|
227
230
|
};
|
|
228
231
|
|
|
@@ -262,15 +265,19 @@ RCT_EXPORT_METHOD(peerConnectionSetRemoteDescription:(RTCSessionDescription *)sd
|
|
|
262
265
|
[newTransceivers addObject:newTransceiver];
|
|
263
266
|
}
|
|
264
267
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
|
|
269
|
+
NSMutableDictionary *sdpInfo = [NSMutableDictionary new];
|
|
270
|
+
RTCSessionDescription *remoteDesc = peerConnection.remoteDescription;
|
|
271
|
+
if (remoteDesc) {
|
|
272
|
+
sdpInfo[@"type"] = [RTCSessionDescription stringForType:remoteDesc.type];
|
|
273
|
+
sdpInfo[@"sdp"] = remoteDesc.sdp;
|
|
274
|
+
}
|
|
275
|
+
id data = @{
|
|
276
|
+
@"sdpInfo": sdpInfo,
|
|
270
277
|
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID],
|
|
271
278
|
@"newTransceivers": newTransceivers
|
|
272
279
|
};
|
|
273
|
-
callback(@[@(YES),
|
|
280
|
+
callback(@[@(YES), data]);
|
|
274
281
|
}
|
|
275
282
|
}];
|
|
276
283
|
}
|
|
@@ -482,46 +489,36 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver:(nonnull NSN
|
|
|
482
489
|
return params;
|
|
483
490
|
}
|
|
484
491
|
|
|
485
|
-
|
|
486
|
-
|
|
492
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumber *)objectID
|
|
493
|
+
senderId:(nonnull NSString *)senderId)
|
|
487
494
|
{
|
|
495
|
+
__block BOOL ret = NO;
|
|
496
|
+
|
|
497
|
+
dispatch_sync(self.workerQueue, ^{
|
|
488
498
|
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
489
499
|
if (!peerConnection) {
|
|
490
500
|
RCTLogWarn(@"PeerConnection %@ not found in peerConnectionRemoveTrack()", objectID);
|
|
491
|
-
[self sendErrorWithEventName: kEventPeerConnectionOnError
|
|
492
|
-
funcName: @"removeTrack"
|
|
493
|
-
message: @"Peer Connection is not initialized"
|
|
494
|
-
info: nil];
|
|
495
501
|
return;
|
|
496
502
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
for (
|
|
501
|
-
if ([
|
|
502
|
-
|
|
503
|
+
|
|
504
|
+
RTCRtpSender *sender = nil;
|
|
505
|
+
|
|
506
|
+
for (RTCRtpSender *s in peerConnection.senders) {
|
|
507
|
+
if ([s.senderId isEqual: senderId]) {
|
|
508
|
+
sender = s;
|
|
503
509
|
break;
|
|
504
510
|
}
|
|
505
511
|
}
|
|
506
|
-
|
|
507
|
-
if (!
|
|
508
|
-
RCTLogWarn(@"
|
|
512
|
+
|
|
513
|
+
if (!sender) {
|
|
514
|
+
RCTLogWarn(@"Sender not found in peerConnectionRemoveTrack()");
|
|
509
515
|
return;
|
|
510
516
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
if ([peerConnection removeTrack: transceiver.sender]) {
|
|
517
|
-
[self sendEventWithName: kEventPeerConnectionOnRemoveTrackSuccessful
|
|
518
|
-
body: identifier];
|
|
519
|
-
} else {
|
|
520
|
-
[self sendErrorWithEventName: kEventPeerConnectionOnError
|
|
521
|
-
funcName: @"removeTrack"
|
|
522
|
-
message: @"Cannot remove track"
|
|
523
|
-
info: identifier];
|
|
524
|
-
}
|
|
517
|
+
|
|
518
|
+
ret = [peerConnection removeTrack: sender];
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
return @(ret);
|
|
525
522
|
}
|
|
526
523
|
|
|
527
524
|
// TODO: move these below to some SerializeUrils file
|
|
@@ -703,25 +700,25 @@ RCT_EXPORT_METHOD(peerConnectionRemoveTrack:(nonnull NSNumber *)objectID
|
|
|
703
700
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeSignalingState:(RTCSignalingState)newState {
|
|
704
701
|
[self sendEventWithName:kEventPeerConnectionSignalingStateChanged
|
|
705
702
|
body:@{
|
|
706
|
-
@"
|
|
703
|
+
@"pcId": peerConnection.reactTag,
|
|
707
704
|
@"signalingState": [self stringForSignalingState:newState]
|
|
708
705
|
}];
|
|
709
706
|
}
|
|
710
707
|
|
|
711
708
|
- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection {
|
|
712
709
|
[self sendEventWithName:kEventPeerConnectionOnRenegotiationNeeded
|
|
713
|
-
body:@{ @"
|
|
710
|
+
body:@{ @"pcId": peerConnection.reactTag }];
|
|
714
711
|
}
|
|
715
712
|
|
|
716
713
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeConnectionState:(RTCPeerConnectionState)newState {
|
|
717
714
|
[self sendEventWithName:kEventPeerConnectionStateChanged
|
|
718
|
-
body:@{@"
|
|
715
|
+
body:@{@"pcId": peerConnection.reactTag, @"connectionState": [self stringForPeerConnectionState:newState]}];
|
|
719
716
|
}
|
|
720
717
|
|
|
721
718
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeIceConnectionState:(RTCIceConnectionState)newState {
|
|
722
719
|
[self sendEventWithName:kEventPeerConnectionIceConnectionChanged
|
|
723
720
|
body:@{
|
|
724
|
-
@"
|
|
721
|
+
@"pcId": peerConnection.reactTag,
|
|
725
722
|
@"iceConnectionState": [self stringForICEConnectionState:newState]
|
|
726
723
|
}];
|
|
727
724
|
}
|
|
@@ -736,7 +733,7 @@ RCT_EXPORT_METHOD(peerConnectionRemoveTrack:(nonnull NSNumber *)objectID
|
|
|
736
733
|
}
|
|
737
734
|
[self sendEventWithName:kEventPeerConnectionIceGatheringChanged
|
|
738
735
|
body:@{
|
|
739
|
-
@"
|
|
736
|
+
@"pcId": peerConnection.reactTag,
|
|
740
737
|
@"iceGatheringState": [self stringForICEGatheringState:newState],
|
|
741
738
|
@"sdp": newSdp
|
|
742
739
|
}];
|
|
@@ -745,7 +742,7 @@ RCT_EXPORT_METHOD(peerConnectionRemoveTrack:(nonnull NSNumber *)objectID
|
|
|
745
742
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didGenerateIceCandidate:(RTCIceCandidate *)candidate {
|
|
746
743
|
[self sendEventWithName:kEventPeerConnectionGotICECandidate
|
|
747
744
|
body:@{
|
|
748
|
-
@"
|
|
745
|
+
@"pcId": peerConnection.reactTag,
|
|
749
746
|
@"candidate": @{
|
|
750
747
|
@"candidate": candidate.sdp,
|
|
751
748
|
@"sdpMLineIndex": @(candidate.sdpMLineIndex),
|
|
@@ -778,7 +775,7 @@ RCT_EXPORT_METHOD(peerConnectionRemoveTrack:(nonnull NSNumber *)objectID
|
|
|
778
775
|
@"readyState": [self stringForDataChannelState:dataChannel.readyState]
|
|
779
776
|
};
|
|
780
777
|
NSDictionary *body = @{
|
|
781
|
-
@"
|
|
778
|
+
@"pcId": peerConnection.reactTag,
|
|
782
779
|
@"dataChannel": dataChannelInfo
|
|
783
780
|
};
|
|
784
781
|
[self sendEventWithName:kEventPeerConnectionDidOpenDataChannel body:body];
|
|
@@ -802,17 +799,20 @@ RCT_EXPORT_METHOD(peerConnectionRemoveTrack:(nonnull NSNumber *)objectID
|
|
|
802
799
|
|
|
803
800
|
RTCMediaStreamTrack *track = rtpReceiver.track;
|
|
804
801
|
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
802
|
+
// We need to fire this event for an existing track sometimes, like
|
|
803
|
+
// when the transceiver direction (on the sending side) switches from
|
|
804
|
+
// sendrecv to recvonly and then back.
|
|
805
|
+
BOOL existingTrack = peerConnection.remoteTracks[track.trackId] != nil;
|
|
806
|
+
|
|
807
|
+
if (!existingTrack) {
|
|
808
|
+
if (track.kind == kRTCMediaStreamTrackKindVideo) {
|
|
809
|
+
RTCVideoTrack *videoTrack = (RTCVideoTrack *)track;
|
|
810
|
+
[peerConnection addVideoTrackAdapter: videoTrack];
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
peerConnection.remoteTracks[track.trackId] = track;
|
|
812
814
|
}
|
|
813
815
|
|
|
814
|
-
peerConnection.remoteTracks[track.trackId] = track;
|
|
815
|
-
|
|
816
816
|
NSMutableDictionary *params = [NSMutableDictionary new];
|
|
817
817
|
NSMutableArray *streams = [NSMutableArray new];
|
|
818
818
|
|
|
@@ -843,10 +843,23 @@ RCT_EXPORT_METHOD(peerConnectionRemoveTrack:(nonnull NSNumber *)objectID
|
|
|
843
843
|
params[@"receiver"] = [SerializeUtils receiverToJSONWithPeerConnectionId: peerConnection.reactTag receiver: rtpReceiver];
|
|
844
844
|
params[@"transceiverOrder"] = [NSNumber numberWithInt:_transceiverNextId++];
|
|
845
845
|
params[@"transceiver"] = [SerializeUtils transceiverToJSONWithPeerConnectionId: peerConnection.reactTag transceiver: transceiver];
|
|
846
|
-
params[@"
|
|
846
|
+
params[@"pcId"] = peerConnection.reactTag;
|
|
847
847
|
|
|
848
|
-
[self sendEventWithName: kEventPeerConnectionOnTrack
|
|
849
|
-
|
|
848
|
+
[self sendEventWithName: kEventPeerConnectionOnTrack body: params];
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection
|
|
853
|
+
didRemoveReceiver:(RTC_OBJC_TYPE(RTCRtpReceiver) *)rtpReceiver {
|
|
854
|
+
dispatch_async(self.workerQueue, ^{
|
|
855
|
+
RTCMediaStreamTrack *track = rtpReceiver.track;
|
|
856
|
+
|
|
857
|
+
NSMutableDictionary *params = [NSMutableDictionary new];
|
|
858
|
+
|
|
859
|
+
params[@"pcId"] = peerConnection.reactTag;
|
|
860
|
+
params[@"trackId"] = track.trackId;
|
|
861
|
+
|
|
862
|
+
[self sendEventWithName: kEventPeerConnectionOnRemoveTrack body: params];
|
|
850
863
|
});
|
|
851
864
|
}
|
|
852
865
|
|