react-native-webrtc 106.0.5 → 106.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/.clang-format +11 -0
  2. package/LICENSE +2 -1
  3. package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +0 -1
  4. package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +7 -15
  5. package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +3 -12
  6. package/android/src/main/java/com/oney/WebRTCModule/DataChannelWrapper.java +12 -16
  7. package/android/src/main/java/com/oney/WebRTCModule/DisplayUtils.java +1 -1
  8. package/android/src/main/java/com/oney/WebRTCModule/EglUtils.java +1 -1
  9. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +29 -43
  10. package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +123 -116
  11. package/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +60 -61
  12. package/android/src/main/java/com/oney/WebRTCModule/ReactBridgeUtil.java +1 -2
  13. package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +11 -13
  14. package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +116 -119
  15. package/android/src/main/java/com/oney/WebRTCModule/StringUtils.java +8 -14
  16. package/android/src/main/java/com/oney/WebRTCModule/ThreadUtils.java +1 -2
  17. package/android/src/main/java/com/oney/WebRTCModule/TrackCapturerEventsEmitter.java +3 -4
  18. package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +5 -9
  19. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +335 -350
  20. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModulePackage.java +4 -10
  21. package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +74 -98
  22. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/ProcessorProvider.java +10 -9
  23. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +2 -6
  24. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessorFactoryInterface.java +4 -5
  25. package/ios/RCTWebRTC/CaptureController.h +2 -9
  26. package/ios/RCTWebRTC/CaptureController.m +0 -7
  27. package/ios/RCTWebRTC/DataChannelWrapper.h +9 -13
  28. package/ios/RCTWebRTC/DataChannelWrapper.m +4 -5
  29. package/ios/RCTWebRTC/RCTConvert+WebRTC.h +2 -2
  30. package/ios/RCTWebRTC/RCTConvert+WebRTC.m +166 -171
  31. package/ios/RCTWebRTC/RTCMediaStreamTrack+React.h +1 -1
  32. package/ios/RCTWebRTC/RTCMediaStreamTrack+React.m +1 -1
  33. package/ios/RCTWebRTC/RTCVideoViewManager.h +0 -8
  34. package/ios/RCTWebRTC/RTCVideoViewManager.m +205 -214
  35. package/ios/RCTWebRTC/ScreenCaptureController.h +2 -9
  36. package/ios/RCTWebRTC/ScreenCaptureController.m +10 -16
  37. package/ios/RCTWebRTC/ScreenCapturePickerViewManager.h +0 -7
  38. package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +26 -34
  39. package/ios/RCTWebRTC/ScreenCapturer.h +1 -8
  40. package/ios/RCTWebRTC/ScreenCapturer.m +56 -55
  41. package/ios/RCTWebRTC/SerializeUtils.h +16 -16
  42. package/ios/RCTWebRTC/SerializeUtils.m +98 -99
  43. package/ios/RCTWebRTC/SocketConnection.h +1 -8
  44. package/ios/RCTWebRTC/SocketConnection.m +31 -38
  45. package/ios/RCTWebRTC/TrackCapturerEventsEmitter.h +4 -4
  46. package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +5 -6
  47. package/ios/RCTWebRTC/VideoCaptureController.h +6 -7
  48. package/ios/RCTWebRTC/VideoCaptureController.m +54 -53
  49. package/ios/RCTWebRTC/WebRTCModule+Permissions.m +14 -13
  50. package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.h +3 -3
  51. package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +105 -100
  52. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +3 -2
  53. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +196 -226
  54. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +7 -14
  55. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +625 -603
  56. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +128 -139
  57. package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.h +4 -5
  58. package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +26 -35
  59. package/ios/RCTWebRTC/WebRTCModule.h +13 -20
  60. package/ios/RCTWebRTC/WebRTCModule.m +69 -84
  61. package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  62. package/lib/commonjs/RTCPeerConnection.js +79 -56
  63. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  64. package/lib/commonjs/RTCRtpTransceiver.js +1 -1
  65. package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
  66. package/lib/module/RTCPeerConnection.js +79 -56
  67. package/lib/module/RTCPeerConnection.js.map +1 -1
  68. package/lib/module/RTCRtpTransceiver.js +1 -1
  69. package/lib/module/RTCRtpTransceiver.js.map +1 -1
  70. package/lib/typescript/RTCPeerConnection.d.ts +4 -4
  71. package/package.json +3 -2
  72. package/src/RTCPeerConnection.ts +70 -63
  73. package/src/RTCRtpTransceiver.ts +1 -1
  74. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  75. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  76. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
@@ -8,8 +8,8 @@ import androidx.annotation.Nullable;
8
8
 
9
9
  import com.facebook.react.bridge.Arguments;
10
10
  import com.facebook.react.bridge.Promise;
11
- import com.facebook.react.bridge.ReadableMap;
12
11
  import com.facebook.react.bridge.ReadableArray;
12
+ import com.facebook.react.bridge.ReadableMap;
13
13
  import com.facebook.react.bridge.WritableArray;
14
14
  import com.facebook.react.bridge.WritableMap;
15
15
 
@@ -49,7 +49,8 @@ class PeerConnectionObserver implements PeerConnection.Observer {
49
49
  private int transceiverNextId = 0;
50
50
 
51
51
  private PeerConnection peerConnection;
52
- final Map<String, MediaStream> remoteStreams;
52
+ final Map<String, String> remoteStreamIds; // Stream ID -> React tag
53
+ final Map<String, MediaStream> remoteStreams; // React tag -> MediaStream
53
54
  final Map<String, MediaStreamTrack> remoteTracks;
54
55
  private final VideoTrackAdapter videoTrackAdapters;
55
56
  private final WebRTCModule webRTCModule;
@@ -58,6 +59,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
58
59
  this.webRTCModule = webRTCModule;
59
60
  this.id = id;
60
61
  this.dataChannels = new HashMap<>();
62
+ this.remoteStreamIds = new HashMap<>();
61
63
  this.remoteStreams = new HashMap<>();
62
64
  this.remoteTracks = new HashMap<>();
63
65
  this.videoTrackAdapters = new VideoTrackAdapter(webRTCModule, id);
@@ -74,8 +76,11 @@ class PeerConnectionObserver implements PeerConnection.Observer {
74
76
  void close() {
75
77
  Log.d(TAG, "PeerConnection.close() for " + id);
76
78
 
77
- // Close the PeerConnection first to stop any events.
78
79
  peerConnection.close();
80
+ }
81
+
82
+ void dispose() {
83
+ Log.d(TAG, "PeerConnection.dispose() for " + id);
79
84
 
80
85
  // Remove video track adapters
81
86
  for (MediaStreamTrack track : this.remoteTracks.values()) {
@@ -87,7 +92,6 @@ class PeerConnectionObserver implements PeerConnection.Observer {
87
92
  // Remove DataChannel observers
88
93
  for (DataChannelWrapper dcw : dataChannels.values()) {
89
94
  DataChannel dataChannel = dcw.getDataChannel();
90
- dataChannel.close();
91
95
  dataChannel.unregisterObserver();
92
96
  }
93
97
 
@@ -96,12 +100,12 @@ class PeerConnectionObserver implements PeerConnection.Observer {
96
100
  // by the PeerConnection instance (RtpReceivers, RtpSenders, etc.)
97
101
  peerConnection.dispose();
98
102
 
103
+ remoteStreamIds.clear();
99
104
  remoteStreams.clear();
100
105
  remoteTracks.clear();
101
106
  dataChannels.clear();
102
107
  }
103
108
 
104
-
105
109
  public synchronized int getNextTransceiverId() {
106
110
  return transceiverNextId++;
107
111
  }
@@ -127,7 +131,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
127
131
  return null;
128
132
  }
129
133
 
130
- for (RtpSender sender: this.peerConnection.getSenders()) {
134
+ for (RtpSender sender : this.peerConnection.getSenders()) {
131
135
  if (sender.id().equals(id)) {
132
136
  return sender;
133
137
  }
@@ -141,7 +145,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
141
145
  return null;
142
146
  }
143
147
 
144
- for (RtpTransceiver transceiver: this.peerConnection.getTransceivers()) {
148
+ for (RtpTransceiver transceiver : this.peerConnection.getTransceivers()) {
145
149
  if (transceiver.getSender().id().equals(id)) {
146
150
  return transceiver;
147
151
  }
@@ -175,7 +179,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
175
179
  if (dataChannel == null) {
176
180
  return null;
177
181
  }
178
- final String reactTag = UUID.randomUUID().toString();
182
+ final String reactTag = UUID.randomUUID().toString();
179
183
  DataChannelWrapper dcw = new DataChannelWrapper(webRTCModule, id, reactTag, dataChannel);
180
184
  dataChannels.put(reactTag, dcw);
181
185
  dataChannel.registerObserver(dcw);
@@ -239,18 +243,14 @@ class PeerConnectionObserver implements PeerConnection.Observer {
239
243
  }
240
244
 
241
245
  void getStats(Promise promise) {
242
- peerConnection.getStats(rtcStatsReport -> {
243
- promise.resolve(StringUtils.statsToJSON(rtcStatsReport));
244
- });
246
+ peerConnection.getStats(rtcStatsReport -> { promise.resolve(StringUtils.statsToJSON(rtcStatsReport)); });
245
247
  }
246
248
 
247
-
248
249
  /**
249
250
  * @param trackIdentifier sender or receiver id
250
251
  * @param streamType "outbound-rtp" for sender or "inbound-rtp" for receiver
251
252
  */
252
253
  void getFilteredStats(String trackIdentifier, boolean isReceiver, Promise promise) {
253
-
254
254
  peerConnection.getStats(rtcStatsReport -> {
255
255
  Map<String, RTCStats> statsMap = rtcStatsReport.getStatsMap();
256
256
  Set<RTCStats> filteredStats = new HashSet<>();
@@ -291,7 +291,6 @@ class PeerConnectionObserver implements PeerConnection.Observer {
291
291
  }
292
292
  }
293
293
 
294
-
295
294
  // Get candidate information
296
295
  RTCStats candidatePairStats = null;
297
296
  for (RTCStats stats : statsMap.values()) {
@@ -310,13 +309,15 @@ class PeerConnectionObserver implements PeerConnection.Observer {
310
309
  }
311
310
 
312
311
  // Sweep for any remaining stats we want.
313
- filteredStats.addAll(getExtraStats(trackIdentifier, ssrcs, codecIds, localCandidateId, remoteCandidateId, statsMap));
312
+ filteredStats.addAll(
313
+ getExtraStats(trackIdentifier, ssrcs, codecIds, localCandidateId, remoteCandidateId, statsMap));
314
314
 
315
315
  Map<String, RTCStats> filteredStatsMap = new HashMap<>();
316
316
  for (RTCStats stats : filteredStats) {
317
317
  filteredStatsMap.put(stats.getId(), stats);
318
318
  }
319
- RTCStatsReport filteredStatsReport = new RTCStatsReport((long) rtcStatsReport.getTimestampUs(), filteredStatsMap);
319
+ RTCStatsReport filteredStatsReport =
320
+ new RTCStatsReport((long) rtcStatsReport.getTimestampUs(), filteredStatsMap);
320
321
  promise.resolve(StringUtils.statsToJSON(filteredStatsReport));
321
322
  });
322
323
  }
@@ -333,7 +334,6 @@ class PeerConnectionObserver implements PeerConnection.Observer {
333
334
  return null;
334
335
  }
335
336
 
336
-
337
337
  @Nullable
338
338
  private RTCStats getStreamStats(String trackId, Map<String, RTCStats> statsMap) {
339
339
  for (RTCStats stats : statsMap.values()) {
@@ -347,13 +347,8 @@ class PeerConnectionObserver implements PeerConnection.Observer {
347
347
 
348
348
  // Note: trackIdentifier can differ from the internal stats trackId
349
349
  // trackIdentifier refers to the sender or receiver id
350
- public Set<RTCStats> getExtraStats(
351
- String trackIdentifier,
352
- Set<Long> ssrcs,
353
- Set<String> codecIds,
354
- @Nullable String localCandidateId,
355
- @Nullable String remoteCandidateId,
356
- Map<String, RTCStats> statsMap) {
350
+ public Set<RTCStats> getExtraStats(String trackIdentifier, Set<Long> ssrcs, Set<String> codecIds,
351
+ @Nullable String localCandidateId, @Nullable String remoteCandidateId, Map<String, RTCStats> statsMap) {
357
352
  Set<RTCStats> extraStats = new HashSet<>();
358
353
  for (RTCStats stats : statsMap.values()) {
359
354
  switch (stats.getType()) {
@@ -387,112 +382,131 @@ class PeerConnectionObserver implements PeerConnection.Observer {
387
382
  @Override
388
383
  public void onIceCandidate(final IceCandidate candidate) {
389
384
  Log.d(TAG, "onIceCandidate");
390
- WritableMap params = Arguments.createMap();
391
- params.putInt("pcId", id);
392
- WritableMap candidateParams = Arguments.createMap();
393
- candidateParams.putInt("sdpMLineIndex", candidate.sdpMLineIndex);
394
- candidateParams.putString("sdpMid", candidate.sdpMid);
395
- candidateParams.putString("candidate", candidate.sdp);
396
- params.putMap("candidate", candidateParams);
397
- SessionDescription newSdp = peerConnection.getLocalDescription();
398
- WritableMap newSdpMap = Arguments.createMap();
399
- // Can happen when doing a rollback.
400
- if (newSdp != null) {
401
- newSdpMap.putString("type", newSdp.type.canonicalForm());
402
- newSdpMap.putString("sdp", newSdp.description);
403
- }
404
- params.putMap("sdp", newSdpMap);
405
385
 
406
- webRTCModule.sendEvent("peerConnectionGotICECandidate", params);
386
+ ThreadUtils.runOnExecutor(() -> {
387
+ WritableMap params = Arguments.createMap();
388
+ params.putInt("pcId", id);
389
+
390
+ WritableMap candidateParams = Arguments.createMap();
391
+ candidateParams.putInt("sdpMLineIndex", candidate.sdpMLineIndex);
392
+ candidateParams.putString("sdpMid", candidate.sdpMid);
393
+ candidateParams.putString("candidate", candidate.sdp);
394
+
395
+ params.putMap("candidate", candidateParams);
396
+
397
+ SessionDescription newSdp = peerConnection.getLocalDescription();
398
+ WritableMap newSdpMap = Arguments.createMap();
399
+
400
+ // Can happen when doing a rollback.
401
+ if (newSdp != null) {
402
+ newSdpMap.putString("type", newSdp.type.canonicalForm());
403
+ newSdpMap.putString("sdp", newSdp.description);
404
+ }
405
+ params.putMap("sdp", newSdpMap);
406
+
407
+ webRTCModule.sendEvent("peerConnectionGotICECandidate", params);
408
+ });
407
409
  }
408
410
 
409
411
  @Override
410
- public void onIceCandidatesRemoved(final IceCandidate[] candidates) {
411
- Log.d(TAG, "onIceCandidatesRemoved");
412
- }
412
+ public void onIceCandidatesRemoved(final IceCandidate[] candidates) {}
413
413
 
414
414
  @Override
415
415
  public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) {
416
- WritableMap params = Arguments.createMap();
417
- params.putInt("pcId", id);
418
- params.putString("iceConnectionState", iceConnectionStateString(iceConnectionState));
419
- webRTCModule.sendEvent("peerConnectionIceConnectionChanged", params);
416
+ ThreadUtils.runOnExecutor(() -> {
417
+ WritableMap params = Arguments.createMap();
418
+ params.putInt("pcId", id);
419
+ params.putString("iceConnectionState", iceConnectionStateString(iceConnectionState));
420
+ webRTCModule.sendEvent("peerConnectionIceConnectionChanged", params);
421
+ });
420
422
  }
421
423
 
422
424
  @Override
423
425
  public void onConnectionChange(PeerConnection.PeerConnectionState peerConnectionState) {
424
- WritableMap params = Arguments.createMap();
425
- params.putInt("pcId", id);
426
- params.putString("connectionState", peerConnectionStateString(peerConnectionState));
426
+ ThreadUtils.runOnExecutor(() -> {
427
+ WritableMap params = Arguments.createMap();
428
+ params.putInt("pcId", id);
429
+ params.putString("connectionState", peerConnectionStateString(peerConnectionState));
427
430
 
428
- webRTCModule.sendEvent("peerConnectionStateChanged", params);
431
+ webRTCModule.sendEvent("peerConnectionStateChanged", params);
432
+ });
429
433
  }
430
434
 
431
435
  @Override
432
- public void onIceConnectionReceivingChange(boolean var1) {
433
- }
436
+ public void onIceConnectionReceivingChange(boolean receiving) {}
434
437
 
435
438
  @Override
436
439
  public void onIceGatheringChange(PeerConnection.IceGatheringState iceGatheringState) {
437
440
  Log.d(TAG, "onIceGatheringChange" + iceGatheringState.name());
438
- WritableMap params = Arguments.createMap();
439
- params.putInt("pcId", id);
440
- params.putString("iceGatheringState", iceGatheringStateString(iceGatheringState));
441
- if (iceGatheringState == PeerConnection.IceGatheringState.COMPLETE) {
442
- SessionDescription newSdp = peerConnection.getLocalDescription();
443
- WritableMap newSdpMap = Arguments.createMap();
444
- // Can happen when doing a rollback.
445
- if (newSdp != null) {
446
- newSdpMap.putString("type", newSdp.type.canonicalForm());
447
- newSdpMap.putString("sdp", newSdp.description);
441
+
442
+ ThreadUtils.runOnExecutor(() -> {
443
+ WritableMap params = Arguments.createMap();
444
+ params.putInt("pcId", id);
445
+ params.putString("iceGatheringState", iceGatheringStateString(iceGatheringState));
446
+
447
+ if (iceGatheringState == PeerConnection.IceGatheringState.COMPLETE) {
448
+ SessionDescription newSdp = peerConnection.getLocalDescription();
449
+ WritableMap newSdpMap = Arguments.createMap();
450
+
451
+ // Can happen when doing a rollback.
452
+ if (newSdp != null) {
453
+ newSdpMap.putString("type", newSdp.type.canonicalForm());
454
+ newSdpMap.putString("sdp", newSdp.description);
455
+ }
456
+ params.putMap("sdp", newSdpMap);
448
457
  }
449
- params.putMap("sdp", newSdpMap);
450
- }
451
- webRTCModule.sendEvent("peerConnectionIceGatheringChanged", params);
458
+ webRTCModule.sendEvent("peerConnectionIceGatheringChanged", params);
459
+ });
452
460
  }
453
461
 
454
462
  @Override
455
463
  public void onDataChannel(DataChannel dataChannel) {
456
- final String reactTag = UUID.randomUUID().toString();
457
- DataChannelWrapper dcw = new DataChannelWrapper(webRTCModule, id, reactTag, dataChannel);
458
- dataChannels.put(reactTag, dcw);
459
- dataChannel.registerObserver(dcw);
460
-
461
- WritableMap info = Arguments.createMap();
462
- info.putInt("peerConnectionId", id);
463
- info.putString("reactTag", reactTag);
464
- info.putString("label", dataChannel.label());
465
- info.putInt("id", dataChannel.id());
466
-
467
- // TODO: These values are not gettable from a DataChannel instance.
468
- info.putBoolean("ordered", true);
469
- info.putInt("maxPacketLifeTime", -1);
470
- info.putInt("maxRetransmits", -1);
471
- info.putString("protocol", "");
472
-
473
- info.putBoolean("negotiated", false);
474
- info.putString("readyState", dcw.dataChannelStateString(dataChannel.state()));
464
+ ThreadUtils.runOnExecutor(() -> {
465
+ final String reactTag = UUID.randomUUID().toString();
466
+ DataChannelWrapper dcw = new DataChannelWrapper(webRTCModule, id, reactTag, dataChannel);
467
+ dataChannels.put(reactTag, dcw);
468
+ dataChannel.registerObserver(dcw);
469
+
470
+ WritableMap info = Arguments.createMap();
471
+ info.putInt("peerConnectionId", id);
472
+ info.putString("reactTag", reactTag);
473
+ info.putString("label", dataChannel.label());
474
+ info.putInt("id", dataChannel.id());
475
+
476
+ // TODO: These values are not gettable from a DataChannel instance.
477
+ info.putBoolean("ordered", true);
478
+ info.putInt("maxPacketLifeTime", -1);
479
+ info.putInt("maxRetransmits", -1);
480
+ info.putString("protocol", "");
481
+
482
+ info.putBoolean("negotiated", false);
483
+ info.putString("readyState", dcw.dataChannelStateString(dataChannel.state()));
475
484
 
476
- WritableMap params = Arguments.createMap();
477
- params.putInt("pcId", id);
478
- params.putMap("dataChannel", info);
485
+ WritableMap params = Arguments.createMap();
486
+ params.putInt("pcId", id);
487
+ params.putMap("dataChannel", info);
479
488
 
480
- webRTCModule.sendEvent("peerConnectionDidOpenDataChannel", params);
489
+ webRTCModule.sendEvent("peerConnectionDidOpenDataChannel", params);
490
+ });
481
491
  }
482
492
 
483
493
  @Override
484
494
  public void onRenegotiationNeeded() {
485
- WritableMap params = Arguments.createMap();
486
- params.putInt("pcId", id);
487
- webRTCModule.sendEvent("peerConnectionOnRenegotiationNeeded", params);
495
+ ThreadUtils.runOnExecutor(() -> {
496
+ WritableMap params = Arguments.createMap();
497
+ params.putInt("pcId", id);
498
+ webRTCModule.sendEvent("peerConnectionOnRenegotiationNeeded", params);
499
+ });
488
500
  }
489
501
 
490
502
  @Override
491
503
  public void onSignalingChange(PeerConnection.SignalingState signalingState) {
492
- WritableMap params = Arguments.createMap();
493
- params.putInt("pcId", id);
494
- params.putString("signalingState", signalingStateString(signalingState));
495
- webRTCModule.sendEvent("peerConnectionSignalingStateChanged", params);
504
+ ThreadUtils.runOnExecutor(() -> {
505
+ WritableMap params = Arguments.createMap();
506
+ params.putInt("pcId", id);
507
+ params.putString("signalingState", signalingStateString(signalingState));
508
+ webRTCModule.sendEvent("peerConnectionSignalingStateChanged", params);
509
+ });
496
510
  }
497
511
 
498
512
  /**
@@ -505,7 +519,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
505
519
 
506
520
  ThreadUtils.runOnExecutor(() -> {
507
521
  RtpTransceiver transceiver = null;
508
- for(RtpTransceiver t: this.peerConnection.getTransceivers()) {
522
+ for (RtpTransceiver t : this.peerConnection.getTransceivers()) {
509
523
  if (Objects.equals(t.getReceiver().id(), receiver.id())) {
510
524
  transceiver = t;
511
525
  break;
@@ -524,7 +538,7 @@ class PeerConnectionObserver implements PeerConnection.Observer {
524
538
  final boolean existingTrack = remoteTracks.containsKey(track.id());
525
539
 
526
540
  if (!existingTrack) {
527
- if (track.kind().equals(MediaStreamTrack.VIDEO_TRACK_KIND)){
541
+ if (track.kind().equals(MediaStreamTrack.VIDEO_TRACK_KIND)) {
528
542
  videoTrackAdapters.addAdapter((VideoTrack) track);
529
543
  }
530
544
  remoteTracks.put(track.id(), track);
@@ -535,17 +549,16 @@ class PeerConnectionObserver implements PeerConnection.Observer {
535
549
 
536
550
  for (MediaStream stream : mediaStreams) {
537
551
  // Getting the streamReactTag
538
- String streamReactTag = null;
539
- for (Map.Entry<String, MediaStream> e : remoteStreams.entrySet()) {
540
- if (e.getValue().equals(stream)) {
541
- streamReactTag = e.getKey();
542
- break;
543
- }
544
- }
552
+ String streamReactTag = remoteStreamIds.get(stream.getId());
553
+
545
554
  if (streamReactTag == null) {
546
555
  streamReactTag = UUID.randomUUID().toString();
547
- remoteStreams.put(streamReactTag, stream);
556
+ remoteStreamIds.put(stream.getId(), streamReactTag);
548
557
  }
558
+
559
+ // Make sure the stored stream is updated in case we get a new reference.
560
+ remoteStreams.put(streamReactTag, stream);
561
+
549
562
  streams.pushMap(SerializeUtils.serializeStream(id, streamReactTag, stream));
550
563
  }
551
564
 
@@ -565,15 +578,14 @@ class PeerConnectionObserver implements PeerConnection.Observer {
565
578
  * semantics are specified. The transceiver will be disposed automatically.
566
579
  */
567
580
  @Override
568
- public void onTrack(final RtpTransceiver transceiver) {
569
- }
581
+ public void onTrack(final RtpTransceiver transceiver) {}
570
582
 
571
583
  /*
572
584
  * Triggered when a previously added remote track is removed by the remote
573
585
  * peer, as a result of setRemoteDescription.
574
586
  */
575
587
  @Override
576
- public void onRemoveTrack(RtpReceiver receiver){
588
+ public void onRemoveTrack(RtpReceiver receiver) {
577
589
  ThreadUtils.runOnExecutor(() -> {
578
590
  WritableMap params = Arguments.createMap();
579
591
  params.putInt("pcId", this.id);
@@ -585,15 +597,11 @@ class PeerConnectionObserver implements PeerConnection.Observer {
585
597
 
586
598
  // This is only added to compile. Plan B is not supported anymore.
587
599
  @Override
588
- public void onRemoveStream(MediaStream stream) {
589
-
590
- }
600
+ public void onRemoveStream(MediaStream stream) {}
591
601
 
592
602
  // This is only added to compile. Plan B is not supported anymore.
593
603
  @Override
594
- public void onAddStream(MediaStream stream) {
595
-
596
- }
604
+ public void onAddStream(MediaStream stream) {}
597
605
 
598
606
  @Nullable
599
607
  private String peerConnectionStateString(PeerConnection.PeerConnectionState peerConnectionState) {
@@ -666,5 +674,4 @@ class PeerConnectionObserver implements PeerConnection.Observer {
666
674
  }
667
675
  return null;
668
676
  }
669
-
670
677
  }
@@ -1,74 +1,73 @@
1
1
  package com.oney.WebRTCModule;
2
2
 
3
- import com.facebook.react.uimanager.annotations.ReactProp;
4
3
  import com.facebook.react.uimanager.SimpleViewManager;
5
4
  import com.facebook.react.uimanager.ThemedReactContext;
6
-
5
+ import com.facebook.react.uimanager.annotations.ReactProp;
7
6
 
8
7
  public class RTCVideoViewManager extends SimpleViewManager<WebRTCView> {
9
- private static final String REACT_CLASS = "RTCVideoView";
8
+ private static final String REACT_CLASS = "RTCVideoView";
10
9
 
11
- @Override
12
- public String getName() {
13
- return REACT_CLASS;
14
- }
10
+ @Override
11
+ public String getName() {
12
+ return REACT_CLASS;
13
+ }
15
14
 
16
- @Override
17
- public WebRTCView createViewInstance(ThemedReactContext context) {
18
- return new WebRTCView(context);
19
- }
15
+ @Override
16
+ public WebRTCView createViewInstance(ThemedReactContext context) {
17
+ return new WebRTCView(context);
18
+ }
20
19
 
21
- /**
22
- * Sets the indicator which determines whether a specific {@link WebRTCView}
23
- * is to mirror the video specified by {@code streamURL} during its rendering.
24
- * For more details, refer to the documentation of the {@code mirror} property
25
- * of the JavaScript counterpart of {@code WebRTCView} i.e. {@code RTCView}.
26
- *
27
- * @param view The {@code WebRTCView} on which the specified {@code mirror} is
28
- * to be set.
29
- * @param mirror If the specified {@code WebRTCView} is to mirror the video
30
- * specified by its associated {@code streamURL} during its rendering,
31
- * {@code true}; otherwise, {@code false}.
32
- */
33
- @ReactProp(name = "mirror")
34
- public void setMirror(WebRTCView view, boolean mirror) {
35
- view.setMirror(mirror);
36
- }
20
+ /**
21
+ * Sets the indicator which determines whether a specific {@link WebRTCView}
22
+ * is to mirror the video specified by {@code streamURL} during its rendering.
23
+ * For more details, refer to the documentation of the {@code mirror} property
24
+ * of the JavaScript counterpart of {@code WebRTCView} i.e. {@code RTCView}.
25
+ *
26
+ * @param view The {@code WebRTCView} on which the specified {@code mirror} is
27
+ * to be set.
28
+ * @param mirror If the specified {@code WebRTCView} is to mirror the video
29
+ * specified by its associated {@code streamURL} during its rendering,
30
+ * {@code true}; otherwise, {@code false}.
31
+ */
32
+ @ReactProp(name = "mirror")
33
+ public void setMirror(WebRTCView view, boolean mirror) {
34
+ view.setMirror(mirror);
35
+ }
37
36
 
38
- /**
39
- * In the fashion of
40
- * https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth
41
- * and https://www.w3.org/TR/html5/rendering.html#video-object-fit, resembles
42
- * the CSS style {@code object-fit}.
43
- *
44
- * @param view The {@code WebRTCView} on which the specified {@code objectFit}
45
- * is to be set.
46
- * @param objectFit For details, refer to the documentation of the
47
- * {@code objectFit} property of the JavaScript counterpart of
48
- * {@code WebRTCView} i.e. {@code RTCView}.
49
- */
50
- @ReactProp(name = "objectFit")
51
- public void setObjectFit(WebRTCView view, String objectFit) {
52
- view.setObjectFit(objectFit);
53
- }
37
+ /**
38
+ * In the fashion of
39
+ * https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth
40
+ * and https://www.w3.org/TR/html5/rendering.html#video-object-fit, resembles
41
+ * the CSS style {@code object-fit}.
42
+ *
43
+ * @param view The {@code WebRTCView} on which the specified {@code objectFit}
44
+ * is to be set.
45
+ * @param objectFit For details, refer to the documentation of the
46
+ * {@code objectFit} property of the JavaScript counterpart of
47
+ * {@code WebRTCView} i.e. {@code RTCView}.
48
+ */
49
+ @ReactProp(name = "objectFit")
50
+ public void setObjectFit(WebRTCView view, String objectFit) {
51
+ view.setObjectFit(objectFit);
52
+ }
54
53
 
55
- @ReactProp(name = "streamURL")
56
- public void setStreamURL(WebRTCView view, String streamURL) {
57
- view.setStreamURL(streamURL);
58
- }
54
+ @ReactProp(name = "streamURL")
55
+ public void setStreamURL(WebRTCView view, String streamURL) {
56
+ view.setStreamURL(streamURL);
57
+ }
59
58
 
60
- /**
61
- * Sets the z-order of a specific {@link WebRTCView} in the stacking space of
62
- * all {@code WebRTCView}s. For more details, refer to the documentation of
63
- * the {@code zOrder} property of the JavaScript counterpart of
64
- * {@code WebRTCView} i.e. {@code RTCView}.
65
- *
66
- * @param view The {@code WebRTCView} on which the specified {@code zOrder} is
67
- * to be set.
68
- * @param zOrder The z-order to set on the specified {@code WebRTCView}.
69
- */
70
- @ReactProp(name = "zOrder")
71
- public void setZOrder(WebRTCView view, int zOrder) {
72
- view.setZOrder(zOrder);
73
- }
59
+ /**
60
+ * Sets the z-order of a specific {@link WebRTCView} in the stacking space of
61
+ * all {@code WebRTCView}s. For more details, refer to the documentation of
62
+ * the {@code zOrder} property of the JavaScript counterpart of
63
+ * {@code WebRTCView} i.e. {@code RTCView}.
64
+ *
65
+ * @param view The {@code WebRTCView} on which the specified {@code zOrder} is
66
+ * to be set.
67
+ * @param zOrder The z-order to set on the specified {@code WebRTCView}.
68
+ */
69
+ @ReactProp(name = "zOrder")
70
+ public void setZOrder(WebRTCView view, int zOrder) {
71
+ view.setZOrder(zOrder);
72
+ }
74
73
  }
@@ -4,7 +4,6 @@ import com.facebook.react.bridge.ReadableMap;
4
4
  import com.facebook.react.bridge.ReadableType;
5
5
 
6
6
  public class ReactBridgeUtil {
7
-
8
7
  /**
9
8
  * Reads a value from given <tt>ReadableMap</tt> and returns it as
10
9
  * a <tt>String</tt>. Note that integer value is converted to double, before
@@ -15,7 +14,7 @@ public class ReactBridgeUtil {
15
14
  * <tt>null</tt> if there is no value mapped for given <tt>key</tt>.
16
15
  */
17
16
  public static String getMapStrValue(ReadableMap map, String key) {
18
- if(!map.hasKey(key)){
17
+ if (!map.hasKey(key)) {
19
18
  return null;
20
19
  }
21
20
  ReadableType type = map.getType(key);
@@ -50,21 +50,19 @@ public class ScreenCaptureController extends AbstractVideoCaptureController {
50
50
 
51
51
  @Override
52
52
  protected VideoCapturer createVideoCapturer() {
53
- VideoCapturer videoCapturer = new ScreenCapturerAndroid(
54
- mediaProjectionPermissionResultData,
55
- new MediaProjection.Callback() {
56
- @Override
57
- public void onStop() {
58
- Log.w(TAG, "Media projection stopped.");
59
- orientatationListener.disable();
60
- stopCapture();
53
+ VideoCapturer videoCapturer =
54
+ new ScreenCapturerAndroid(mediaProjectionPermissionResultData, new MediaProjection.Callback() {
55
+ @Override
56
+ public void onStop() {
57
+ Log.w(TAG, "Media projection stopped.");
58
+ orientatationListener.disable();
59
+ stopCapture();
61
60
 
62
- if(capturerEventsListener != null) {
63
- capturerEventsListener.onCapturerEnded();
61
+ if (capturerEventsListener != null) {
62
+ capturerEventsListener.onCapturerEnded();
63
+ }
64
64
  }
65
- }
66
- });
67
-
65
+ });
68
66
 
69
67
  return videoCapturer;
70
68
  }