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
@@ -3,25 +3,23 @@
3
3
 
4
4
  #import <React/RCTLog.h>
5
5
 
6
-
7
6
  @interface VideoCaptureController ()
8
7
 
9
- @property (nonatomic, strong) RTCCameraVideoCapturer *capturer;
10
- @property (nonatomic, strong) AVCaptureDeviceFormat *selectedFormat;
11
- @property (nonatomic, strong) AVCaptureDevice *device;
12
- @property (nonatomic, copy) NSString *deviceId;
13
- @property (nonatomic, assign) BOOL running;
14
- @property (nonatomic, assign) BOOL usingFrontCamera;
15
- @property (nonatomic, assign) int width;
16
- @property (nonatomic, assign) int height;
17
- @property (nonatomic, assign) int frameRate;
8
+ @property(nonatomic, strong) RTCCameraVideoCapturer *capturer;
9
+ @property(nonatomic, strong) AVCaptureDeviceFormat *selectedFormat;
10
+ @property(nonatomic, strong) AVCaptureDevice *device;
11
+ @property(nonatomic, copy) NSString *deviceId;
12
+ @property(nonatomic, assign) BOOL running;
13
+ @property(nonatomic, assign) BOOL usingFrontCamera;
14
+ @property(nonatomic, assign) int width;
15
+ @property(nonatomic, assign) int height;
16
+ @property(nonatomic, assign) int frameRate;
18
17
 
19
18
  @end
20
19
 
21
20
  @implementation VideoCaptureController
22
21
 
23
- - (instancetype)initWithCapturer:(RTCCameraVideoCapturer *)capturer
24
- andConstraints:(NSDictionary *)constraints {
22
+ - (instancetype)initWithCapturer:(RTCCameraVideoCapturer *)capturer andConstraints:(NSDictionary *)constraints {
25
23
  self = [super init];
26
24
  if (self) {
27
25
  self.capturer = capturer;
@@ -65,10 +63,8 @@
65
63
  self.device = [AVCaptureDevice deviceWithUniqueID:self.deviceId];
66
64
  }
67
65
  if (!self.device) {
68
- AVCaptureDevicePosition position
69
- = self.usingFrontCamera
70
- ? AVCaptureDevicePositionFront
71
- : AVCaptureDevicePositionBack;
66
+ AVCaptureDevicePosition position =
67
+ self.usingFrontCamera ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack;
72
68
  self.device = [self findDeviceForPosition:position];
73
69
  }
74
70
 
@@ -77,34 +73,36 @@
77
73
 
78
74
  return;
79
75
  }
80
-
81
- AVCaptureDeviceFormat *format
82
- = [self selectFormatForDevice:self.device
83
- withTargetWidth:self.width
84
- withTargetHeight:self.height];
76
+
77
+ AVCaptureDeviceFormat *format = [self selectFormatForDevice:self.device
78
+ withTargetWidth:self.width
79
+ withTargetHeight:self.height];
85
80
  if (!format) {
86
81
  RCTLogWarn(@"[VideoCaptureController] No valid formats for device %@", self.device);
87
82
 
88
83
  return;
89
84
  }
90
-
85
+
91
86
  self.selectedFormat = format;
92
87
 
93
88
  RCTLog(@"[VideoCaptureController] Capture will start");
94
89
 
95
90
  // Starting the capture happens on another thread. Wait for it.
96
91
  dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
97
-
92
+
98
93
  __weak VideoCaptureController *weakSelf = self;
99
- [self.capturer startCaptureWithDevice:self.device format:format fps:self.frameRate completionHandler:^(NSError *err) {
100
- if (err) {
101
- RCTLogError(@"[VideoCaptureController] Error starting capture: %@", err);
102
- } else {
103
- RCTLog(@"[VideoCaptureController] Capture started");
104
- weakSelf.running = YES;
105
- }
106
- dispatch_semaphore_signal(semaphore);
107
- }];
94
+ [self.capturer startCaptureWithDevice:self.device
95
+ format:format
96
+ fps:self.frameRate
97
+ completionHandler:^(NSError *err) {
98
+ if (err) {
99
+ RCTLogError(@"[VideoCaptureController] Error starting capture: %@", err);
100
+ } else {
101
+ RCTLog(@"[VideoCaptureController] Capture started");
102
+ weakSelf.running = YES;
103
+ }
104
+ dispatch_semaphore_signal(semaphore);
105
+ }];
108
106
 
109
107
  dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
110
108
  }
@@ -122,7 +120,7 @@
122
120
  RCTLog(@"[VideoCaptureController] Capture stopped");
123
121
  weakSelf.running = NO;
124
122
  weakSelf.device = nil;
125
-
123
+
126
124
  dispatch_semaphore_signal(semaphore);
127
125
  }];
128
126
 
@@ -139,17 +137,24 @@
139
137
 
140
138
  #pragma mark NSKeyValueObserving
141
139
 
142
- - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
140
+ - (void)observeValueForKeyPath:(NSString *)keyPath
141
+ ofObject:(id)object
142
+ change:(NSDictionary<NSKeyValueChangeKey, id> *)change
143
+ context:(void *)context {
143
144
  if (@available(iOS 11.1, *)) {
144
145
  if ([object isKindOfClass:[AVCaptureDevice class]] && [keyPath isEqualToString:@"systemPressureState"]) {
145
146
  AVCaptureDevice *device = (AVCaptureDevice *)object;
146
- AVCaptureSystemPressureLevel pressureLevel = ((AVCaptureSystemPressureState *)change[NSKeyValueChangeNewKey]).level;
147
- if (pressureLevel == AVCaptureSystemPressureLevelSerious || pressureLevel == AVCaptureSystemPressureLevelCritical) {
148
- RCTLogWarn(@"[VideoCaptureController] Reached elevated system pressure level: %@. Throttling frame rate.", pressureLevel);
147
+ AVCaptureSystemPressureLevel pressureLevel =
148
+ ((AVCaptureSystemPressureState *)change[NSKeyValueChangeNewKey]).level;
149
+ if (pressureLevel == AVCaptureSystemPressureLevelSerious ||
150
+ pressureLevel == AVCaptureSystemPressureLevelCritical) {
151
+ RCTLogWarn(
152
+ @"[VideoCaptureController] Reached elevated system pressure level: %@. Throttling frame rate.",
153
+ pressureLevel);
149
154
  [self throttleFrameRateForDevice:device];
150
- }
151
- else if (pressureLevel == AVCaptureSystemPressureLevelNominal) {
152
- RCTLogWarn(@"[VideoCaptureController] Restored normal system pressure level. Resetting frame rate to default.");
155
+ } else if (pressureLevel == AVCaptureSystemPressureLevelNominal) {
156
+ RCTLogWarn(@"[VideoCaptureController] Restored normal system pressure level. Resetting frame rate to "
157
+ @"default.");
153
158
  [self resetFrameRateForDevice:device];
154
159
  }
155
160
  }
@@ -158,10 +163,7 @@
158
163
 
159
164
  - (void)registerSystemPressureStateObserverForDevice:(AVCaptureDevice *)device {
160
165
  if (@available(iOS 11.1, *)) {
161
- [device addObserver:self
162
- forKeyPath:@"systemPressureState"
163
- options:NSKeyValueObservingOptionNew
164
- context:nil];
166
+ [device addObserver:self forKeyPath:@"systemPressureState" options:NSKeyValueObservingOptionNew context:nil];
165
167
  }
166
168
  }
167
169
 
@@ -180,7 +182,7 @@
180
182
  if (device) {
181
183
  [self registerSystemPressureStateObserverForDevice:device];
182
184
  }
183
-
185
+
184
186
  _device = device;
185
187
  }
186
188
 
@@ -198,8 +200,7 @@
198
200
  - (AVCaptureDeviceFormat *)selectFormatForDevice:(AVCaptureDevice *)device
199
201
  withTargetWidth:(int)targetWidth
200
202
  withTargetHeight:(int)targetHeight {
201
- NSArray<AVCaptureDeviceFormat *> *formats =
202
- [RTCCameraVideoCapturer supportedFormatsForDevice:device];
203
+ NSArray<AVCaptureDeviceFormat *> *formats = [RTCCameraVideoCapturer supportedFormatsForDevice:device];
203
204
  AVCaptureDeviceFormat *selectedFormat = nil;
204
205
  int currentDiff = INT_MAX;
205
206
 
@@ -220,31 +221,31 @@
220
221
 
221
222
  - (void)throttleFrameRateForDevice:(AVCaptureDevice *)device {
222
223
  NSError *error = nil;
223
-
224
+
224
225
  [device lockForConfiguration:&error];
225
226
  if (error) {
226
227
  RCTLog(@"[VideoCaptureController] Could not lock device for configuration: %@", error);
227
228
  return;
228
229
  }
229
-
230
+
230
231
  device.activeVideoMinFrameDuration = CMTimeMake(1, 20);
231
232
  device.activeVideoMaxFrameDuration = CMTimeMake(1, 15);
232
-
233
+
233
234
  [device unlockForConfiguration];
234
235
  }
235
236
 
236
237
  - (void)resetFrameRateForDevice:(AVCaptureDevice *)device {
237
238
  NSError *error = nil;
238
-
239
+
239
240
  [device lockForConfiguration:&error];
240
241
  if (error) {
241
242
  RCTLog(@"[VideoCaptureController] Could not lock device for configuration: %@", error);
242
243
  return;
243
244
  }
244
-
245
+
245
246
  device.activeVideoMinFrameDuration = kCMTimeInvalid;
246
247
  device.activeVideoMaxFrameDuration = kCMTimeInvalid;
247
-
248
+
248
249
  [device unlockForConfiguration];
249
250
  }
250
251
 
@@ -3,13 +3,13 @@
3
3
 
4
4
  #import "WebRTCModule.h"
5
5
 
6
- static NSString *const PERMISSION_DENIED = @"denied";
6
+ static NSString *const PERMISSION_DENIED = @"denied";
7
7
  static NSString *const PERMISSION_GRANTED = @"granted";
8
- static NSString *const PERMISSION_PROMPT = @"prompt";
8
+ static NSString *const PERMISSION_PROMPT = @"prompt";
9
9
 
10
10
  @implementation WebRTCModule (Permissions)
11
11
 
12
- - (AVMediaType)avMediaType:(NSString* )mediaType {
12
+ - (AVMediaType)avMediaType:(NSString *)mediaType {
13
13
  if ([mediaType isEqualToString:@"microphone"]) {
14
14
  return AVMediaTypeAudio;
15
15
  } else if ([mediaType isEqualToString:@"camera"]) {
@@ -19,9 +19,10 @@ static NSString *const PERMISSION_PROMPT = @"prompt";
19
19
  }
20
20
  }
21
21
 
22
- RCT_EXPORT_METHOD(checkPermission:(NSString *)mediaType
23
- resolver:(RCTPromiseResolveBlock)resolve
24
- rejecter:(RCTPromiseRejectBlock)reject) {
22
+ RCT_EXPORT_METHOD(checkPermission
23
+ : (NSString *)mediaType resolver
24
+ : (RCTPromiseResolveBlock)resolve rejecter
25
+ : (RCTPromiseRejectBlock)reject) {
25
26
  AVMediaType mediaType_ = [self avMediaType:mediaType];
26
27
 
27
28
  if (mediaType_ == nil) {
@@ -29,8 +30,7 @@ RCT_EXPORT_METHOD(checkPermission:(NSString *)mediaType
29
30
  return;
30
31
  }
31
32
 
32
- AVAuthorizationStatus status
33
- = [AVCaptureDevice authorizationStatusForMediaType:mediaType_];
33
+ AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:mediaType_];
34
34
  switch (status) {
35
35
  case AVAuthorizationStatusAuthorized:
36
36
  resolve(PERMISSION_GRANTED);
@@ -46,9 +46,10 @@ RCT_EXPORT_METHOD(checkPermission:(NSString *)mediaType
46
46
  }
47
47
  }
48
48
 
49
- RCT_EXPORT_METHOD(requestPermission:(NSString *)mediaType
50
- resolver:(RCTPromiseResolveBlock)resolve
51
- rejecter:(RCTPromiseRejectBlock)reject) {
49
+ RCT_EXPORT_METHOD(requestPermission
50
+ : (NSString *)mediaType resolver
51
+ : (RCTPromiseResolveBlock)resolve rejecter
52
+ : (RCTPromiseRejectBlock)reject) {
52
53
  AVMediaType mediaType_ = [self avMediaType:mediaType];
53
54
 
54
55
  if (mediaType_ == nil) {
@@ -58,8 +59,8 @@ RCT_EXPORT_METHOD(requestPermission:(NSString *)mediaType
58
59
 
59
60
  [AVCaptureDevice requestAccessForMediaType:mediaType_
60
61
  completionHandler:^(BOOL granted) {
61
- resolve(@(granted));
62
- }];
62
+ resolve(@(granted));
63
+ }];
63
64
  }
64
65
 
65
66
  @end
@@ -1,13 +1,13 @@
1
- #import "WebRTCModule.h"
2
1
  #import "DataChannelWrapper.h"
2
+ #import "WebRTCModule.h"
3
3
 
4
4
  @interface RTCDataChannel (React)
5
5
 
6
- @property (nonatomic, strong) NSNumber *peerConnectionId;
6
+ @property(nonatomic, strong) NSNumber *peerConnectionId;
7
7
 
8
8
  @end
9
9
 
10
- @interface WebRTCModule (RTCDataChannel) <DataChannelWrapperDelegate>
10
+ @interface WebRTCModule (RTCDataChannel)<DataChannelWrapperDelegate>
11
11
 
12
12
  - (NSString *)stringForDataChannelState:(RTCDataChannelState)state;
13
13
 
@@ -4,10 +4,9 @@
4
4
  #import <React/RCTBridgeModule.h>
5
5
  #import <React/RCTEventDispatcher.h>
6
6
 
7
+ #import <WebRTC/RTCDataChannelConfiguration.h>
7
8
  #import "WebRTCModule+RTCDataChannel.h"
8
9
  #import "WebRTCModule+RTCPeerConnection.h"
9
- #import <WebRTC/RTCDataChannelConfiguration.h>
10
-
11
10
 
12
11
  @implementation WebRTCModule (RTCDataChannel)
13
12
 
@@ -15,15 +14,15 @@
15
14
  * Thuis methos is implemented synchronously since we need to create the DataChannel on the spot
16
15
  * and where is no good way to report an error at creation time.
17
16
  */
18
- RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(createDataChannel:(nonnull NSNumber *)peerConnectionId
19
- label:(NSString *)label
20
- config:(RTCDataChannelConfiguration *)config)
21
- {
17
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(createDataChannel
18
+ : (nonnull NSNumber *)peerConnectionId label
19
+ : (NSString *)label config
20
+ : (RTCDataChannelConfiguration *)config) {
22
21
  __block id channelInfo;
23
22
 
24
23
  dispatch_sync(self.workerQueue, ^{
25
24
  RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];
26
-
25
+
27
26
  if (peerConnection == nil) {
28
27
  RCTLogWarn(@"PeerConnection %@ not found", peerConnectionId);
29
28
  channelInfo = nil;
@@ -31,12 +30,12 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(createDataChannel:(nonnull NSNumber *)pee
31
30
  }
32
31
 
33
32
  RTCDataChannel *dataChannel = [peerConnection dataChannelForLabel:label configuration:config];
34
-
33
+
35
34
  if (dataChannel == nil) {
36
35
  channelInfo = nil;
37
36
  return;
38
37
  }
39
-
38
+
40
39
  NSString *reactTag = [[NSUUID UUID] UUIDString];
41
40
  DataChannelWrapper *dcw = [[DataChannelWrapper alloc] initWithChannel:dataChannel reactTag:reactTag];
42
41
  dcw.pcId = peerConnectionId;
@@ -44,116 +43,122 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(createDataChannel:(nonnull NSNumber *)pee
44
43
  dcw.delegate = self;
45
44
 
46
45
  channelInfo = @{
47
- @"peerConnectionId": peerConnectionId,
48
- @"reactTag": reactTag,
49
- @"label": dataChannel.label,
50
- @"id": @(dataChannel.channelId),
51
- @"ordered": @(dataChannel.isOrdered),
52
- @"maxPacketLifeTime": @(dataChannel.maxPacketLifeTime),
53
- @"maxRetransmits": @(dataChannel.maxRetransmits),
54
- @"protocol": dataChannel.protocol,
55
- @"negotiated": @(dataChannel.isNegotiated),
56
- @"readyState": [self stringForDataChannelState:dataChannel.readyState]
46
+ @"peerConnectionId" : peerConnectionId,
47
+ @"reactTag" : reactTag,
48
+ @"label" : dataChannel.label,
49
+ @"id" : @(dataChannel.channelId),
50
+ @"ordered" : @(dataChannel.isOrdered),
51
+ @"maxPacketLifeTime" : @(dataChannel.maxPacketLifeTime),
52
+ @"maxRetransmits" : @(dataChannel.maxRetransmits),
53
+ @"protocol" : dataChannel.protocol,
54
+ @"negotiated" : @(dataChannel.isNegotiated),
55
+ @"readyState" : [self stringForDataChannelState:dataChannel.readyState]
57
56
  };
58
57
  });
59
58
 
60
59
  return channelInfo;
61
60
  }
62
61
 
63
- RCT_EXPORT_METHOD(dataChannelClose:(nonnull NSNumber *)peerConnectionId
64
- reactTag:(nonnull NSString *)tag
65
- {
66
- RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];
67
- DataChannelWrapper *dcw = peerConnection.dataChannels[tag];
68
- if (dcw) {
69
- [dcw.channel close];
70
- }
71
- })
72
-
73
- RCT_EXPORT_METHOD(dataChannelDispose:(nonnull NSNumber *)peerConnectionId
74
- reactTag:(nonnull NSString *)tag
75
- {
76
- RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];
77
- DataChannelWrapper *dcw = peerConnection.dataChannels[tag];
78
- if (dcw) {
79
- dcw.delegate = nil;
80
- [peerConnection.dataChannels removeObjectForKey:tag];
62
+ RCT_EXPORT_METHOD(dataChannelClose
63
+ : (nonnull NSNumber *)peerConnectionId reactTag
64
+ : (nonnull NSString *)tag {
65
+ RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];
66
+ DataChannelWrapper *dcw = peerConnection.dataChannels[tag];
67
+ if (dcw) {
68
+ [dcw.channel close];
69
+ }
70
+ })
71
+
72
+ RCT_EXPORT_METHOD(dataChannelDispose
73
+ : (nonnull NSNumber *)peerConnectionId reactTag
74
+ : (nonnull NSString *)tag {
75
+ RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];
76
+ DataChannelWrapper *dcw = peerConnection.dataChannels[tag];
77
+ if (dcw) {
78
+ dcw.delegate = nil;
79
+ [peerConnection.dataChannels removeObjectForKey:tag];
80
+ }
81
+ })
82
+
83
+ RCT_EXPORT_METHOD(dataChannelSend
84
+ : (nonnull NSNumber *)peerConnectionId reactTag
85
+ : (nonnull NSString *)tag data
86
+ : (NSString *)data type
87
+ : (NSString *)type {
88
+ RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];
89
+ DataChannelWrapper *dcw = peerConnection.dataChannels[tag];
90
+ if (dcw) {
91
+ BOOL isBinary = [type isEqualToString:@"binary"];
92
+ NSData *bytes = isBinary ? [[NSData alloc] initWithBase64EncodedString:data options:0]
93
+ : [data dataUsingEncoding:NSUTF8StringEncoding];
94
+ RTCDataBuffer *buffer = [[RTCDataBuffer alloc] initWithData:bytes isBinary:isBinary];
95
+ [dcw.channel sendData:buffer];
96
+ }
97
+ })
98
+
99
+ - (NSString *)stringForDataChannelState:(RTCDataChannelState)state {
100
+ switch (state) {
101
+ case RTCDataChannelStateConnecting:
102
+ return @"connecting";
103
+ case RTCDataChannelStateOpen:
104
+ return @"open";
105
+ case RTCDataChannelStateClosing:
106
+ return @"closing";
107
+ case RTCDataChannelStateClosed:
108
+ return @"closed";
81
109
  }
82
- })
83
-
84
- RCT_EXPORT_METHOD(dataChannelSend:(nonnull NSNumber *)peerConnectionId
85
- reactTag:(nonnull NSString *)tag
86
- data:(NSString *)data
87
- type:(NSString *)type
88
- {
89
- RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];
90
- DataChannelWrapper *dcw = peerConnection.dataChannels[tag];
91
- if (dcw) {
92
- BOOL isBinary = [type isEqualToString:@"binary"];
93
- NSData *bytes = isBinary ? [[NSData alloc] initWithBase64EncodedString:data options:0] : [data dataUsingEncoding:NSUTF8StringEncoding];
94
- RTCDataBuffer *buffer = [[RTCDataBuffer alloc] initWithData:bytes isBinary:isBinary];
95
- [dcw.channel sendData:buffer];
96
- }
97
- })
98
-
99
- - (NSString *)stringForDataChannelState:(RTCDataChannelState)state
100
- {
101
- switch (state) {
102
- case RTCDataChannelStateConnecting: return @"connecting";
103
- case RTCDataChannelStateOpen: return @"open";
104
- case RTCDataChannelStateClosing: return @"closing";
105
- case RTCDataChannelStateClosed: return @"closed";
106
- }
107
- return nil;
110
+ return nil;
108
111
  }
109
112
 
110
113
  #pragma mark - DataChannelWrapperDelegate methods
111
114
 
112
115
  // Called when the data channel state has changed.
113
- - (void)dataChannelDidChangeState:(DataChannelWrapper *)dcw
114
- {
116
+ - (void)dataChannelDidChangeState:(DataChannelWrapper *)dcw {
115
117
  RTCDataChannel *channel = dcw.channel;
116
- NSDictionary *event = @{@"reactTag": dcw.reactTag,
117
- @"peerConnectionId": dcw.pcId,
118
- @"id": @(channel.channelId),
119
- @"state": [self stringForDataChannelState:channel.readyState]};
118
+ NSDictionary *event = @{
119
+ @"reactTag" : dcw.reactTag,
120
+ @"peerConnectionId" : dcw.pcId,
121
+ @"id" : @(channel.channelId),
122
+ @"state" : [self stringForDataChannelState:channel.readyState]
123
+ };
120
124
  [self sendEventWithName:kEventDataChannelStateChanged body:event];
121
125
  }
122
126
 
123
127
  // Called when a data buffer was successfully received.
124
- - (void)dataChannel:(DataChannelWrapper *)dcw didReceiveMessageWithBuffer:(RTCDataBuffer *)buffer
125
- {
126
- NSString *type;
127
- NSString *data;
128
- if (buffer.isBinary) {
129
- type = @"binary";
130
- data = [buffer.data base64EncodedStringWithOptions:0];
131
- } else {
132
- type = @"text";
133
- // XXX NSData has a length property which means that, when it represents
134
- // text, the value of its bytes property does not have to be terminated by
135
- // null. In such a case, NSString's stringFromUTF8String may fail and return
136
- // nil (which would crash the process when inserting data into NSDictionary
137
- // without the nil protection implemented below).
138
- data = [[NSString alloc] initWithData:buffer.data
139
- encoding:NSUTF8StringEncoding];
140
- }
141
- NSDictionary *event = @{@"reactTag": dcw.reactTag,
142
- @"peerConnectionId": dcw.pcId,
143
- @"type": type,
144
- // XXX NSDictionary will crash the process upon
145
- // attempting to insert nil. Such behavior is
146
- // unacceptable given that protection in such a
147
- // scenario is extremely simple.
148
- @"data": (data ? data : [NSNull null])};
149
- [self sendEventWithName:kEventDataChannelReceiveMessage body:event];
128
+ - (void)dataChannel:(DataChannelWrapper *)dcw didReceiveMessageWithBuffer:(RTCDataBuffer *)buffer {
129
+ NSString *type;
130
+ NSString *data;
131
+ if (buffer.isBinary) {
132
+ type = @"binary";
133
+ data = [buffer.data base64EncodedStringWithOptions:0];
134
+ } else {
135
+ type = @"text";
136
+ // XXX NSData has a length property which means that, when it represents
137
+ // text, the value of its bytes property does not have to be terminated by
138
+ // null. In such a case, NSString's stringFromUTF8String may fail and return
139
+ // nil (which would crash the process when inserting data into NSDictionary
140
+ // without the nil protection implemented below).
141
+ data = [[NSString alloc] initWithData:buffer.data encoding:NSUTF8StringEncoding];
142
+ }
143
+ NSDictionary *event = @{
144
+ @"reactTag" : dcw.reactTag,
145
+ @"peerConnectionId" : dcw.pcId,
146
+ @"type" : type,
147
+ // XXX NSDictionary will crash the process upon
148
+ // attempting to insert nil. Such behavior is
149
+ // unacceptable given that protection in such a
150
+ // scenario is extremely simple.
151
+ @"data" : (data ? data : [NSNull null])
152
+ };
153
+ [self sendEventWithName:kEventDataChannelReceiveMessage body:event];
150
154
  }
151
155
 
152
- - (void)dataChannel:(DataChannelWrapper *)dcw didChangeBufferedAmount:(uint64_t)amount
153
- {
154
- NSDictionary *event = @{@"reactTag": dcw.reactTag,
155
- @"peerConnectionId": dcw.pcId,
156
- @"bufferedAmount": [NSNumber numberWithUnsignedLongLong:amount]};
156
+ - (void)dataChannel:(DataChannelWrapper *)dcw didChangeBufferedAmount:(uint64_t)amount {
157
+ NSDictionary *event = @{
158
+ @"reactTag" : dcw.reactTag,
159
+ @"peerConnectionId" : dcw.pcId,
160
+ @"bufferedAmount" : [NSNumber numberWithUnsignedLongLong:amount]
161
+ };
157
162
  [self sendEventWithName:kEventDataChannelDidChangeBufferedAmount body:event];
158
163
  }
159
164
 
@@ -1,7 +1,8 @@
1
- #import "WebRTCModule.h"
2
1
  #import "CaptureController.h"
2
+ #import "WebRTCModule.h"
3
3
 
4
4
  @interface WebRTCModule (RTCMediaStream)
5
- - (RTCVideoTrack *)createVideoTrackWithCaptureController:(CaptureController * (^)(RTCVideoSource *)) captureControllerCreator;
5
+ - (RTCVideoTrack *)createVideoTrackWithCaptureController:
6
+ (CaptureController * (^)(RTCVideoSource *))captureControllerCreator;
6
7
  - (NSArray *)createMediaStream:(NSArray<RTCMediaStreamTrack *> *)tracks;
7
8
  @end