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

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 (163) hide show
  1. package/.eslintignore +6 -0
  2. package/.github/stale.yml +15 -0
  3. package/.github/workflows/ci.yml +17 -0
  4. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +36 -0
  5. package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +65 -26
  6. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +30 -1
  7. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/ProcessorProvider.java +37 -0
  8. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +57 -0
  9. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessor.java +19 -0
  10. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessorFactoryInterface.java +13 -0
  11. package/ios/RCTWebRTC/SerializeUtils.m +18 -5
  12. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +53 -5
  13. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +5 -4
  14. package/ios/RCTWebRTC.xcodeproj/project.pbxproj +46 -9
  15. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  16. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  17. package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  18. package/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  19. package/ios/RCTWebRTC.xcworkspace/contents.xcworkspacedata +10 -0
  20. package/lib/commonjs/EventEmitter.js.map +1 -1
  21. package/lib/commonjs/Logger.js.map +1 -1
  22. package/lib/commonjs/MediaDevices.js +2 -2
  23. package/lib/commonjs/MediaDevices.js.map +1 -1
  24. package/lib/commonjs/MediaStream.js +3 -3
  25. package/lib/commonjs/MediaStream.js.map +1 -1
  26. package/lib/commonjs/MediaStreamTrack.js +15 -3
  27. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  28. package/lib/commonjs/Permissions.js +3 -3
  29. package/lib/commonjs/Permissions.js.map +1 -1
  30. package/lib/commonjs/RTCDataChannel.js +6 -5
  31. package/lib/commonjs/RTCDataChannel.js.map +1 -1
  32. package/lib/commonjs/RTCErrorEvent.js +1 -1
  33. package/lib/commonjs/RTCErrorEvent.js.map +1 -1
  34. package/lib/commonjs/RTCPeerConnection.js +139 -58
  35. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  36. package/lib/commonjs/RTCRtcpParameters.js +7 -0
  37. package/lib/commonjs/RTCRtcpParameters.js.map +1 -1
  38. package/lib/commonjs/RTCRtpCapabilities.js +10 -2
  39. package/lib/commonjs/RTCRtpCapabilities.js.map +1 -1
  40. package/lib/commonjs/RTCRtpCodecParameters.js +22 -4
  41. package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -1
  42. package/lib/commonjs/RTCRtpEncodingParameters.js +21 -10
  43. package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -1
  44. package/lib/commonjs/RTCRtpHeaderExtension.js +8 -0
  45. package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -1
  46. package/lib/commonjs/RTCRtpParameters.js +25 -3
  47. package/lib/commonjs/RTCRtpParameters.js.map +1 -1
  48. package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -1
  49. package/lib/commonjs/RTCRtpReceiver.js +21 -10
  50. package/lib/commonjs/RTCRtpReceiver.js.map +1 -1
  51. package/lib/commonjs/RTCRtpSendParameters.js +10 -4
  52. package/lib/commonjs/RTCRtpSendParameters.js.map +1 -1
  53. package/lib/commonjs/RTCRtpSender.js +3 -3
  54. package/lib/commonjs/RTCRtpSender.js.map +1 -1
  55. package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
  56. package/lib/commonjs/RTCSessionDescription.js.map +1 -1
  57. package/lib/commonjs/RTCUtil.js +13 -0
  58. package/lib/commonjs/RTCUtil.js.map +1 -1
  59. package/lib/commonjs/getDisplayMedia.js.map +1 -1
  60. package/lib/commonjs/getUserMedia.js +3 -3
  61. package/lib/commonjs/getUserMedia.js.map +1 -1
  62. package/lib/commonjs/index.js +12 -93
  63. package/lib/commonjs/index.js.map +1 -1
  64. package/lib/module/EventEmitter.js.map +1 -1
  65. package/lib/module/Logger.js.map +1 -1
  66. package/lib/module/MediaDevices.js +1 -1
  67. package/lib/module/MediaDevices.js.map +1 -1
  68. package/lib/module/MediaStream.js +2 -2
  69. package/lib/module/MediaStream.js.map +1 -1
  70. package/lib/module/MediaStreamTrack.js +14 -2
  71. package/lib/module/MediaStreamTrack.js.map +1 -1
  72. package/lib/module/Permissions.js +3 -3
  73. package/lib/module/Permissions.js.map +1 -1
  74. package/lib/module/RTCDataChannel.js +4 -3
  75. package/lib/module/RTCDataChannel.js.map +1 -1
  76. package/lib/module/RTCErrorEvent.js +2 -2
  77. package/lib/module/RTCErrorEvent.js.map +1 -1
  78. package/lib/module/RTCPeerConnection.js +135 -55
  79. package/lib/module/RTCPeerConnection.js.map +1 -1
  80. package/lib/module/RTCRtcpParameters.js +7 -0
  81. package/lib/module/RTCRtcpParameters.js.map +1 -1
  82. package/lib/module/RTCRtpCapabilities.js +10 -2
  83. package/lib/module/RTCRtpCapabilities.js.map +1 -1
  84. package/lib/module/RTCRtpCodecParameters.js +22 -4
  85. package/lib/module/RTCRtpCodecParameters.js.map +1 -1
  86. package/lib/module/RTCRtpEncodingParameters.js +21 -10
  87. package/lib/module/RTCRtpEncodingParameters.js.map +1 -1
  88. package/lib/module/RTCRtpHeaderExtension.js +8 -0
  89. package/lib/module/RTCRtpHeaderExtension.js.map +1 -1
  90. package/lib/module/RTCRtpParameters.js +20 -3
  91. package/lib/module/RTCRtpParameters.js.map +1 -1
  92. package/lib/module/RTCRtpReceiveParameters.js +1 -1
  93. package/lib/module/RTCRtpReceiveParameters.js.map +1 -1
  94. package/lib/module/RTCRtpReceiver.js +18 -8
  95. package/lib/module/RTCRtpReceiver.js.map +1 -1
  96. package/lib/module/RTCRtpSendParameters.js +10 -5
  97. package/lib/module/RTCRtpSendParameters.js.map +1 -1
  98. package/lib/module/RTCRtpSender.js +3 -3
  99. package/lib/module/RTCRtpSender.js.map +1 -1
  100. package/lib/module/RTCRtpTransceiver.js.map +1 -1
  101. package/lib/module/RTCSessionDescription.js.map +1 -1
  102. package/lib/module/RTCUtil.js +11 -0
  103. package/lib/module/RTCUtil.js.map +1 -1
  104. package/lib/module/getDisplayMedia.js.map +1 -1
  105. package/lib/module/getUserMedia.js +1 -1
  106. package/lib/module/getUserMedia.js.map +1 -1
  107. package/lib/module/index.js +8 -26
  108. package/lib/module/index.js.map +1 -1
  109. package/lib/typescript/EventEmitter.d.ts +4 -3
  110. package/lib/typescript/MediaStreamTrack.d.ts +1 -0
  111. package/lib/typescript/Permissions.d.ts +1 -1
  112. package/lib/typescript/RTCDataChannel.d.ts +2 -1
  113. package/lib/typescript/RTCErrorEvent.d.ts +1 -1
  114. package/lib/typescript/RTCPeerConnection.d.ts +7 -8
  115. package/lib/typescript/RTCRtcpParameters.d.ts +6 -4
  116. package/lib/typescript/RTCRtpCodecParameters.d.ts +11 -9
  117. package/lib/typescript/RTCRtpEncodingParameters.d.ts +13 -11
  118. package/lib/typescript/RTCRtpHeaderExtension.d.ts +7 -5
  119. package/lib/typescript/RTCRtpParameters.d.ts +9 -8
  120. package/lib/typescript/RTCRtpReceiveParameters.d.ts +1 -1
  121. package/lib/typescript/RTCRtpReceiver.d.ts +9 -4
  122. package/lib/typescript/RTCRtpSendParameters.d.ts +9 -10
  123. package/lib/typescript/RTCRtpSender.d.ts +3 -3
  124. package/lib/typescript/RTCRtpTransceiver.d.ts +1 -1
  125. package/lib/typescript/RTCSessionDescription.d.ts +6 -8
  126. package/lib/typescript/RTCUtil.d.ts +7 -0
  127. package/lib/typescript/index.d.ts +6 -15
  128. package/package.json +7 -4
  129. package/react-native-webrtc.podspec +1 -2
  130. package/src/.eslintrc.cjs +67 -0
  131. package/src/EventEmitter.ts +5 -4
  132. package/src/Logger.ts +1 -1
  133. package/src/MediaDevices.ts +2 -2
  134. package/src/MediaStream.ts +13 -4
  135. package/src/MediaStreamTrack.ts +21 -5
  136. package/src/Permissions.ts +12 -5
  137. package/src/RTCDataChannel.ts +17 -5
  138. package/src/RTCErrorEvent.ts +9 -9
  139. package/src/RTCPeerConnection.ts +189 -91
  140. package/src/RTCRtcpParameters.ts +21 -12
  141. package/src/RTCRtpCapabilities.ts +15 -4
  142. package/src/RTCRtpCodecParameters.ts +34 -13
  143. package/src/RTCRtpEncodingParameters.ts +37 -23
  144. package/src/RTCRtpHeaderExtension.ts +15 -6
  145. package/src/RTCRtpParameters.ts +26 -11
  146. package/src/RTCRtpReceiveParameters.ts +3 -3
  147. package/src/RTCRtpReceiver.ts +26 -10
  148. package/src/RTCRtpSendParameters.ts +29 -17
  149. package/src/RTCRtpSender.ts +14 -13
  150. package/src/RTCRtpTransceiver.ts +11 -7
  151. package/src/RTCSessionDescription.ts +7 -2
  152. package/src/RTCUtil.ts +24 -4
  153. package/src/getDisplayMedia.ts +1 -1
  154. package/src/getUserMedia.ts +9 -2
  155. package/src/index.ts +9 -34
  156. package/tools/downloadWebRTC.js +7 -5
  157. package/.prettierignore +0 -9
  158. package/.prettierrc.json +0 -10
  159. package/lib/commonjs/typings.d.js +0 -2
  160. package/lib/commonjs/typings.d.js.map +0 -1
  161. package/lib/module/typings.d.js +0 -2
  162. package/lib/module/typings.d.js.map +0 -1
  163. package/src/typings.d.ts +0 -1
package/.eslintignore ADDED
@@ -0,0 +1,6 @@
1
+ examples
2
+ lib
3
+ tools
4
+
5
+ metro.*.js
6
+ react-native.config.js
@@ -0,0 +1,15 @@
1
+ # Number of days of inactivity before an issue becomes stale
2
+ daysUntilStale: 60
3
+ # Number of days of inactivity before a stale issue is closed
4
+ daysUntilClose: 7
5
+ # Issues with these labels will never be considered stale
6
+ exemptLabels:
7
+ - confirmed
8
+ staleLabel: wontfix
9
+ # Comment to post when marking an issue as stale. Set to `false` to disable
10
+ markComment: >
11
+ This issue has been automatically marked as stale because it has not had
12
+ recent activity. It will be closed if no further activity occurs. Thank you
13
+ for your contributions.
14
+ # Comment to post when closing a stale issue. Set to `false` to disable
15
+ closeComment: false
@@ -0,0 +1,17 @@
1
+ name: Simple CI
2
+
3
+ on: [pull_request]
4
+
5
+ jobs:
6
+ run-ci:
7
+ name: Lint
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - uses: actions/setup-node@v3
12
+ with:
13
+ node-version: 16
14
+ - run: npm install
15
+ - name: Check if the git repository is clean
16
+ run: $(exit $(git status --porcelain --untracked-files=no | head -255 | wc -l)) || (echo "Dirty git tree"; git diff; exit 1)
17
+ - run: npm run lint
@@ -18,6 +18,10 @@ import com.facebook.react.bridge.UiThreadUtil;
18
18
  import com.facebook.react.bridge.WritableArray;
19
19
  import com.facebook.react.bridge.WritableMap;
20
20
 
21
+ import com.oney.WebRTCModule.videoEffects.ProcessorProvider;
22
+ import com.oney.WebRTCModule.videoEffects.VideoEffectProcessor;
23
+ import com.oney.WebRTCModule.videoEffects.VideoFrameProcessor;
24
+
21
25
  import java.util.ArrayList;
22
26
  import java.util.HashMap;
23
27
  import java.util.Map;
@@ -390,6 +394,38 @@ class GetUserMediaImpl {
390
394
  return track;
391
395
  }
392
396
 
397
+ /**
398
+ * Set video effect to the TrackPrivate corresponding to the trackId with the help of VideoEffectProcessor
399
+ * corresponding to the name.
400
+ * @param trackId TrackPrivate id
401
+ * @param name VideoEffectProcessor name
402
+ */
403
+ void setVideoEffect(String trackId, String name) {
404
+ TrackPrivate track = tracks.get(trackId);
405
+
406
+ if (track != null && track.videoCaptureController instanceof CameraCaptureController) {
407
+ VideoSource videoSource = (VideoSource) track.mediaSource;
408
+ SurfaceTextureHelper surfaceTextureHelper = track.surfaceTextureHelper;
409
+
410
+ if (name != null) {
411
+ VideoFrameProcessor videoFrameProcessor = ProcessorProvider.getProcessor(name);
412
+
413
+ if (videoFrameProcessor == null) {
414
+ Log.e(TAG, "no videoFrameProcessor associated with this name");
415
+ return;
416
+ }
417
+
418
+ VideoEffectProcessor videoEffectProcessor = new VideoEffectProcessor(videoFrameProcessor,
419
+ surfaceTextureHelper);
420
+ videoSource.setVideoProcessor(videoEffectProcessor);
421
+
422
+ } else {
423
+ videoSource.setVideoProcessor(null);
424
+ }
425
+
426
+ }
427
+ }
428
+
393
429
  /**
394
430
  * Application/library-specific private members of local
395
431
  * {@code MediaStreamTrack}s created by {@code GetUserMediaImpl}.
@@ -5,6 +5,7 @@ import java.util.ArrayList;
5
5
  import java.util.HashMap;
6
6
  import java.util.List;
7
7
  import java.util.Map;
8
+ import java.util.stream.Collectors;
8
9
 
9
10
  import org.webrtc.*;
10
11
 
@@ -96,7 +97,10 @@ public class SerializeUtils {
96
97
  WritableMap res = Arguments.createMap();
97
98
  res.putString("id", receiver.id());
98
99
  res.putInt("peerConnectionId", id);
99
- res.putMap("track", SerializeUtils.serializeTrack(id, receiver.track()));
100
+ if (receiver.track() != null) {
101
+ res.putMap("track", SerializeUtils.serializeTrack(id, receiver.track()));
102
+ }
103
+ res.putMap("rtpParameters", SerializeUtils.serializeRtpParameters(receiver.getParameters()));
100
104
  return res;
101
105
  }
102
106
 
@@ -126,12 +130,10 @@ public class SerializeUtils {
126
130
  WritableArray headerExtensions = Arguments.createArray();
127
131
  WritableMap rtcp = Arguments.createMap();
128
132
 
129
-
130
133
  // Preparing RTCP
131
134
  rtcp.putString("cname", params.getRtcp().getCname());
132
135
  rtcp.putBoolean("reducedSize", params.getRtcp().getReducedSize());
133
-
134
-
136
+
135
137
  // Preparing header extensions
136
138
  params.getHeaderExtensions().forEach(extension -> {
137
139
  WritableMap extensionMap = Arguments.createMap();
@@ -145,6 +147,9 @@ public class SerializeUtils {
145
147
  params.encodings.forEach(encoding -> {
146
148
  WritableMap encodingMap = Arguments.createMap();
147
149
  encodingMap.putBoolean("active", encoding.active);
150
+ if (encoding.rid != null) {
151
+ encodingMap.putString("rid", encoding.rid);
152
+ }
148
153
  // Since they return integer objects that are nullable,
149
154
  // while the map does not accept nullable integer values.
150
155
  if (encoding.maxBitrateBps != null) {
@@ -162,7 +167,6 @@ public class SerializeUtils {
162
167
  // Preparing codecs
163
168
  params.codecs.forEach(codec -> {
164
169
  WritableMap codecMap = Arguments.createMap();
165
- WritableMap sdpFmptLineParams = Arguments.createMap();
166
170
  codecMap.putInt("payloadType", codec.payloadType);
167
171
  codecMap.putString("mimeType", codec.name);
168
172
  codecMap.putInt("clockRate", codec.clockRate);
@@ -170,10 +174,13 @@ public class SerializeUtils {
170
174
  codecMap.putInt("channels", codec.numChannels);
171
175
  }
172
176
  // Serializing sdpFmptLine.
173
- codec.parameters.forEach((k, v) -> {
174
- sdpFmptLineParams.putString((String) k, (String) v);
175
- });
176
- codecMap.putMap("sdpFmtpLine", sdpFmptLineParams);
177
+ if (!codec.parameters.isEmpty()) {
178
+ final String sdpFmptLineParams = codec.parameters.keySet().stream()
179
+ .map(key -> key + "=" + map.get(key))
180
+ .collect(Collectors.joining(";"));
181
+ codecMap.putString("sdpFmtpLine", sdpFmptLineParams);
182
+ }
183
+
177
184
  codecs.pushMap(codecMap);
178
185
  });
179
186
 
@@ -207,12 +214,13 @@ public class SerializeUtils {
207
214
  ReadableMap encodingUpdate = encodingsArray.getMap(i);
208
215
  RtpParameters.Encoding encoding = encodings.get(i);
209
216
  // Dealing with nullable Integers
210
- Integer maxBitrate = encodingUpdate.hasKey("maxBitrate")? encodingUpdate.getInt("maxBitrate") : null;
211
- Integer maxFramerate = encodingUpdate.hasKey("maxFramerate")? encodingUpdate.getInt("maxFramerate") : null;
212
- Double scaleResolutionDownBy = encodingUpdate.hasKey("scaleResolutionDownBy")?
217
+ Integer maxBitrate = encodingUpdate.hasKey("maxBitrate") ? encodingUpdate.getInt("maxBitrate") : null;
218
+ Integer maxFramerate = encodingUpdate.hasKey("maxFramerate") ? encodingUpdate.getInt("maxFramerate") : null;
219
+ Double scaleResolutionDownBy = encodingUpdate.hasKey("scaleResolutionDownBy") ?
213
220
  encodingUpdate.getDouble("scaleResolutionDownBy") : null;
214
221
 
215
222
  encoding.active = encodingUpdate.getBoolean("active");
223
+ encoding.rid = encodingUpdate.getString("rid");
216
224
  encoding.maxBitrateBps = maxBitrate;
217
225
  encoding.maxFramerate = maxFramerate;
218
226
  encoding.scaleResolutionDownBy = scaleResolutionDownBy;
@@ -253,27 +261,58 @@ public class SerializeUtils {
253
261
  throw new Error("Invalid direction");
254
262
  }
255
263
 
264
+ private static RtpParameters.Encoding parseEncoding(ReadableMap params) {
265
+ RtpParameters.Encoding encoding = new RtpParameters.Encoding(params.getString("rid"), true, 1.0);
266
+
267
+ if (params.hasKey("active")) {
268
+ encoding.active = params.getBoolean("active");
269
+ }
270
+ if (params.hasKey("maxBitrate")) {
271
+ encoding.maxBitrateBps = params.getInt("maxBitrate");
272
+ }
273
+ if (params.hasKey("maxFramerate")) {
274
+ encoding.maxFramerate = params.getInt("maxFramerate");
275
+ }
276
+ if (params.hasKey("scaleResolutionDownBy")) {
277
+ encoding.scaleResolutionDownBy = params.getDouble("scaleResolutionDownBy");
278
+ }
279
+
280
+ return encoding;
281
+ }
282
+
256
283
  public static RtpTransceiver.RtpTransceiverInit parseTransceiverOptions(ReadableMap map) {
284
+ if (map == null) {
285
+ return null;
286
+ }
287
+
257
288
  RtpTransceiver.RtpTransceiverDirection direction = RtpTransceiver.RtpTransceiverDirection.INACTIVE;
258
- ArrayList<String> streamIds = new ArrayList<>();
259
- if (map != null) {
260
- if (map.hasKey("direction")) {
261
- String directionRaw = map.getString("direction");
262
- if (directionRaw != null) {
263
- direction = SerializeUtils.parseDirection(directionRaw);
289
+ List<String> streamIds = new ArrayList<>();
290
+ List<RtpParameters.Encoding> sendEncodings = new ArrayList<>();
291
+
292
+ if (map.hasKey("direction")) {
293
+ String directionRaw = map.getString("direction");
294
+ if (directionRaw != null) {
295
+ direction = SerializeUtils.parseDirection(directionRaw);
296
+ }
297
+ }
298
+ if (map.hasKey("streamIds")) {
299
+ ReadableArray rawStreamIds = map.getArray("streamIds");
300
+ if (rawStreamIds != null) {
301
+ for (int i = 0; i < rawStreamIds.size(); i++) {
302
+ streamIds.add(rawStreamIds.getString(i));
264
303
  }
265
304
  }
266
- if (map.hasKey("streamIds")) {
267
- ReadableArray rawStreamIds = map.getArray("streamIds");
268
- if (rawStreamIds != null) {
269
- for (int i = 0; i < rawStreamIds.size(); i++) {
270
- streamIds.add(rawStreamIds.getString(i));
271
- }
305
+ }
306
+ if (map.hasKey("sendEncodings")) {
307
+ ReadableArray encodingsArray = map.getArray("sendEncodings");
308
+ if (encodingsArray != null) {
309
+ for (int i = 0; i < encodingsArray.size(); i++){
310
+ ReadableMap encoding = encodingsArray.getMap(i);
311
+ sendEncodings.add(SerializeUtils.parseEncoding(encoding));
272
312
  }
273
313
  }
274
314
  }
275
315
 
276
- return new RtpTransceiver.RtpTransceiverInit(direction, streamIds);
316
+ return new RtpTransceiver.RtpTransceiverInit(direction, streamIds, sendEncodings);
277
317
  }
278
-
279
318
  }
@@ -889,11 +889,21 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
889
889
  transceiverUpdate.putMap("senderRtpParameters",
890
890
  SerializeUtils.serializeRtpParameters(
891
891
  transceiver.getSender().getParameters()));
892
+ transceiverUpdate.putMap("receiverRtpParameters",
893
+ SerializeUtils.serializeRtpParameters(
894
+ transceiver.getReceiver().getParameters()));
892
895
  transceiverUpdates.pushMap(transceiverUpdate);
893
896
  }
894
897
  return transceiverUpdates;
895
898
  }
896
899
 
900
+ @ReactMethod
901
+ public void mediaStreamTrackSetVideoEffect(String id, String name) {
902
+ ThreadUtils.runOnExecutor(() -> {
903
+ getUserMediaImpl.setVideoEffect(id, name);
904
+ });
905
+ }
906
+
897
907
  @ReactMethod
898
908
  public void peerConnectionSetConfiguration(ReadableMap configuration,
899
909
  int id) {
@@ -1042,7 +1052,9 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
1042
1052
  int id,
1043
1053
  Callback callback) {
1044
1054
  ThreadUtils.runOnExecutor(() -> {
1045
- PeerConnection peerConnection = getPeerConnection(id);
1055
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
1056
+ PeerConnection peerConnection = pco.getPeerConnection();
1057
+
1046
1058
  if (peerConnection == null) {
1047
1059
  Log.d(TAG, "peerConnectionSetRemoteDescription() peerConnection is null");
1048
1060
  callback.invoke(false, "peerConnection is null");
@@ -1054,6 +1066,10 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
1054
1066
  sdpMap.getString("sdp")
1055
1067
  );
1056
1068
 
1069
+ List<String> receiversIds = new ArrayList<>();
1070
+ for(RtpTransceiver transceiver: peerConnection.getTransceivers()) {
1071
+ receiversIds.add(transceiver.getReceiver().id());
1072
+ }
1057
1073
  peerConnection.setRemoteDescription(new SdpObserver() {
1058
1074
  @Override
1059
1075
  public void onCreateSuccess(final SessionDescription sdp) {
@@ -1068,6 +1084,19 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
1068
1084
  newSdpMap.putString("sdp", newSdp.description);
1069
1085
  params.putArray("transceiversInfo", getTransceiversInfo(id));
1070
1086
  params.putMap("sdpInfo", newSdpMap);
1087
+
1088
+ WritableArray newTransceivers = Arguments.createArray();
1089
+ for(RtpTransceiver transceiver: peerConnection.getTransceivers()) {
1090
+ if(!receiversIds.contains(transceiver.getReceiver().id())) {
1091
+ WritableMap newTransceiver = Arguments.createMap();
1092
+ newTransceiver.putInt("transceiverOrder", pco.getNextTransceiverId());
1093
+ newTransceiver.putMap("transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
1094
+ newTransceivers.pushMap(newTransceiver);
1095
+ }
1096
+ }
1097
+
1098
+ params.putArray("newTransceivers", newTransceivers);
1099
+
1071
1100
  callback.invoke(true, params);
1072
1101
  }
1073
1102
 
@@ -0,0 +1,37 @@
1
+ package com.oney.WebRTCModule.videoEffects;
2
+
3
+ import java.util.HashMap;
4
+ import java.util.Map;
5
+
6
+ /**
7
+ * Manages VideoFrameProcessorFactoryInterfaces corresponding to name using hashmap, and provides
8
+ * get, add and remove functionality.
9
+ */
10
+ public class ProcessorProvider {
11
+ private static Map<String, VideoFrameProcessorFactoryInterface> methodMap = new HashMap<String, VideoFrameProcessorFactoryInterface>();
12
+
13
+ public static VideoFrameProcessor getProcessor(String name) {
14
+ if (methodMap.containsKey(name)) {
15
+ return methodMap.get(name).build();
16
+ } else{
17
+ return null;
18
+ }
19
+ }
20
+
21
+ public static void addProcessor(String name,
22
+ VideoFrameProcessorFactoryInterface videoFrameProcessorFactoryInterface) {
23
+ if (name != null && videoFrameProcessorFactoryInterface != null) {
24
+ methodMap.put(name, videoFrameProcessorFactoryInterface);
25
+ } else{
26
+ throw new NullPointerException("Name or VideoFrameProcessorFactry can not be null");
27
+ }
28
+ }
29
+
30
+ public static void removeProcessor(String name) {
31
+ if (name != null && methodMap.containsKey(name)) {
32
+ methodMap.remove(name);
33
+ } else{
34
+ throw new RuntimeException("VideoFrameProcessorFactry with " + name + " does not exist");
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,57 @@
1
+ package com.oney.WebRTCModule.videoEffects;
2
+
3
+ import org.webrtc.SurfaceTextureHelper;
4
+ import org.webrtc.VideoFrame;
5
+ import org.webrtc.VideoProcessor;
6
+ import org.webrtc.VideoSink;
7
+
8
+ /**
9
+ * Lightweight abstraction for an object that can receive video frames, process and add effects in
10
+ * them, and pass them on to another object.
11
+ */
12
+ public class VideoEffectProcessor implements VideoProcessor {
13
+ private VideoSink mSink;
14
+ final private SurfaceTextureHelper textureHelper;
15
+ final private VideoFrameProcessor videoFrameProcessor;
16
+
17
+ public VideoEffectProcessor(VideoFrameProcessor processor, SurfaceTextureHelper textureHelper) {
18
+ this.textureHelper = textureHelper;
19
+ this.videoFrameProcessor = processor;
20
+ }
21
+
22
+ @Override
23
+ public void onCapturerStarted(boolean success) {
24
+
25
+ }
26
+
27
+ @Override
28
+ public void onCapturerStopped() {
29
+
30
+ }
31
+
32
+ @Override
33
+ public void setSink(VideoSink sink) {
34
+ mSink = sink;
35
+ }
36
+
37
+ /**
38
+ * Called just after the frame is captured.
39
+ * Will process the VideoFrame with the help of VideoFrameProcessor and send the processed
40
+ * VideoFrame back to webrtc using onFrame method in VideoSink.
41
+ * @param frame raw VideoFrame received from webrtc.
42
+ */
43
+ @Override
44
+ public void onFrameCaptured(VideoFrame frame) {
45
+ frame.retain();
46
+ VideoFrame outputFrame = videoFrameProcessor.process(frame, textureHelper);
47
+
48
+ if (outputFrame == null) {
49
+ mSink.onFrame(frame);
50
+ frame.release();
51
+ return;
52
+ }
53
+ mSink.onFrame(outputFrame);
54
+ outputFrame.release();
55
+ frame.release();
56
+ }
57
+ }
@@ -0,0 +1,19 @@
1
+ package com.oney.WebRTCModule.videoEffects;
2
+
3
+ import org.webrtc.SurfaceTextureHelper;
4
+ import org.webrtc.VideoFrame;
5
+
6
+ /**
7
+ * Interface contains process method to process VideoFrame.
8
+ * The caller takes ownership of the object.
9
+ */
10
+ public interface VideoFrameProcessor {
11
+ /**
12
+ * Applies the image processing algorithms to the frame. Returns the processed frame.
13
+ * The caller is responsible for releasing the returned frame.
14
+ * @param frame raw videoframe which need to be processed
15
+ * @param textureHelper
16
+ * @return processed videoframe which will rendered
17
+ */
18
+ public VideoFrame process(VideoFrame frame, SurfaceTextureHelper textureHelper);
19
+ }
@@ -0,0 +1,13 @@
1
+ package com.oney.WebRTCModule.videoEffects;
2
+
3
+ /**
4
+ * Factory for creating VideoFrameProcessor instances.
5
+ */
6
+ public interface VideoFrameProcessorFactoryInterface {
7
+
8
+ /**
9
+ * Dynamically allocates a VideoFrameProcessor instance and returns a pointer to it.
10
+ * The caller takes ownership of the object.
11
+ */
12
+ public VideoFrameProcessor build();
13
+ }
@@ -36,7 +36,8 @@
36
36
  NSString *currentDirectionSerialized = [SerializeUtils serializeDirection: currentDirection];
37
37
  transceiverUpdate[@"currentDirection"] = currentDirectionSerialized;
38
38
  transceiverUpdate[@"senderRtpParameters"] = [SerializeUtils parametersToJSON:transceiver.sender.parameters];
39
-
39
+ transceiverUpdate[@"receiverRtpParameters"] = [SerializeUtils parametersToJSON:transceiver.receiver.parameters];
40
+
40
41
  [transceiverUpdates addObject:transceiverUpdate];
41
42
  }
42
43
  }
@@ -69,6 +70,8 @@
69
70
  if (receiver.track) {
70
71
  receiverDictionary[@"track"] = [SerializeUtils trackToJSONWithPeerConnectionId: id track: receiver.track];
71
72
  }
73
+
74
+ receiverDictionary[@"rtpParameters"] = [SerializeUtils parametersToJSON: receiver.parameters];
72
75
 
73
76
  return receiverDictionary;
74
77
  }
@@ -95,9 +98,12 @@
95
98
 
96
99
  for (RTCRtpEncodingParameters *encoding in params.encodings) {
97
100
  NSMutableDictionary *encodingDictionary = [NSMutableDictionary new];
98
-
101
+
99
102
  encodingDictionary[@"active"] = [NSNumber numberWithBool: encoding.isActive];
100
-
103
+
104
+ if (encoding.rid) {
105
+ encodingDictionary[@"rid"] = encoding.rid;
106
+ }
101
107
  if (encoding.maxBitrateBps) {
102
108
  encodingDictionary[@"maxBitrate"] = encoding.maxBitrateBps;
103
109
  }
@@ -123,8 +129,15 @@
123
129
  if (codec.numChannels) {
124
130
  codecDictionary[@"channels"] = codec.numChannels;
125
131
  }
126
-
127
- codecDictionary[@"sdpFmtpLine"] = codec.parameters;
132
+
133
+ if (codec.parameters.count) {
134
+ NSMutableArray *parts = [NSMutableArray arrayWithCapacity:codec.parameters.count];
135
+ [codec.parameters enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull value, BOOL * _Nonnull stop) {
136
+ [parts addObject:[NSString stringWithFormat:@"%@=%@", key, value]];
137
+ }];
138
+
139
+ codecDictionary[@"sdpFmtpLine"] = [parts componentsJoinedByString:@";"];
140
+ }
128
141
 
129
142
  [codecs addObject: codecDictionary];
130
143
  }
@@ -240,6 +240,11 @@ RCT_EXPORT_METHOD(peerConnectionSetRemoteDescription:(RTCSessionDescription *)sd
240
240
  return;
241
241
  }
242
242
 
243
+ NSMutableArray *receiversIds = [NSMutableArray new];
244
+ for (RTCRtpTransceiver *transceiver in peerConnection.transceivers) {
245
+ [receiversIds addObject:transceiver.receiver.receiverId];
246
+ }
247
+
243
248
  [peerConnection setRemoteDescription: sdp completionHandler: ^(NSError *error) {
244
249
  if (error) {
245
250
  id errorResponse = @{
@@ -248,11 +253,22 @@ RCT_EXPORT_METHOD(peerConnectionSetRemoteDescription:(RTCSessionDescription *)sd
248
253
  };
249
254
  callback(@[@(NO), errorResponse]);
250
255
  } else {
256
+ NSMutableArray *newTransceivers = [NSMutableArray new];
257
+ for (RTCRtpTransceiver *transceiver in peerConnection.transceivers) {
258
+ if (![receiversIds containsObject:transceiver.receiver.receiverId]) {
259
+ NSMutableDictionary *newTransceiver = [NSMutableDictionary new];
260
+ newTransceiver[@"transceiverOrder"] = [NSNumber numberWithInt:_transceiverNextId++];
261
+ newTransceiver[@"transceiver"] = [SerializeUtils transceiverToJSONWithPeerConnectionId:objectID transceiver:transceiver];
262
+ [newTransceivers addObject:newTransceiver];
263
+ }
264
+ }
265
+
251
266
  id newSdp = @{
252
267
  @"sdpInfo": @{
253
268
  @"type": [RTCSessionDescription stringForType:peerConnection.remoteDescription.type],
254
269
  @"sdp": peerConnection.remoteDescription.sdp},
255
- @"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID]
270
+ @"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID],
271
+ @"newTransceivers": newTransceivers
256
272
  };
257
273
  callback(@[@(YES), newSdp]);
258
274
  }
@@ -348,7 +364,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTrack:(nonnull NSNumber
348
364
  trackId:(NSString *)trackId
349
365
  options:(NSDictionary *)options)
350
366
  {
351
- __block id params;
367
+ __block id params = nil;
352
368
 
353
369
  dispatch_sync(self.workerQueue, ^{
354
370
  RTCPeerConnection *peerConnection = self.peerConnections[objectID];
@@ -388,7 +404,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTrack:(nonnull NSNumber
388
404
  RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver:(nonnull NSNumber *)objectID
389
405
  options:(NSDictionary *)options)
390
406
  {
391
- __block id params;
407
+ __block id params = nil;
392
408
 
393
409
  dispatch_sync(self.workerQueue, ^{
394
410
  RTCPeerConnection *peerConnection = self.peerConnections[objectID];
@@ -435,8 +451,17 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver:(nonnull NSN
435
451
  if (streamIds) {
436
452
  [transceiverInit setStreamIds:streamIds];
437
453
  }
454
+
455
+ NSArray *encodingsArray = [initOptions objectForKey:@"sendEncodings"];
456
+ if (encodingsArray) {
457
+ NSMutableArray<RTCRtpEncodingParameters *> *sendEncodings = [NSMutableArray new];
458
+ for (NSDictionary* encoding in encodingsArray) {
459
+ [sendEncodings addObject:[self parseEncoding:encoding]];
460
+ }
461
+ [transceiverInit setSendEncodings:sendEncodings];
462
+ }
438
463
  }
439
-
464
+
440
465
  transceiver = [peerConnection addTransceiverWithTrack:track init:transceiverInit];
441
466
  } else {
442
467
  RCTLogWarn(@"peerConnectionAddTransceiver() no type nor trackId provided in options");
@@ -473,7 +498,7 @@ RCT_EXPORT_METHOD(peerConnectionRemoveTrack:(nonnull NSNumber *)objectID
473
498
  RTCRtpTransceiver *transceiver = nil;
474
499
 
475
500
  for (RTCRtpTransceiver *t in peerConnection.transceivers) {
476
- if (t.sender.senderId == senderId) {
501
+ if ([t.sender.senderId isEqual: senderId]) {
477
502
  transceiver = t;
478
503
  break;
479
504
  }
@@ -501,6 +526,29 @@ RCT_EXPORT_METHOD(peerConnectionRemoveTrack:(nonnull NSNumber *)objectID
501
526
 
502
527
  // TODO: move these below to some SerializeUrils file
503
528
 
529
+ - (RTCRtpEncodingParameters*)parseEncoding:(NSDictionary*)params
530
+ {
531
+ RTCRtpEncodingParameters *encoding = [RTCRtpEncodingParameters new];
532
+
533
+ if (params[@"rid"] != nil) {
534
+ [encoding setRid:params[@"rid"]];
535
+ }
536
+ if (params[@"active"] != nil) {
537
+ [encoding setIsActive:((NSNumber*)params[@"active"]).boolValue];
538
+ }
539
+ if (params[@"maxBitrate"] != nil) {
540
+ [encoding setMaxBitrateBps:(NSNumber*)params[@"maxBitrate"]];
541
+ }
542
+ if (params[@"maxFramerate"] != nil) {
543
+ [encoding setMaxFramerate:(NSNumber*)params[@"maxFramerate"]];
544
+ }
545
+ if (params[@"scaleResolutionDownBy"] != nil) {
546
+ [encoding setScaleResolutionDownBy:(NSNumber*)params[@"scaleResolutionDownBy"]];
547
+ }
548
+
549
+ return encoding;
550
+ }
551
+
504
552
  /**
505
553
  * Constructs a JSON <tt>NSString</tt> representation of a specific
506
554
  * <tt>RTCStatisticsReport</tt>s.
@@ -199,17 +199,18 @@ RCT_EXPORT_METHOD(transceiverStop:(nonnull NSNumber *) objectID
199
199
  for (int i = 0; i < [encodingsArray count]; i++) {
200
200
  NSDictionary *encodingUpdate = encodingsArray[i];
201
201
  RTCRtpEncodingParameters *encoding = encodings[i];
202
-
203
- [encoding setIsActive: encodingUpdate[@"active"]];
202
+
203
+ encoding.isActive = encodingUpdate[@"active"];
204
+ encoding.rid = encodingUpdate[@"rid"];
204
205
  encoding.maxBitrateBps = encodingUpdate[@"maxBitrate"];
205
206
  encoding.maxFramerate = encodingUpdate[@"maxFramerate"];
206
207
  encoding.scaleResolutionDownBy = encodingUpdate[@"scaleResolutionDownBy"];
207
208
  }
208
-
209
+
209
210
  if ([options objectForKey:@"degradationPreference"]) {
210
211
  params.degradationPreference = [options objectForKey:@"degradationPreference"];
211
212
  }
212
-
213
+
213
214
  return params;
214
215
  }
215
216