react-native-webrtc 1.94.0 → 1.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ A WebRTC module for React Native.
7
7
  - Support iOS / macOS / Android.
8
8
  - Support Video / Audio / Data Channels.
9
9
 
10
- **NOTE** for Expo users: this plugin doesn't work unless you eject.
10
+ > 🚨 Expo: This package is not available in the [Expo Go](https://expo.dev/client) app. Learn how you can use this package in [Custom Dev Clients](https://docs.expo.dev/development/getting-started/) via the out-of-tree [Expo Config Plugin](https://github.com/expo/config-plugins/tree/master/packages/react-native-webrtc).
11
11
 
12
12
  ## Community
13
13
 
@@ -15,7 +15,7 @@ Everyone is welcome to our [Discourse community](https://react-native-webrtc.dis
15
15
 
16
16
  ## WebRTC Revision
17
17
 
18
- * Currently used revision: [M92](https://github.com/jitsi/webrtc/commit/4f97ba956083bdd402aa6d3f55cc064831f88f50)
18
+ * Currently used revision: [M94](https://github.com/jitsi/webrtc/releases/tag/v94.0.0)
19
19
  * Supported architectures
20
20
  * Android: armeabi-v7a, arm64-v8a, x86, x86_64
21
21
  * iOS: arm64, x86_64 (for bitcode support, run [this script](https://github.com/react-native-webrtc/react-native-webrtc/blob/master/tools/downloadBitcode.sh))
@@ -107,9 +107,11 @@ class GetUserMediaImpl {
107
107
 
108
108
  AudioSource audioSource = pcFactory.createAudioSource(peerConstraints);
109
109
  AudioTrack track = pcFactory.createAudioTrack(id, audioSource);
110
+
111
+ // surfaceTextureHelper is initialized for videoTrack only, so its null here.
110
112
  tracks.put(
111
113
  id,
112
- new TrackPrivate(track, audioSource, /* videoCapturer */ null));
114
+ new TrackPrivate(track, audioSource, /* videoCapturer */ null, /* surfaceTextureHelper */ null));
113
115
 
114
116
  return track;
115
117
  }
@@ -381,7 +383,7 @@ class GetUserMediaImpl {
381
383
  VideoTrack track = pcFactory.createVideoTrack(id, videoSource);
382
384
 
383
385
  track.setEnabled(true);
384
- tracks.put(id, new TrackPrivate(track, videoSource, videoCaptureController));
386
+ tracks.put(id, new TrackPrivate(track, videoSource, videoCaptureController, surfaceTextureHelper));
385
387
 
386
388
  videoCaptureController.startCapture();
387
389
 
@@ -405,6 +407,8 @@ class GetUserMediaImpl {
405
407
  * if {@link #track} is a {@link VideoTrack}.
406
408
  */
407
409
  public final AbstractVideoCaptureController videoCaptureController;
410
+
411
+ private final SurfaceTextureHelper surfaceTextureHelper;
408
412
 
409
413
  /**
410
414
  * Whether this object has been disposed or not.
@@ -424,10 +428,12 @@ class GetUserMediaImpl {
424
428
  public TrackPrivate(
425
429
  MediaStreamTrack track,
426
430
  MediaSource mediaSource,
427
- AbstractVideoCaptureController videoCaptureController) {
431
+ AbstractVideoCaptureController videoCaptureController,
432
+ SurfaceTextureHelper surfaceTextureHelper) {
428
433
  this.track = track;
429
434
  this.mediaSource = mediaSource;
430
435
  this.videoCaptureController = videoCaptureController;
436
+ this.surfaceTextureHelper = surfaceTextureHelper;
431
437
  this.disposed = false;
432
438
  }
433
439
 
@@ -438,6 +444,18 @@ class GetUserMediaImpl {
438
444
  videoCaptureController.dispose();
439
445
  }
440
446
  }
447
+
448
+ /*
449
+ * As per webrtc library documentation - The caller still has ownership of {@code
450
+ * surfaceTextureHelper} and is responsible for making sure surfaceTextureHelper.dispose() is
451
+ * called. This also means that the caller can reuse the SurfaceTextureHelper to initialize a new
452
+ * VideoCapturer once the previous VideoCapturer has been disposed. */
453
+
454
+ if(surfaceTextureHelper != null) {
455
+ surfaceTextureHelper.stopListening();
456
+ surfaceTextureHelper.dispose();
457
+ }
458
+
441
459
  mediaSource.dispose();
442
460
  track.dispose();
443
461
  disposed = true;
@@ -1,5 +1,7 @@
1
1
  package com.oney.WebRTCModule;
2
2
 
3
+ import android.util.Log;
4
+
3
5
  import org.webrtc.PeerConnection;
4
6
  import org.webrtc.RTCStats;
5
7
  import org.webrtc.RTCStatsReport;
@@ -7,6 +9,8 @@ import org.webrtc.RTCStatsReport;
7
9
  import java.util.Map;
8
10
 
9
11
  public class StringUtils {
12
+ private static final String TAG = StringUtils.class.getSimpleName();
13
+
10
14
  /**
11
15
  * Constructs a JSON <tt>String</tt> representation of a specific array of
12
16
  * <tt>RTCStatsReport</tt>s (produced by {@link PeerConnection#getStats}).
@@ -74,6 +78,26 @@ public class StringUtils {
74
78
  }
75
79
 
76
80
  builder.append("]");
81
+ } else if (value instanceof Map) {
82
+ try {
83
+ Map<String, Object> mapValue = (Map) value;
84
+
85
+ boolean firstKey = true;
86
+ builder.append("{");
87
+
88
+ for (Map.Entry<String, Object> entry : mapValue.entrySet()) {
89
+ if (firstKey) {
90
+ firstKey = false;
91
+ } else {
92
+ builder.append(",");
93
+ }
94
+ builder.append("\"").append(entry.getKey()).append("\":");
95
+ appendValue(builder, entry.getValue());
96
+ }
97
+ builder.append("}");
98
+ } catch (ClassCastException e) {
99
+ Log.e(TAG, "Error parsing stats value " + value);
100
+ }
77
101
  } else if (value instanceof String) {
78
102
  builder.append("\"").append(value).append("\"");
79
103
  } else {
@@ -98,6 +98,7 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
98
98
 
99
99
  PeerConnectionFactory.initialize(
100
100
  PeerConnectionFactory.InitializationOptions.builder(reactContext)
101
+ .setFieldTrials("WebRTC-DataChannel-Dcsctp/Enabled/")
101
102
  .setNativeLibraryLoader(new LibraryLoader())
102
103
  .setInjectableLogger(injectableLogger, loggingSeverity)
103
104
  .createInitializationOptions());
@@ -152,6 +152,7 @@ const NSUInteger kMaxReadLength = 10 * 1024;
152
152
 
153
153
  - (void)stopCapture {
154
154
  [self.connection close];
155
+ self.connection = nil;
155
156
  }
156
157
 
157
158
  // MARK: Private Methods
@@ -402,34 +402,53 @@ RCT_EXPORT_METHOD(peerConnectionRestartIce:(nonnull NSNumber *)objectID)
402
402
  [s appendString:key];
403
403
  [s appendString:@"\":"];
404
404
  NSObject *statisticsValue = [statistics.values objectForKey:key];
405
- if ([statisticsValue isKindOfClass:[NSArray class]]) {
406
- [s appendString:@"["];
407
- BOOL firstValue = YES;
408
- for (NSObject *value in (NSArray *)statisticsValue) {
409
- if(firstValue) {
405
+ [self appendValue:statisticsValue toString:s];
406
+ }
407
+
408
+ [s appendString:@"}]"];
409
+ }
410
+
411
+ [s appendString:@"]"];
412
+
413
+ return s;
414
+ }
415
+
416
+ - (void)appendValue:(NSObject *)statisticsValue toString:(NSMutableString *)s {
417
+ if ([statisticsValue isKindOfClass:[NSArray class]]) {
418
+ [s appendString:@"["];
419
+ BOOL firstValue = YES;
420
+ for (NSObject *element in (NSArray *)statisticsValue) {
421
+ if(firstValue) {
410
422
  firstValue = NO;
411
- } else {
423
+ } else {
412
424
  [s appendString:@","];
413
- }
414
-
415
- [s appendString:@"\""];
416
- [s appendString:[NSString stringWithFormat:@"%@", value]];
417
- [s appendString:@"\""];
418
425
  }
419
- [s appendString:@"]"];
420
- } else {
426
+
427
+ [s appendString:@"\""];
428
+ [s appendString:[NSString stringWithFormat:@"%@", element]];
429
+ [s appendString:@"\""];
430
+ }
431
+
432
+ [s appendString:@"]"];
433
+ } else if ([statisticsValue isKindOfClass:[NSDictionary class]]) {
434
+ NSError *error;
435
+ NSData *jsonData = [NSJSONSerialization dataWithJSONObject:statisticsValue
436
+ options:0
437
+ error:&error];
438
+
439
+ if (!jsonData) {
421
440
  [s appendString:@"\""];
422
441
  [s appendString:[NSString stringWithFormat:@"%@", statisticsValue]];
423
442
  [s appendString:@"\""];
443
+ } else {
444
+ NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
445
+ [s appendString:jsonString];
424
446
  }
447
+ } else {
448
+ [s appendString:@"\""];
449
+ [s appendString:[NSString stringWithFormat:@"%@", statisticsValue]];
450
+ [s appendString:@"\""];
425
451
  }
426
-
427
- [s appendString:@"}]"];
428
- }
429
-
430
- [s appendString:@"]"];
431
-
432
- return s;
433
452
  }
434
453
 
435
454
  - (NSString *)stringForPeerConnectionState:(RTCPeerConnectionState)state {
@@ -15,6 +15,7 @@
15
15
 
16
16
  #import <WebRTC/RTCDefaultVideoDecoderFactory.h>
17
17
  #import <WebRTC/RTCDefaultVideoEncoderFactory.h>
18
+ #import <WebRTC/RTCFieldTrials.h>
18
19
 
19
20
  #import "WebRTCModule.h"
20
21
  #import "WebRTCModule+RTCPeerConnection.h"
@@ -56,6 +57,9 @@
56
57
  {
57
58
  self = [super init];
58
59
  if (self) {
60
+ NSDictionary *fieldTrials = @{@"WebRTC-DataChannel-Dcsctp": @"Enabled"};
61
+ RTCInitFieldTrialDictionary(fieldTrials);
62
+
59
63
  if (encoderFactory == nil) {
60
64
  encoderFactory = [[RTCDefaultVideoEncoderFactory alloc] init];
61
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-webrtc",
3
- "version": "1.94.0",
3
+ "version": "1.98.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/react-native-webrtc/react-native-webrtc.git"
@@ -20,8 +20,7 @@
20
20
  "dependencies": {
21
21
  "base64-js": "1.5.1",
22
22
  "event-target-shim": "6.0.2",
23
- "tar": "6.1.11",
24
- "uuid": "3.4.0"
23
+ "tar": "6.1.11"
25
24
  },
26
25
  "peerDependencies": {
27
26
  "react-native": ">=0.60.0"
@@ -42,8 +41,8 @@
42
41
  "**/*": "prettier --write --ignore-unknown"
43
42
  },
44
43
  "webrtc-builds": {
45
- "android": "https://github.com/jitsi/webrtc/releases/download/v94.0.0/android-webrtc.tgz",
46
- "ios": "https://github.com/jitsi/webrtc/releases/download/v94.0.0/WebRTC.xcframework.tgz",
47
- "ios-bitcode": "https://github.com/jitsi/webrtc/releases/download/v94.0.0/WebRTC.xcframework-bitcode.tgz"
44
+ "android": "https://github.com/jitsi/webrtc/releases/download/v98.0.0/android-webrtc.tgz",
45
+ "ios": "https://github.com/jitsi/webrtc/releases/download/v98.0.0/WebRTC.xcframework.tgz",
46
+ "ios-bitcode": "https://github.com/jitsi/webrtc/releases/download/v98.0.0/WebRTC.xcframework-bitcode.tgz"
48
47
  }
49
48
  }
@@ -1,7 +1,7 @@
1
1
 
2
2
  import { NativeModules } from 'react-native';
3
3
  import { defineCustomEventTarget } from 'event-target-shim';
4
- import uuid from 'uuid';
4
+ import { uniqueID } from './RTCUtil';
5
5
 
6
6
  import MediaStreamTrack from './MediaStreamTrack';
7
7
 
@@ -40,7 +40,7 @@ export default class MediaStream extends defineCustomEventTarget(...MEDIA_STREAM
40
40
  super();
41
41
 
42
42
  // Assigm a UUID to start with. It may get overridden for remote streams.
43
- this.id = uuid.v4();
43
+ this.id = uniqueID();
44
44
  // Local MediaStreams are created by WebRTCModule to have their id and
45
45
  // reactTag equal because WebRTCModule follows the respective standard's
46
46
  // recommendation for id generation i.e. uses UUID which is unique enough
package/src/RTCUtil.js CHANGED
@@ -112,6 +112,27 @@ function normalizeMediaConstraints(constraints, mediaType) {
112
112
  }
113
113
  }
114
114
 
115
+ /**
116
+ * Utility for creating short random strings from float point values.
117
+ * We take 4 characters from the end after converting to a string.
118
+ * Conversion to string gives us some letters as we don't want just numbers.
119
+ * Should be suitable to pass for enough randomness.
120
+ *
121
+ * @return {String} 4 random characters
122
+ */
123
+ function chr4() {
124
+ return Math.random().toString(16).slice(-4);
125
+ }
126
+
127
+ /**
128
+ * Put together a random string in UUIDv4 format {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
129
+ *
130
+ * @return {String} uuidv4
131
+ */
132
+ export function uniqueID() {
133
+ return `${chr4()}${chr4()}-${chr4()}-${chr4()}-${chr4()}-${chr4()}${chr4()}${chr4()}`;
134
+ }
135
+
115
136
  /**
116
137
  * Utility for deep cloning an object. Object.assign() only does a shallow copy.
117
138
  *
@@ -37,12 +37,17 @@ def build_gn_args(platform_args):
37
37
  GN_COMMON_ARGS = [
38
38
  'is_component_build=false',
39
39
  'rtc_libvpx_build_vp9=true',
40
+ 'rtc_build_dcsctp=true',
41
+ 'rtc_build_usrsctp=false',
42
+ 'rtc_enable_protobuf=false',
43
+ 'rtc_include_tests=false',
40
44
  'is_debug=%s',
41
45
  'target_cpu="%s"'
42
46
  ]
43
47
 
44
48
  _GN_APPLE_COMMON = [
45
- 'enable_dsyms=true',
49
+ 'enable_dsyms=false',
50
+ 'rtc_enable_symbol_export=false',
46
51
  'rtc_enable_objc_symbol_export=true',
47
52
  'rtc_include_tests=false'
48
53
  ]
@@ -51,15 +56,14 @@ _GN_IOS_ARGS = [
51
56
  'enable_ios_bitcode=true',
52
57
  'ios_deployment_target="12.0"',
53
58
  'ios_enable_code_signing=false',
59
+ 'use_lld=false',
54
60
  'target_os="ios"',
55
- 'use_xcode_clang=true',
56
61
  'target_environment="%s"'
57
62
  ]
58
63
  GN_IOS_ARGS = build_gn_args(_GN_APPLE_COMMON + _GN_IOS_ARGS)
59
64
 
60
65
  _GN_MACOS_ARGS = [
61
- 'target_os="mac"',
62
- 'use_xcode_clang=false'
66
+ 'target_os="mac"'
63
67
  ]
64
68
  GN_MACOS_ARGS = build_gn_args(_GN_APPLE_COMMON + _GN_MACOS_ARGS)
65
69