react-native-webrtc 1.100.1 → 106.0.0-beta.2

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.
Files changed (166) hide show
  1. package/ISSUE_TEMPLATE.md +17 -13
  2. package/README.md +46 -129
  3. package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +160 -165
  4. package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +279 -0
  5. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +361 -56
  6. package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +5 -1
  7. package/ios/RCTWebRTC/RCTConvert+WebRTC.m +2 -6
  8. package/ios/RCTWebRTC/ScreenCapturer.m +0 -1
  9. package/ios/RCTWebRTC/SerializeUtils.h +25 -0
  10. package/ios/RCTWebRTC/SerializeUtils.m +219 -0
  11. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +284 -128
  12. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +216 -0
  13. package/ios/RCTWebRTC/WebRTCModule.h +15 -4
  14. package/ios/RCTWebRTC/WebRTCModule.m +26 -6
  15. package/lib/commonjs/EventEmitter.js +24 -0
  16. package/lib/commonjs/EventEmitter.js.map +1 -1
  17. package/lib/commonjs/Logger.js +65 -0
  18. package/lib/commonjs/Logger.js.map +1 -0
  19. package/lib/commonjs/MediaStream.js +1 -1
  20. package/lib/commonjs/MediaStream.js.map +1 -1
  21. package/lib/commonjs/MediaStreamTrack.js +4 -2
  22. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  23. package/lib/commonjs/Permissions.js +1 -1
  24. package/lib/commonjs/Permissions.js.map +1 -1
  25. package/lib/commonjs/RTCDataChannel.js.map +1 -1
  26. package/lib/commonjs/RTCErrorEvent.js +33 -0
  27. package/lib/commonjs/RTCErrorEvent.js.map +1 -0
  28. package/lib/commonjs/RTCPeerConnection.js +380 -102
  29. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  30. package/lib/commonjs/RTCRtcpParameters.js +24 -0
  31. package/lib/commonjs/RTCRtcpParameters.js.map +1 -0
  32. package/lib/commonjs/RTCRtpCapabilities.js +79 -0
  33. package/lib/commonjs/RTCRtpCapabilities.js.map +1 -0
  34. package/lib/commonjs/RTCRtpCodecCapability.js +25 -0
  35. package/lib/commonjs/RTCRtpCodecCapability.js.map +1 -0
  36. package/lib/commonjs/RTCRtpCodecParameters.js +33 -0
  37. package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -0
  38. package/lib/commonjs/RTCRtpEncodingParameters.js +81 -0
  39. package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -0
  40. package/lib/commonjs/RTCRtpHeaderExtension.js +27 -0
  41. package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -0
  42. package/lib/commonjs/RTCRtpParameters.js +26 -0
  43. package/lib/commonjs/RTCRtpParameters.js.map +1 -0
  44. package/lib/commonjs/RTCRtpReceiveParameters.js +20 -0
  45. package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -0
  46. package/lib/commonjs/RTCRtpReceiver.js +51 -0
  47. package/lib/commonjs/RTCRtpReceiver.js.map +1 -0
  48. package/lib/commonjs/RTCRtpSendParameters.js +60 -0
  49. package/lib/commonjs/RTCRtpSendParameters.js.map +1 -0
  50. package/lib/commonjs/RTCRtpSender.js +85 -0
  51. package/lib/commonjs/RTCRtpSender.js.map +1 -0
  52. package/lib/commonjs/RTCRtpTransceiver.js +141 -0
  53. package/lib/commonjs/RTCRtpTransceiver.js.map +1 -0
  54. package/lib/commonjs/RTCSessionDescription.js.map +1 -1
  55. package/lib/commonjs/RTCTrackEvent.js +32 -0
  56. package/lib/commonjs/RTCTrackEvent.js.map +1 -0
  57. package/lib/commonjs/RTCUtil.js +20 -37
  58. package/lib/commonjs/RTCUtil.js.map +1 -1
  59. package/lib/commonjs/getDisplayMedia.js.map +1 -1
  60. package/lib/commonjs/getUserMedia.js.map +1 -1
  61. package/lib/commonjs/index.js +127 -3
  62. package/lib/commonjs/index.js.map +1 -1
  63. package/lib/module/EventEmitter.js +21 -0
  64. package/lib/module/EventEmitter.js.map +1 -1
  65. package/lib/module/Logger.js +53 -0
  66. package/lib/module/Logger.js.map +1 -0
  67. package/lib/module/MediaStream.js +1 -1
  68. package/lib/module/MediaStream.js.map +1 -1
  69. package/lib/module/MediaStreamTrack.js +4 -2
  70. package/lib/module/MediaStreamTrack.js.map +1 -1
  71. package/lib/module/Permissions.js +1 -1
  72. package/lib/module/Permissions.js.map +1 -1
  73. package/lib/module/RTCDataChannel.js.map +1 -1
  74. package/lib/module/RTCErrorEvent.js +22 -0
  75. package/lib/module/RTCErrorEvent.js.map +1 -0
  76. package/lib/module/RTCPeerConnection.js +373 -102
  77. package/lib/module/RTCPeerConnection.js.map +1 -1
  78. package/lib/module/RTCRtcpParameters.js +15 -0
  79. package/lib/module/RTCRtcpParameters.js.map +1 -0
  80. package/lib/module/RTCRtpCapabilities.js +63 -0
  81. package/lib/module/RTCRtpCapabilities.js.map +1 -0
  82. package/lib/module/RTCRtpCodecCapability.js +16 -0
  83. package/lib/module/RTCRtpCodecCapability.js.map +1 -0
  84. package/lib/module/RTCRtpCodecParameters.js +24 -0
  85. package/lib/module/RTCRtpCodecParameters.js.map +1 -0
  86. package/lib/module/RTCRtpEncodingParameters.js +72 -0
  87. package/lib/module/RTCRtpEncodingParameters.js.map +1 -0
  88. package/lib/module/RTCRtpHeaderExtension.js +18 -0
  89. package/lib/module/RTCRtpHeaderExtension.js.map +1 -0
  90. package/lib/module/RTCRtpParameters.js +17 -0
  91. package/lib/module/RTCRtpParameters.js.map +1 -0
  92. package/lib/module/RTCRtpReceiveParameters.js +8 -0
  93. package/lib/module/RTCRtpReceiveParameters.js.map +1 -0
  94. package/lib/module/RTCRtpReceiver.js +39 -0
  95. package/lib/module/RTCRtpReceiver.js.map +1 -0
  96. package/lib/module/RTCRtpSendParameters.js +49 -0
  97. package/lib/module/RTCRtpSendParameters.js.map +1 -0
  98. package/lib/module/RTCRtpSender.js +70 -0
  99. package/lib/module/RTCRtpSender.js.map +1 -0
  100. package/lib/module/RTCRtpTransceiver.js +125 -0
  101. package/lib/module/RTCRtpTransceiver.js.map +1 -0
  102. package/lib/module/RTCSessionDescription.js.map +1 -1
  103. package/lib/module/RTCTrackEvent.js +23 -0
  104. package/lib/module/RTCTrackEvent.js.map +1 -0
  105. package/lib/module/RTCUtil.js +18 -36
  106. package/lib/module/RTCUtil.js.map +1 -1
  107. package/lib/module/getDisplayMedia.js.map +1 -1
  108. package/lib/module/getUserMedia.js.map +1 -1
  109. package/lib/module/index.js +35 -4
  110. package/lib/module/index.js.map +1 -1
  111. package/lib/typescript/EventEmitter.d.ts +3 -0
  112. package/lib/typescript/Logger.d.ts +13 -0
  113. package/lib/typescript/MediaDevices.d.ts +2 -2
  114. package/lib/typescript/MediaStream.d.ts +6 -6
  115. package/lib/typescript/MediaStreamTrack.d.ts +10 -9
  116. package/lib/typescript/RTCDataChannel.d.ts +4 -2
  117. package/lib/typescript/RTCErrorEvent.d.ts +12 -0
  118. package/lib/typescript/RTCPeerConnection.d.ts +42 -11
  119. package/lib/typescript/RTCRtcpParameters.d.ts +8 -0
  120. package/lib/typescript/RTCRtpCapabilities.d.ts +19 -0
  121. package/lib/typescript/RTCRtpCodecCapability.d.ts +7 -0
  122. package/lib/typescript/RTCRtpCodecParameters.d.ts +14 -0
  123. package/lib/typescript/RTCRtpEncodingParameters.d.ts +21 -0
  124. package/lib/typescript/RTCRtpHeaderExtension.d.ts +10 -0
  125. package/lib/typescript/RTCRtpParameters.d.ts +14 -0
  126. package/lib/typescript/RTCRtpReceiveParameters.d.ts +4 -0
  127. package/lib/typescript/RTCRtpReceiver.d.ts +15 -0
  128. package/lib/typescript/RTCRtpSendParameters.d.ts +17 -0
  129. package/lib/typescript/RTCRtpSender.d.ts +21 -0
  130. package/lib/typescript/RTCRtpTransceiver.d.ts +35 -0
  131. package/lib/typescript/RTCTrackEvent.d.ts +15 -0
  132. package/lib/typescript/RTCUtil.d.ts +5 -9
  133. package/lib/typescript/getDisplayMedia.d.ts +2 -1
  134. package/lib/typescript/getUserMedia.d.ts +2 -1
  135. package/lib/typescript/index.d.ts +16 -3
  136. package/package.json +6 -4
  137. package/react-native-webrtc.podspec +1 -1
  138. package/src/EventEmitter.ts +21 -1
  139. package/src/Logger.ts +49 -0
  140. package/src/MediaStream.ts +11 -11
  141. package/src/MediaStreamTrack.ts +14 -13
  142. package/src/Permissions.ts +1 -1
  143. package/src/RTCDataChannel.ts +11 -8
  144. package/src/RTCErrorEvent.ts +21 -0
  145. package/src/RTCPeerConnection.ts +423 -156
  146. package/src/RTCRtcpParameters.ts +14 -0
  147. package/src/RTCRtpCapabilities.ts +54 -0
  148. package/src/RTCRtpCodecCapability.ts +13 -0
  149. package/src/RTCRtpCodecParameters.ts +23 -0
  150. package/src/RTCRtpEncodingParameters.ts +67 -0
  151. package/src/RTCRtpHeaderExtension.ts +18 -0
  152. package/src/RTCRtpParameters.ts +21 -0
  153. package/src/RTCRtpReceiveParameters.ts +7 -0
  154. package/src/RTCRtpReceiver.ts +35 -0
  155. package/src/RTCRtpSendParameters.ts +51 -0
  156. package/src/RTCRtpSender.ts +72 -0
  157. package/src/RTCRtpTransceiver.ts +125 -0
  158. package/src/RTCSessionDescription.ts +3 -3
  159. package/src/RTCTrackEvent.ts +21 -0
  160. package/src/RTCUtil.ts +20 -40
  161. package/src/getDisplayMedia.ts +1 -1
  162. package/src/getUserMedia.ts +2 -2
  163. package/src/index.ts +51 -6
  164. package/tools/build-webrtc.py +32 -33
  165. package/tools/downloadBitcode.sh +2 -12
  166. package/tools/downloadWebRTC.js +21 -12
@@ -17,6 +17,7 @@ import com.facebook.react.bridge.ReadableMap;
17
17
  import com.facebook.react.bridge.ReadableMapKeySetIterator;
18
18
  import com.facebook.react.bridge.ReadableType;
19
19
  import com.facebook.react.bridge.WritableMap;
20
+ import com.facebook.react.bridge.WritableArray;
20
21
  import com.facebook.react.module.annotations.ReactModule;
21
22
  import com.facebook.react.modules.core.DeviceEventManagerModule;
22
23
 
@@ -37,6 +38,10 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
37
38
  static final String TAG = WebRTCModule.class.getCanonicalName();
38
39
 
39
40
  PeerConnectionFactory mFactory;
41
+ VideoEncoderFactory mVideoEncoderFactory;
42
+ VideoDecoderFactory mVideoDecoderFactory;
43
+
44
+ // Need to expose the peer connection codec factories here to get capabilities
40
45
  private final SparseArray<PeerConnectionObserver> mPeerConnectionObservers;
41
46
  final Map<String, MediaStream> localStreams;
42
47
 
@@ -120,7 +125,9 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
120
125
  }
121
126
 
122
127
  if (adm == null) {
123
- adm = JavaAudioDeviceModule.builder(reactContext).createAudioDeviceModule();
128
+ adm = JavaAudioDeviceModule.builder(reactContext)
129
+ .setEnableVolumeLogger(false)
130
+ .createAudioDeviceModule();
124
131
  }
125
132
 
126
133
  mFactory
@@ -130,6 +137,10 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
130
137
  .setVideoDecoderFactory(decoderFactory)
131
138
  .createPeerConnectionFactory();
132
139
 
140
+ // Saving the encoder and decoder factories to get codec info later when needed
141
+ mVideoEncoderFactory = encoderFactory;
142
+ mVideoDecoderFactory = decoderFactory;
143
+
133
144
  getUserMediaImpl = new GetUserMediaImpl(this, reactContext);
134
145
  }
135
146
 
@@ -144,12 +155,22 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
144
155
  return (pco == null) ? null : pco.getPeerConnection();
145
156
  }
146
157
 
147
- void sendEvent(String eventName, @Nullable WritableMap params) {
158
+ void sendEvent(String eventName, @Nullable ReadableMap params) {
148
159
  getReactApplicationContext()
149
160
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
150
161
  .emit(eventName, params);
151
162
  }
152
163
 
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
+
153
174
  private PeerConnection.IceServer createIceServer(String url) {
154
175
  return PeerConnection.IceServer.builder(url).createIceServer();
155
176
  }
@@ -167,13 +188,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
167
188
  for (int i = 0; i < size; i++) {
168
189
  ReadableMap iceServerMap = iceServersArray.getMap(i);
169
190
  boolean hasUsernameAndCredential = iceServerMap.hasKey("username") && iceServerMap.hasKey("credential");
170
- if (iceServerMap.hasKey("url")) {
171
- if (hasUsernameAndCredential) {
172
- iceServers.add(createIceServer(iceServerMap.getString("url"), iceServerMap.getString("username"), iceServerMap.getString("credential")));
173
- } else {
174
- iceServers.add(createIceServer(iceServerMap.getString("url")));
175
- }
176
- } else if (iceServerMap.hasKey("urls")) {
191
+ if (iceServerMap.hasKey("urls")) {
177
192
  switch (iceServerMap.getType("urls")) {
178
193
  case String:
179
194
  if (hasUsernameAndCredential) {
@@ -210,8 +225,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
210
225
  // Required for perfect negotiation.
211
226
  conf.enableImplicitRollback = true;
212
227
 
213
- // Plan B, just a little longer.
214
- conf.sdpSemantics = PeerConnection.SdpSemantics.PLAN_B;
228
+ conf.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN;
215
229
 
216
230
  if (map == null) {
217
231
  return conf;
@@ -442,7 +456,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
442
456
  }
443
457
  }
444
458
 
445
- private MediaStreamTrack getTrack(String trackId) {
459
+ public MediaStreamTrack getTrack(String trackId) {
446
460
  MediaStreamTrack track = getLocalTrack(trackId);
447
461
 
448
462
  if (track == null) {
@@ -485,6 +499,255 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
485
499
  return mediaConstraints;
486
500
  }
487
501
 
502
+
503
+
504
+ @ReactMethod(isBlockingSynchronousMethod = true)
505
+ public WritableMap peerConnectionAddTransceiver(int id, ReadableMap options) {
506
+ try {
507
+ return (WritableMap) ThreadUtils.submitToExecutor((Callable<Object>) () -> {
508
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
509
+ if (pco == null) {
510
+ Log.d(TAG, "peerConnectionAddTransceiver() peerConnection is null");
511
+ return null;
512
+ }
513
+
514
+ RtpTransceiver transceiver = null;
515
+ if (options.hasKey("type")) {
516
+ String kind = options.getString("type");
517
+ transceiver = pco.addTransceiver(SerializeUtils.parseMediaType(kind),
518
+ SerializeUtils.parseTransceiverOptions(options.getMap("init")));
519
+ } else if (options.hasKey("trackId")) {
520
+ String trackId = options.getString("trackId");
521
+ MediaStreamTrack track = getTrack(trackId);
522
+ transceiver = pco.addTransceiver(track,
523
+ SerializeUtils.parseTransceiverOptions(options.getMap("init")));
524
+
525
+ } else {
526
+ // This should technically never happen as the JS side checks for that.
527
+ Log.d(TAG, "peerConnectionAddTransceiver() no type nor trackId provided in options");
528
+ return null;
529
+ }
530
+
531
+ if (transceiver == null) {
532
+ Log.d(TAG, "peerConnectionAddTransceiver() Error adding transceiver");
533
+ return null;
534
+ }
535
+ WritableMap params = Arguments.createMap();
536
+ // We need to get a unique order at which the transceiver was created
537
+ // to reorder the cached array of transceivers on the JS layer.
538
+ params.putInt("transceiverOrder", pco.getNextTransceiverId());
539
+ params.putMap("transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
540
+ return params;
541
+ }).get();
542
+ } catch (InterruptedException | ExecutionException e) {
543
+ Log.d(TAG, "peerConnectionAddTransceiver() " + e.getMessage());
544
+ return null;
545
+ }
546
+ }
547
+
548
+ @ReactMethod(isBlockingSynchronousMethod = true)
549
+ public WritableMap peerConnectionAddTrack(int id,
550
+ String trackId,
551
+ ReadableMap options) {
552
+ try {
553
+ return (WritableMap) ThreadUtils.submitToExecutor((Callable<Object>) () -> {
554
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
555
+ if (pco == null) {
556
+ Log.d(TAG, "peerConnectionAddTrack() peerConnection is null");
557
+ return null;
558
+ }
559
+
560
+ MediaStreamTrack track = getLocalTrack(trackId);
561
+ if (track == null) {
562
+ Log.w(TAG, "peerConnectionAddTrack() couldn't find track " + trackId);
563
+ return null;
564
+ }
565
+
566
+ List<String> streamIds = new ArrayList<>();
567
+ if (options.hasKey("streamIds")) {
568
+ ReadableArray rawStreamIds = options.getArray("streamIds");
569
+ if (rawStreamIds != null) {
570
+ for (int i = 0; i < rawStreamIds.size(); i++) {
571
+ streamIds.add(rawStreamIds.getString(i));
572
+ }
573
+ }
574
+ }
575
+ RtpSender sender = pco.getPeerConnection().addTrack(track, streamIds);
576
+
577
+ // Need to get the corresponding transceiver as well
578
+ RtpTransceiver transceiver = pco.getTransceiver(sender.id());
579
+
580
+ // We need the transceiver creation order to reorder the transceivers array
581
+ // in the JS layer.
582
+ WritableMap params = Arguments.createMap();
583
+ params.putInt("transceiverOrder", pco.getNextTransceiverId());
584
+ params.putMap("transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
585
+ params.putMap("sender", SerializeUtils.serializeSender(id, sender));
586
+ return params;
587
+ }).get();
588
+ } catch (InterruptedException | ExecutionException e) {
589
+ Log.d(TAG, "peerConnectionAddTrack() " + e.getMessage());
590
+ return null;
591
+ }
592
+ }
593
+
594
+ @ReactMethod
595
+ public void senderSetParameters(int id, String senderId, ReadableMap options, Promise promise) {
596
+ ThreadUtils.runOnExecutor(() ->{
597
+ try {
598
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
599
+ if (pco == null) {
600
+ Log.d(TAG, "senderSetParameters() peerConnectionObserver is null");
601
+ promise.reject(new Exception("Peer Connection is not initialized"));
602
+ return;
603
+ }
604
+
605
+ RtpSender sender = pco.getSender(senderId);
606
+ if (sender == null) {
607
+ Log.w(TAG, "senderSetParameters() sender is null");
608
+ promise.reject(new Exception("Could not get sender"));
609
+ return;
610
+ }
611
+
612
+ RtpParameters params = sender.getParameters();
613
+ params = SerializeUtils.updateRtpParameters(options, params);
614
+ sender.setParameters(params);
615
+ promise.resolve(SerializeUtils.serializeRtpParameters(sender.getParameters()));
616
+ } catch (Exception e) {
617
+ Log.d(TAG, "senderSetParameters: " + e.getMessage());
618
+ promise.reject(e);
619
+ }
620
+ });
621
+ }
622
+
623
+ @ReactMethod
624
+ public void peerConnectionRemoveTrack(int id, String senderId) {
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) {
659
+ ThreadUtils.runOnExecutor(() -> {
660
+ WritableMap identifier = Arguments.createMap();
661
+ identifier.putInt("peerConnectionId", id);
662
+ identifier.putString("transceiverId", senderId);
663
+ try {
664
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
665
+ if (pco == null) {
666
+ Log.d(TAG, "transceiverStop() peerConnectionObserver is null");
667
+ // Cannot really report an error specific to RTCRtpTransceiver as the peer connection
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.
671
+ return;
672
+ }
673
+ RtpTransceiver transceiver = pco.getTransceiver(senderId);
674
+
675
+ transceiver.stopStandard();
676
+ sendEvent("transceiverStopSuccessful", identifier);
677
+ } catch (Exception e) {
678
+ Log.d(TAG, "transceiverStop(): " + e.getMessage());
679
+ sendError("transceiverOnError", "stopTransceiver", e.getMessage(), identifier);
680
+ }
681
+ });
682
+ }
683
+
684
+ @ReactMethod
685
+ public void senderReplaceTrack(int id,
686
+ String senderId,
687
+ String trackId,
688
+ Promise promise) {
689
+ ThreadUtils.runOnExecutor(() -> {
690
+ try {
691
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
692
+ if (pco == null) {
693
+ Log.d(TAG, "senderReplaceTrack() peerConnectionObserver is null");
694
+ promise.reject(new Exception("Peer Connection is not initialized"));
695
+ return;
696
+ }
697
+
698
+ RtpSender sender = pco.getSender(senderId);
699
+ if (sender == null) {
700
+ Log.w(TAG, "senderReplaceTrack() sender is null");
701
+ promise.reject(new Exception("Could not get sender"));
702
+ return;
703
+ }
704
+
705
+ MediaStreamTrack track = getLocalTrack(trackId);
706
+ sender.setTrack(track, false);
707
+ promise.resolve(true);
708
+ } catch (Exception e) {
709
+ Log.d(TAG, "senderReplaceTrack(): " + e.getMessage());
710
+ promise.reject(e);
711
+ }
712
+ });
713
+ }
714
+
715
+ @ReactMethod
716
+ public void transceiverSetDirection(int id,
717
+ String senderId,
718
+ String direction) {
719
+
720
+ ThreadUtils.runOnExecutor(() -> {
721
+ WritableMap identifier = Arguments.createMap();
722
+ WritableMap params = Arguments.createMap();
723
+ identifier.putInt("peerConnectionId", id);
724
+ identifier.putString("transceiverId", senderId);
725
+ try {
726
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
727
+ if (pco == null) {
728
+ Log.d(TAG, "transceiverSetDirection() peerConnectionObserver is null");
729
+ // Cannot really report an error specific to RTCRtpSender as the peer connection
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
732
+ return;
733
+ }
734
+ RtpTransceiver transceiver = pco.getTransceiver(senderId);
735
+ if (transceiver == null){
736
+ Log.d(TAG, "transceiverSetDirection() transceiver is null");
737
+ return;
738
+ }
739
+
740
+ RtpTransceiver.RtpTransceiverDirection oldDirection = transceiver.getDirection();
741
+ params.putString("oldDirection", SerializeUtils.serializeDirection(oldDirection));
742
+ transceiver.setDirection(SerializeUtils.parseDirection(direction));
743
+ } catch (Exception e) {
744
+ Log.d(TAG, "transceiverSetDirection(): " + e.getMessage());
745
+ params.putMap("identifiers", identifier);
746
+ sendError("transceiverOnError", "setDirection", e.getMessage(), params);
747
+ }
748
+ });
749
+ }
750
+
488
751
  @ReactMethod
489
752
  public void getDisplayMedia(Promise promise) {
490
753
  ThreadUtils.runOnExecutor(() -> getUserMediaImpl.getDisplayMedia(promise));
@@ -560,15 +823,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
560
823
  Log.d(TAG, "mediaStreamRelease() stream is null");
561
824
  return;
562
825
  }
563
-
564
826
  localStreams.remove(id);
565
-
566
- // MediaStream.dispose() may be called without an exception only if
567
- // it's no longer added to any PeerConnection.
568
- for (int i = 0, size = mPeerConnectionObservers.size(); i < size; i++) {
569
- mPeerConnectionObservers.valueAt(i).removeStream(stream);
570
- }
571
-
572
827
  stream.dispose();
573
828
  });
574
829
  }
@@ -611,6 +866,34 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
611
866
  });
612
867
  }
613
868
 
869
+ /**
870
+ * This serializes the transceivers current direction and mid and returns them
871
+ * for update when an sdp negotiation/renegotiation happens
872
+ */
873
+ private ReadableArray getTransceiversInfo(int id) {
874
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
875
+ if (pco == null) {
876
+ return null;
877
+ }
878
+ PeerConnection peerConnection = pco.getPeerConnection();
879
+ WritableArray transceiverUpdates = Arguments.createArray();
880
+ for(RtpTransceiver transceiver: peerConnection.getTransceivers()) {
881
+ RtpTransceiver.RtpTransceiverDirection direction = transceiver.getCurrentDirection();
882
+ if (direction == null) continue;
883
+ String directionSerialized = SerializeUtils.serializeDirection(direction);
884
+ WritableMap transceiverUpdate = Arguments.createMap();
885
+ transceiverUpdate.putString("transceiverId", transceiver.getSender().id());
886
+ transceiverUpdate.putInt("peerConnectionId", id);
887
+ transceiverUpdate.putString("mid", transceiver.getMid());
888
+ transceiverUpdate.putString("currentDirection", directionSerialized);
889
+ transceiverUpdate.putMap("senderRtpParameters",
890
+ SerializeUtils.serializeRtpParameters(
891
+ transceiver.getSender().getParameters()));
892
+ transceiverUpdates.pushMap(transceiverUpdate);
893
+ }
894
+ return transceiverUpdates;
895
+ }
896
+
614
897
  @ReactMethod
615
898
  public void peerConnectionSetConfiguration(ReadableMap configuration,
616
899
  int id) {
@@ -624,36 +907,6 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
624
907
  });
625
908
  }
626
909
 
627
- @ReactMethod
628
- public void peerConnectionAddStream(String streamId, int id) {
629
- ThreadUtils.runOnExecutor(() -> {
630
- MediaStream mediaStream = localStreams.get(streamId);
631
- if (mediaStream == null) {
632
- Log.d(TAG, "peerConnectionAddStream() mediaStream is null");
633
- return;
634
- }
635
- PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
636
- if (pco == null || !pco.addStream(mediaStream)) {
637
- Log.e(TAG, "peerConnectionAddStream() failed");
638
- }
639
- });
640
- }
641
-
642
- @ReactMethod
643
- public void peerConnectionRemoveStream(String streamId, int id) {
644
- ThreadUtils.runOnExecutor(() -> {
645
- MediaStream mediaStream = localStreams.get(streamId);
646
- if (mediaStream == null) {
647
- Log.d(TAG, "peerConnectionRemoveStream() mediaStream is null");
648
- return;
649
- }
650
- PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
651
- if (pco == null || !pco.removeStream(mediaStream)) {
652
- Log.e(TAG, "peerConnectionRemoveStream() failed");
653
- }
654
- });
655
- }
656
-
657
910
  @ReactMethod
658
911
  public void peerConnectionCreateOffer(int id,
659
912
  ReadableMap options,
@@ -676,8 +929,11 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
676
929
  @Override
677
930
  public void onCreateSuccess(SessionDescription sdp) {
678
931
  WritableMap params = Arguments.createMap();
679
- params.putString("sdp", sdp.description);
680
- params.putString("type", sdp.type.canonicalForm());
932
+ WritableMap sdpInfo = Arguments.createMap();
933
+ sdpInfo.putString("sdp", sdp.description);
934
+ sdpInfo.putString("type", sdp.type.canonicalForm());
935
+ params.putArray("transceiversInfo", getTransceiversInfo(id));
936
+ params.putMap("sdpInfo", sdpInfo);
681
937
  callback.invoke(true, params);
682
938
  }
683
939
 
@@ -712,8 +968,11 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
712
968
  @Override
713
969
  public void onCreateSuccess(SessionDescription sdp) {
714
970
  WritableMap params = Arguments.createMap();
715
- params.putString("sdp", sdp.description);
716
- params.putString("type", sdp.type.canonicalForm());
971
+ WritableMap sdpInfo = Arguments.createMap();
972
+ sdpInfo.putString("sdp", sdp.description);
973
+ sdpInfo.putString("type", sdp.type.canonicalForm());
974
+ params.putArray("transceiversInfo", getTransceiversInfo(id));
975
+ params.putMap("sdpInfo", sdpInfo);
717
976
  callback.invoke(true, params);
718
977
  }
719
978
 
@@ -747,9 +1006,12 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
747
1006
  public void onSetSuccess() {
748
1007
  SessionDescription newSdp = peerConnection.getLocalDescription();
749
1008
  WritableMap newSdpMap = Arguments.createMap();
1009
+ WritableMap params = Arguments.createMap();
750
1010
  newSdpMap.putString("type", newSdp.type.canonicalForm());
751
1011
  newSdpMap.putString("sdp", newSdp.description);
752
- promise.resolve(newSdpMap);
1012
+ params.putMap("sdpInfo", newSdpMap);
1013
+ params.putArray("transceiversInfo", getTransceiversInfo(pcId));
1014
+ promise.resolve(params);
753
1015
  }
754
1016
 
755
1017
  @Override
@@ -801,9 +1063,12 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
801
1063
  public void onSetSuccess() {
802
1064
  SessionDescription newSdp = peerConnection.getRemoteDescription();
803
1065
  WritableMap newSdpMap = Arguments.createMap();
1066
+ WritableMap params = Arguments.createMap();
804
1067
  newSdpMap.putString("type", newSdp.type.canonicalForm());
805
1068
  newSdpMap.putString("sdp", newSdp.description);
806
- callback.invoke(true, newSdpMap);
1069
+ params.putArray("transceiversInfo", getTransceiversInfo(id));
1070
+ params.putMap("sdpInfo", newSdpMap);
1071
+ callback.invoke(true, params);
807
1072
  }
808
1073
 
809
1074
  @Override
@@ -818,6 +1083,46 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
818
1083
  });
819
1084
  }
820
1085
 
1086
+
1087
+ @ReactMethod(isBlockingSynchronousMethod = true)
1088
+ public WritableMap receiverGetCapabilities() {
1089
+ try {
1090
+ return (WritableMap) ThreadUtils.submitToExecutor((Callable<Object>) () -> {
1091
+ VideoCodecInfo[] videoCodecInfos = mVideoDecoderFactory.getSupportedCodecs();
1092
+ WritableMap params = Arguments.createMap();
1093
+ WritableArray codecs = Arguments.createArray();
1094
+ for(VideoCodecInfo codecInfo: videoCodecInfos) {
1095
+ codecs.pushMap(SerializeUtils.serializeVideoCodecInfo(codecInfo));
1096
+ }
1097
+ params.putArray("codecs", codecs);
1098
+ return params;
1099
+ }).get();
1100
+ } catch (ExecutionException | InterruptedException e) {
1101
+ Log.d(TAG, "receiverGetCapabilities() " + e.getMessage());
1102
+ return null;
1103
+ }
1104
+ }
1105
+
1106
+
1107
+ @ReactMethod(isBlockingSynchronousMethod = true)
1108
+ public WritableMap senderGetCapabilities() {
1109
+ try {
1110
+ return (WritableMap) ThreadUtils.submitToExecutor((Callable<Object>) () -> {
1111
+ VideoCodecInfo[] videoCodecInfos = mVideoEncoderFactory.getSupportedCodecs();
1112
+ WritableMap params = Arguments.createMap();
1113
+ WritableArray codecs = Arguments.createArray();
1114
+ for(VideoCodecInfo codecInfo: videoCodecInfos) {
1115
+ codecs.pushMap(SerializeUtils.serializeVideoCodecInfo(codecInfo));
1116
+ }
1117
+ params.putArray("codecs", codecs);
1118
+ return params;
1119
+ }).get();
1120
+ } catch (ExecutionException | InterruptedException e) {
1121
+ Log.d(TAG, "senderGetCapabilities() " + e.getMessage());
1122
+ return null;
1123
+ }
1124
+ }
1125
+
821
1126
  @ReactMethod
822
1127
  public void peerConnectionAddICECandidate(int pcId,
823
1128
  ReadableMap candidateMap,
@@ -187,8 +187,12 @@ public class WebRTCView extends ViewGroup {
187
187
  videoTrack = videoTracks.get(0);
188
188
  }
189
189
  }
190
- }
191
190
 
191
+ if (videoTrack == null) {
192
+ Log.w(TAG, "No video stream for react tag: " + streamURL);
193
+ }
194
+ }
195
+
192
196
  return videoTrack;
193
197
  }
194
198
 
@@ -68,10 +68,7 @@
68
68
  }
69
69
 
70
70
  NSArray<NSString *> *urls;
71
- if ([json[@"url"] isKindOfClass:[NSString class]]) {
72
- // TODO: 'url' is non-standard
73
- urls = @[json[@"url"]];
74
- } else if ([json[@"urls"] isKindOfClass:[NSString class]]) {
71
+ if ([json[@"urls"] isKindOfClass:[NSString class]]) {
75
72
  urls = @[json[@"urls"]];
76
73
  } else {
77
74
  urls = [RCTConvert NSArray:json[@"urls"]];
@@ -93,8 +90,7 @@
93
90
  // Required for perfect negotiation.
94
91
  config.enableImplicitRollback = YES;
95
92
 
96
- // Plan B, just a little longer.
97
- config.sdpSemantics = RTCSdpSemanticsPlanB;
93
+ config.sdpSemantics = RTCSdpSemanticsUnifiedPlan;
98
94
 
99
95
  if (!json) {
100
96
  return config;
@@ -158,7 +158,6 @@ const NSUInteger kMaxReadLength = 10 * 1024;
158
158
  }
159
159
 
160
160
  - (void)stopCapture {
161
- [self.connection close];
162
161
  self.connection = nil;
163
162
  }
164
163
 
@@ -0,0 +1,25 @@
1
+ #import <WebRTC/RTCMediaStreamTrack.h>
2
+ #import <WebRTC/RTCRtpReceiver.h>
3
+ #import <WebRTC/RTCRtpTransceiver.h>
4
+ #import <WebRTC/RTCVideoCodecInfo.h>
5
+ #import "WebRTCModule+RTCPeerConnection.h"
6
+
7
+ @interface SerializeUtils : NSObject
8
+
9
+ + (NSString *_Nonnull)transceiverToJSONWithPeerConnectionId: (nonnull NSNumber *) id
10
+ transceiver: (RTCRtpTransceiver *_Nonnull) transceiver;
11
+ + (NSDictionary *_Nonnull)senderToJSONWithPeerConnectionId: (nonnull NSNumber *) id
12
+ sender: (RTCRtpSender *_Nonnull) sender;
13
+ + (NSDictionary *_Nonnull)receiverToJSONWithPeerConnectionId: (nonnull NSNumber *) id
14
+ receiver: (RTCRtpReceiver *_Nonnull) receiver;
15
+ + (NSDictionary *_Nonnull)trackToJSONWithPeerConnectionId: (nonnull NSNumber *) id
16
+ track: (RTCMediaStreamTrack *_Nonnull) track;
17
+ + (NSString *_Nonnull)serializeDirection: (RTCRtpTransceiverDirection) direction;
18
+ + (RTCRtpTransceiverDirection) parseDirection: (NSString *_Nonnull) direction;
19
+ + (NSDictionary *_Nonnull)parametersToJSON: (RTCRtpParameters *_Nonnull) parameters;
20
+ + (NSMutableArray *_Nonnull)constructTransceiversInfoArrayWithPeerConnection: (RTCPeerConnection *_Nonnull) peerConnection
21
+ peerConnectionId: (NSNumber *_Nonnull) peerConnectionId;
22
+ + (NSDictionary *_Nonnull)streamToJSONWithPeerConnectionId: (NSNumber *_Nonnull) id
23
+ stream: (RTCMediaStream *_Nonnull) stream
24
+ streamReactTag: (NSString *_Nonnull) streamReactTag;
25
+ @end