react-native-webrtc 124.0.5 → 124.0.7

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 (75) hide show
  1. package/.nvmrc +1 -0
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +2 -1
  4. package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +7 -9
  5. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +39 -19
  6. package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionNotification.java +11 -19
  7. package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionService.java +0 -2
  8. package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +4 -2
  9. package/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +25 -0
  10. package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +1 -4
  11. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +16 -12
  12. package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +37 -0
  13. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +15 -9
  14. package/android/src/main/java/org/webrtc/Camera1Helper.java +0 -1
  15. package/android/src/main/java/org/webrtc/Camera2Helper.java +4 -3
  16. package/ios/RCTWebRTC/CaptureController.h +1 -1
  17. package/ios/RCTWebRTC/CaptureController.m +6 -7
  18. package/ios/RCTWebRTC/I420Converter.h +3 -2
  19. package/ios/RCTWebRTC/I420Converter.m +55 -47
  20. package/ios/RCTWebRTC/PIPController.h +2 -2
  21. package/ios/RCTWebRTC/PIPController.m +29 -37
  22. package/ios/RCTWebRTC/RTCVideoViewManager.m +38 -17
  23. package/ios/RCTWebRTC/SampleBufferVideoCallView.h +2 -2
  24. package/ios/RCTWebRTC/SampleBufferVideoCallView.m +40 -42
  25. package/ios/RCTWebRTC/ScreenCaptureController.m +1 -5
  26. package/ios/RCTWebRTC/VideoCaptureController.h +1 -0
  27. package/ios/RCTWebRTC/VideoCaptureController.m +6 -7
  28. package/ios/RCTWebRTC/WebRTCModule+Permissions.m +4 -8
  29. package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +31 -40
  30. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +5 -0
  31. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +68 -22
  32. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +26 -55
  33. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +11 -28
  34. package/ios/RCTWebRTC/videoEffects/ProcessorProvider.h +9 -0
  35. package/ios/RCTWebRTC/videoEffects/ProcessorProvider.m +23 -0
  36. package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.h +13 -0
  37. package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.m +23 -0
  38. package/ios/RCTWebRTC/videoEffects/VideoFrameProcessor.h +8 -0
  39. package/lib/commonjs/MediaStreamTrack.js +5 -2
  40. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  41. package/lib/commonjs/Permissions.js +3 -3
  42. package/lib/commonjs/Permissions.js.map +1 -1
  43. package/lib/commonjs/RTCPIPView.js +3 -7
  44. package/lib/commonjs/RTCPIPView.js.map +1 -1
  45. package/lib/commonjs/RTCPeerConnection.js +2 -4
  46. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  47. package/lib/commonjs/RTCUtil.js +2 -3
  48. package/lib/commonjs/RTCUtil.js.map +1 -1
  49. package/lib/commonjs/RTCView.js.map +1 -1
  50. package/lib/module/MediaStreamTrack.js +5 -2
  51. package/lib/module/MediaStreamTrack.js.map +1 -1
  52. package/lib/module/Permissions.js +3 -3
  53. package/lib/module/Permissions.js.map +1 -1
  54. package/lib/module/RTCPIPView.js +3 -7
  55. package/lib/module/RTCPIPView.js.map +1 -1
  56. package/lib/module/RTCPeerConnection.js +2 -4
  57. package/lib/module/RTCPeerConnection.js.map +1 -1
  58. package/lib/module/RTCUtil.js +2 -3
  59. package/lib/module/RTCUtil.js.map +1 -1
  60. package/lib/module/RTCView.js.map +1 -1
  61. package/lib/typescript/MediaStreamTrack.d.ts +1 -0
  62. package/lib/typescript/Permissions.d.ts +1 -1
  63. package/lib/typescript/RTCPIPView.d.ts +2 -1
  64. package/lib/typescript/RTCPeerConnection.d.ts +2 -1
  65. package/lib/typescript/RTCUtil.d.ts +7 -1
  66. package/lib/typescript/RTCView.d.ts +14 -0
  67. package/package.json +1 -1
  68. package/src/MediaStreamTrack.ts +6 -2
  69. package/src/Permissions.ts +3 -3
  70. package/src/RTCPIPView.tsx +3 -2
  71. package/src/RTCPeerConnection.ts +4 -5
  72. package/src/RTCUtil.ts +10 -3
  73. package/src/RTCView.ts +11 -1
  74. package/tools/release.sh +1 -1
  75. package/tools/build-webrtc.py +0 -344
@@ -2,50 +2,49 @@
2
2
  // I420Converter.m
3
3
  // VideoSampleCaptureRender
4
4
  //
5
- // Adapted from: https://github.com/twilio/video-ios-affectiva/blob/ed2e864324c40ad25e5a06cc2b05298b03caed09/EmoCall/I420Converter.m
5
+ // Adapted from:
6
+ // https://github.com/twilio/video-ios-affectiva/blob/ed2e864324c40ad25e5a06cc2b05298b03caed09/EmoCall/I420Converter.m
6
7
  // Created by Boisy Pitre on 5/21/16.
7
8
  // Copyright © 2016 Twilio. All rights reserved.
8
9
  //
9
10
 
10
11
  #import "I420Converter.h"
11
12
 
12
- @interface I420Converter()
13
+ @interface I420Converter ()
13
14
 
14
- @property (nonatomic, assign) vImage_YpCbCrToARGB *conversionInfo;
15
- @property (nonatomic, assign) CVPixelBufferPoolRef pixelBufferPool;
16
- @property (nonatomic, assign) size_t poolWidth;
17
- @property (nonatomic, assign) size_t poolHeight;
15
+ @property(nonatomic, assign) vImage_YpCbCrToARGB *conversionInfo;
16
+ @property(nonatomic, assign) CVPixelBufferPoolRef pixelBufferPool;
17
+ @property(nonatomic, assign) size_t poolWidth;
18
+ @property(nonatomic, assign) size_t poolHeight;
18
19
  @end
19
20
 
20
21
  @implementation I420Converter
21
22
 
22
- - (vImage_Error)prepareForAccelerateConversion
23
- {
23
+ - (vImage_Error)prepareForAccelerateConversion {
24
24
  // Setup the YpCbCr to ARGB conversion.
25
25
  if (_conversionInfo != NULL) {
26
26
  return kvImageNoError;
27
27
  }
28
-
28
+
29
29
  // I420 uses limited range.
30
- vImage_YpCbCrPixelRange pixelRange = { 16, 128, 235, 240, 255, 0, 255, 0 };
30
+ vImage_YpCbCrPixelRange pixelRange = {16, 128, 235, 240, 255, 0, 255, 0};
31
31
  vImage_YpCbCrToARGB *outInfo = malloc(sizeof(vImage_YpCbCrToARGB));
32
32
  vImageYpCbCrType inType = kvImage420Yp8_Cb8_Cr8;
33
33
  vImageARGBType outType = kvImageARGB8888;
34
-
34
+
35
35
  vImage_Error error = vImageConvert_YpCbCrToARGB_GenerateConversion(kvImage_YpCbCrToARGBMatrix_ITU_R_601_4,
36
36
  &pixelRange,
37
37
  outInfo,
38
38
  inType,
39
39
  outType,
40
40
  kvImagePrintDiagnosticsToConsole);
41
-
41
+
42
42
  _conversionInfo = outInfo;
43
-
43
+
44
44
  return error;
45
45
  }
46
46
 
47
- - (void)unprepareForAccelerateConversion
48
- {
47
+ - (void)unprepareForAccelerateConversion {
49
48
  if (_conversionInfo != NULL) {
50
49
  free(_conversionInfo);
51
50
  _conversionInfo = NULL;
@@ -60,17 +59,18 @@
60
59
  if (_pixelBufferPool != NULL) {
61
60
  CVPixelBufferPoolRelease(_pixelBufferPool);
62
61
  }
63
-
62
+
64
63
  _poolWidth = width;
65
64
  _poolHeight = height;
66
65
  NSDictionary *pixelBufferAttributes = @{
67
- (id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA),
68
- (id)kCVPixelBufferWidthKey: @(width),
69
- (id)kCVPixelBufferHeightKey: @(height),
70
- (id)kCVPixelBufferIOSurfacePropertiesKey: @{}
66
+ (id)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_32BGRA),
67
+ (id)kCVPixelBufferWidthKey : @(width),
68
+ (id)kCVPixelBufferHeightKey : @(height),
69
+ (id)kCVPixelBufferIOSurfacePropertiesKey : @{}
71
70
  };
72
-
73
- CVReturn ret = CVPixelBufferPoolCreate(kCFAllocatorDefault, NULL, (__bridge CFDictionaryRef)pixelBufferAttributes, &_pixelBufferPool);
71
+
72
+ CVReturn ret = CVPixelBufferPoolCreate(
73
+ kCFAllocatorDefault, NULL, (__bridge CFDictionaryRef)pixelBufferAttributes, &_pixelBufferPool);
74
74
 
75
75
  if (ret != kCVReturnSuccess) {
76
76
  NSLog(@"Error creating pixel buffer pool: %d", ret);
@@ -78,73 +78,81 @@
78
78
  }
79
79
  }
80
80
 
81
- - (CVPixelBufferRef)convertI420ToPixelBuffer:(RTCI420Buffer *)buffer
82
- {
81
+ - (CVPixelBufferRef)convertI420ToPixelBuffer:(RTCI420Buffer *)buffer {
83
82
  if (_conversionInfo == nil) {
84
83
  NSLog(@"%@: not prepared", NSStringFromSelector(_cmd));
85
84
  return NULL;
86
85
  }
87
-
86
+
88
87
  if (_pixelBufferPool == NULL || _poolWidth != buffer.width || _poolHeight != buffer.height) {
89
88
  [self createPixelBufferPoolWithWidth:buffer.width height:buffer.height];
90
89
  }
91
-
90
+
92
91
  CVPixelBufferRef pixelBuffer = NULL;
93
92
  CVReturn status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, _pixelBufferPool, &pixelBuffer);
94
-
93
+
95
94
  if (status != kCVReturnSuccess) {
96
95
  return NULL;
97
96
  }
98
-
97
+
99
98
  vImage_Error err = [self convertFrameVImageYUV:buffer toBuffer:pixelBuffer];
100
-
101
- if(err != kvImageNoError) {
99
+
100
+ if (err != kvImageNoError) {
102
101
  NSLog(@"%@: error during conversion: %ld", NSStringFromSelector(_cmd), err);
103
102
  CVPixelBufferRelease(pixelBuffer);
104
103
  return NULL;
105
104
  }
106
-
105
+
107
106
  return pixelBuffer;
108
107
  }
109
108
 
110
- - (vImage_Error)convertFrameVImageYUV:(RTCI420Buffer *)buffer toBuffer:(CVPixelBufferRef)pixelBufferRef
111
- {
109
+ - (vImage_Error)convertFrameVImageYUV:(RTCI420Buffer *)buffer toBuffer:(CVPixelBufferRef)pixelBufferRef {
112
110
  if (pixelBufferRef == NULL) {
113
111
  return kvImageInvalidParameter;
114
112
  }
115
-
113
+
116
114
  // Compute info for I420 source.
117
115
  vImagePixelCount width = buffer.width;
118
116
  vImagePixelCount height = buffer.height;
119
117
  vImagePixelCount subsampledWidth = buffer.chromaWidth;
120
118
  vImagePixelCount subsampledHeight = buffer.chromaHeight;
121
-
119
+
122
120
  const uint8_t *yPlane = buffer.dataY;
123
121
  const uint8_t *uPlane = buffer.dataU;
124
122
  const uint8_t *vPlane = buffer.dataV;
125
123
  size_t yStride = (size_t)buffer.strideY;
126
124
  size_t uStride = (size_t)buffer.strideU;
127
125
  size_t vStride = (size_t)buffer.strideV;
128
-
126
+
129
127
  // Create vImage buffers to represent each of the Y, U, and V planes
130
128
  vImage_Buffer yPlaneBuffer = {.data = (void *)yPlane, .height = height, .width = width, .rowBytes = yStride};
131
- vImage_Buffer uPlaneBuffer = {.data = (void *)uPlane, .height = subsampledHeight, .width = subsampledWidth, .rowBytes = uStride};
132
- vImage_Buffer vPlaneBuffer = {.data = (void *)vPlane, .height = subsampledHeight, .width = subsampledWidth, .rowBytes = vStride};
133
-
129
+ vImage_Buffer uPlaneBuffer = {
130
+ .data = (void *)uPlane, .height = subsampledHeight, .width = subsampledWidth, .rowBytes = uStride};
131
+ vImage_Buffer vPlaneBuffer = {
132
+ .data = (void *)vPlane, .height = subsampledHeight, .width = subsampledWidth, .rowBytes = vStride};
133
+
134
134
  // Create a vImage buffer for the destination pixel buffer.
135
135
  CVPixelBufferLockBaseAddress(pixelBufferRef, 0);
136
-
136
+
137
137
  void *pixelBufferData = CVPixelBufferGetBaseAddress(pixelBufferRef);
138
138
  size_t rowBytes = CVPixelBufferGetBytesPerRow(pixelBufferRef);
139
- vImage_Buffer destinationImageBuffer = {.data = pixelBufferData, .height = height, .width = width, .rowBytes = rowBytes};
140
-
139
+ vImage_Buffer destinationImageBuffer = {
140
+ .data = pixelBufferData, .height = height, .width = width, .rowBytes = rowBytes};
141
+
141
142
  // Do the conversion.
142
-
143
- uint8_t permuteMap[4] = {3, 2, 1, 0}; // BGRA
144
- vImage_Error convertError = vImageConvert_420Yp8_Cb8_Cr8ToARGB8888(&yPlaneBuffer, &uPlaneBuffer, &vPlaneBuffer, &destinationImageBuffer, self.conversionInfo, permuteMap, 255, kvImageNoFlags);
145
-
143
+
144
+ uint8_t permuteMap[4] = {3, 2, 1, 0}; // BGRA
145
+ vImage_Error convertError = vImageConvert_420Yp8_Cb8_Cr8ToARGB8888(&yPlaneBuffer,
146
+ &uPlaneBuffer,
147
+ &vPlaneBuffer,
148
+ &destinationImageBuffer,
149
+ self.conversionInfo,
150
+ permuteMap,
151
+ 255,
152
+ kvImageNoFlags);
153
+
146
154
  CVPixelBufferUnlockBaseAddress(pixelBufferRef, 0);
147
-
155
+
148
156
  return convertError;
149
157
  }
150
158
 
@@ -1,11 +1,11 @@
1
+ #import <AVKit/AVKit.h>
1
2
  #import <UIKit/UIKit.h>
2
3
  #import <WebRTC/RTCVideoTrack.h>
3
- #import <AVKit/AVKit.h>
4
4
 
5
5
  #import "RTCVideoViewManager.h"
6
6
 
7
7
  API_AVAILABLE(ios(15.0))
8
- @interface PIPController : NSObject <AVPictureInPictureControllerDelegate>
8
+ @interface PIPController : NSObject<AVPictureInPictureControllerDelegate>
9
9
 
10
10
  @property(nonatomic, weak) UIView *sourceView;
11
11
  @property(nonatomic, strong) RTCVideoTrack *videoTrack;
@@ -1,5 +1,5 @@
1
- #import <AVKit/AVKit.h>
2
1
  #import "PIPController.h"
2
+ #import <AVKit/AVKit.h>
3
3
  #import "SampleBufferVideoCallView.h"
4
4
 
5
5
  @interface PIPController ()
@@ -16,29 +16,30 @@
16
16
  @implementation PIPController
17
17
 
18
18
  - (instancetype)initWithSourceView:(UIView *)sourceView {
19
-
20
19
  if (self = [super init]) {
21
20
  self.sourceView = sourceView;
22
-
21
+
23
22
  _fallbackView = [[UIView alloc] initWithFrame:CGRectZero];
24
23
  _fallbackView.translatesAutoresizingMaskIntoConstraints = false;
25
24
 
26
- SampleBufferVideoCallView * subview = [[SampleBufferVideoCallView alloc] initWithFrame:CGRectZero];
25
+ SampleBufferVideoCallView *subview = [[SampleBufferVideoCallView alloc] initWithFrame:CGRectZero];
27
26
  _sampleView = subview;
28
27
  _sampleView.translatesAutoresizingMaskIntoConstraints = false;
29
28
  _pipCallViewController = [[AVPictureInPictureVideoCallViewController alloc] init];
30
29
 
31
30
  [self addToCallViewController:_fallbackView];
32
-
33
- _contentSource = [[AVPictureInPictureControllerContentSource alloc] initWithActiveVideoCallSourceView:sourceView contentViewController:_pipCallViewController];
34
-
31
+
32
+ _contentSource = [[AVPictureInPictureControllerContentSource alloc]
33
+ initWithActiveVideoCallSourceView:sourceView
34
+ contentViewController:_pipCallViewController];
35
+
35
36
  _pipController = [[AVPictureInPictureController alloc] initWithContentSource:_contentSource];
36
37
  _pipController.canStartPictureInPictureAutomaticallyFromInline = YES;
37
38
  _pipController.delegate = self;
38
39
 
39
40
  [_pipController addObserver:self
40
41
  forKeyPath:@"pictureInPictureActive"
41
- options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew
42
+ options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
42
43
  context:nil];
43
44
 
44
45
  [[NSNotificationCenter defaultCenter] addObserver:self
@@ -46,16 +47,15 @@
46
47
  name:UIApplicationWillEnterForegroundNotification
47
48
  object:nil];
48
49
  }
49
-
50
+
50
51
  return self;
51
52
  }
52
53
 
53
54
  - (void)observeValueForKeyPath:(NSString *)keyPath
54
55
  ofObject:(id)object
55
56
  change:(NSDictionary *)change
56
- context:(void *)context
57
- {
58
- if([keyPath isEqualToString:@"pictureInPictureActive"]) {
57
+ context:(void *)context {
58
+ if ([keyPath isEqualToString:@"pictureInPictureActive"]) {
59
59
  _sampleView.shouldRender = [change[NSKeyValueChangeNewKey] boolValue];
60
60
  }
61
61
  }
@@ -72,9 +72,9 @@
72
72
  [_pipCallViewController.view addSubview:view];
73
73
  NSArray *constraints = @[
74
74
  [view.leadingAnchor constraintEqualToAnchor:_pipCallViewController.view.leadingAnchor],
75
- [view.trailingAnchor constraintEqualToAnchor: _pipCallViewController.view.trailingAnchor],
76
- [view.topAnchor constraintEqualToAnchor: _pipCallViewController.view.topAnchor],
77
- [view.bottomAnchor constraintEqualToAnchor: _pipCallViewController.view.bottomAnchor]
75
+ [view.trailingAnchor constraintEqualToAnchor:_pipCallViewController.view.trailingAnchor],
76
+ [view.topAnchor constraintEqualToAnchor:_pipCallViewController.view.topAnchor],
77
+ [view.bottomAnchor constraintEqualToAnchor:_pipCallViewController.view.bottomAnchor]
78
78
  ];
79
79
  [NSLayoutConstraint activateConstraints:constraints];
80
80
  }
@@ -136,9 +136,9 @@
136
136
  }
137
137
 
138
138
  - (void)togglePIP {
139
- if(_pipController.isPictureInPictureActive) {
139
+ if (_pipController.isPictureInPictureActive) {
140
140
  [_pipController stopPictureInPicture];
141
- } else if(_pipController.isPictureInPicturePossible){
141
+ } else if (_pipController.isPictureInPicturePossible) {
142
142
  [_pipController startPictureInPicture];
143
143
  }
144
144
  }
@@ -150,7 +150,7 @@
150
150
  }
151
151
 
152
152
  - (void)stopPIP {
153
- if(_pipController.isPictureInPictureActive) {
153
+ if (_pipController.isPictureInPictureActive) {
154
154
  [_pipController stopPictureInPicture];
155
155
  }
156
156
  }
@@ -158,16 +158,13 @@
158
158
  - (void)dealloc {
159
159
  [_videoTrack removeRenderer:_sampleView];
160
160
  [_pipController removeObserver:self forKeyPath:@"pictureInPictureActive"];
161
- [[NSNotificationCenter defaultCenter] removeObserver:self
162
- name:UIApplicationDidBecomeActiveNotification
163
- object:nil];
161
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
164
162
  }
165
163
 
166
164
  @end
167
165
 
168
166
  @implementation PIPController (AVPictureInPictureControllerDelegate)
169
167
 
170
-
171
168
  /*!
172
169
  @method pictureInPictureControllerWillStartPictureInPicture:
173
170
  @param pictureInPictureController
@@ -175,8 +172,7 @@
175
172
  @abstract Delegate can implement this method to be notified when Picture in Picture will start.
176
173
  */
177
174
  - (void)pictureInPictureControllerWillStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
178
-
179
- NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
175
+ NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
180
176
  }
181
177
 
182
178
  /*!
@@ -186,8 +182,7 @@
186
182
  @abstract Delegate can implement this method to be notified when Picture in Picture did start.
187
183
  */
188
184
  - (void)pictureInPictureControllerDidStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
189
-
190
- NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
185
+ NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
191
186
  }
192
187
 
193
188
  /*!
@@ -198,9 +193,9 @@
198
193
  An error describing why it failed.
199
194
  @abstract Delegate can implement this method to be notified when Picture in Picture failed to start.
200
195
  */
201
- - (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController failedToStartPictureInPictureWithError:(NSError *)error{
202
-
203
- NSLog(@"%@: %@", NSStringFromSelector(_cmd), [error localizedDescription]); // Objective-C
196
+ - (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController
197
+ failedToStartPictureInPictureWithError:(NSError *)error {
198
+ NSLog(@"%@: %@", NSStringFromSelector(_cmd), [error localizedDescription]); // Objective-C
204
199
  }
205
200
 
206
201
  /*!
@@ -210,8 +205,7 @@
210
205
  @abstract Delegate can implement this method to be notified when Picture in Picture will stop.
211
206
  */
212
207
  - (void)pictureInPictureControllerWillStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
213
-
214
- NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
208
+ NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
215
209
  }
216
210
 
217
211
  /*!
@@ -221,8 +215,7 @@
221
215
  @abstract Delegate can implement this method to be notified when Picture in Picture did stop.
222
216
  */
223
217
  - (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
224
-
225
- NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
218
+ NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
226
219
  }
227
220
 
228
221
  /*!
@@ -233,10 +226,9 @@
233
226
  The completion handler the delegate needs to call after restore.
234
227
  @abstract Delegate can implement this method to restore the user interface before Picture in Picture stops.
235
228
  */
236
- - (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler {
237
-
238
- NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
229
+ - (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController
230
+ restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler {
231
+ NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
239
232
  }
240
233
 
241
-
242
234
  @end
@@ -23,7 +23,7 @@
23
23
  * Implements an equivalent of {@code HTMLVideoElement} i.e. Web's video
24
24
  * element.
25
25
  */
26
- @interface RTCVideoView : RCTView
26
+ @interface RTCVideoView : RCTView<RTCVideoViewDelegate>
27
27
 
28
28
  /**
29
29
  * The indicator which determines whether this {@code RTCVideoView} is to mirror
@@ -53,6 +53,9 @@
53
53
  @property(nonatomic, readonly) RTCMTLVideoView *videoView;
54
54
  #endif
55
55
 
56
+ // Add a reference to the view manager
57
+ @property(nonatomic, weak) RTCVideoViewManager *viewManager;
58
+
56
59
  /**
57
60
  * The {@link RTCVideoTrack}, if any, which this instance renders.
58
61
  */
@@ -63,6 +66,8 @@
63
66
  */
64
67
  @property(nonatomic, weak) WebRTCModule *module;
65
68
 
69
+ @property(nonatomic, copy) RCTDirectEventBlock onDimensionsChange;
70
+
66
71
  @end
67
72
 
68
73
  @implementation RTCVideoView
@@ -113,6 +118,7 @@
113
118
  #endif
114
119
  _objectFit = RTCVideoViewObjectFitCover;
115
120
  [self addSubview:self.videoView];
121
+ self.videoView.delegate = self;
116
122
  }
117
123
 
118
124
  return self;
@@ -120,14 +126,14 @@
120
126
 
121
127
  #if TARGET_OS_OSX
122
128
  - (void)layout {
123
- [super layout];
129
+ [super layout];
124
130
  #else
125
131
  - (void)layoutSubviews {
126
- [super layoutSubviews];
132
+ [super layoutSubviews];
127
133
  #endif
128
134
 
129
- CGRect bounds = self.bounds;
130
- self.videoView.frame = bounds;
135
+ CGRect bounds = self.bounds;
136
+ self.videoView.frame = bounds;
131
137
  }
132
138
 
133
139
  /**
@@ -150,12 +156,12 @@
150
156
  [_pipController insertFallbackView:subview];
151
157
  }
152
158
 
153
- - (void) API_AVAILABLE(ios(15.0)) setPIPOptions:(NSDictionary *)pipOptions {
159
+ - (void)API_AVAILABLE(ios(15.0))setPIPOptions:(NSDictionary *)pipOptions {
154
160
  if (!pipOptions) {
155
161
  _pipController = nil;
156
162
  return;
157
163
  }
158
-
164
+
159
165
  BOOL enabled = YES;
160
166
  BOOL startAutomatically = YES;
161
167
  BOOL stopAutomatically = YES;
@@ -175,33 +181,33 @@
175
181
  NSDictionary *sizeDict = pipOptions[@"preferredSize"];
176
182
  id width = sizeDict[@"width"];
177
183
  id height = sizeDict[@"height"];
178
-
184
+
179
185
  if ([width isKindOfClass:[NSNumber class]] && [height isKindOfClass:[NSNumber class]]) {
180
186
  preferredSize = CGSizeMake([width doubleValue], [height doubleValue]);
181
187
  }
182
188
  }
183
-
189
+
184
190
  if (!enabled) {
185
191
  _pipController = nil;
186
192
  return;
187
193
  }
188
-
194
+
189
195
  if (!_pipController) {
190
196
  _pipController = [[PIPController alloc] initWithSourceView:self];
191
197
  _pipController.videoTrack = _videoTrack;
192
198
  }
193
-
199
+
194
200
  _pipController.startAutomatically = startAutomatically;
195
201
  _pipController.stopAutomatically = stopAutomatically;
196
202
  _pipController.objectFit = _objectFit;
197
203
  _pipController.preferredSize = preferredSize;
198
204
  }
199
205
 
200
- - (void) API_AVAILABLE(ios(15.0)) startPIP {
206
+ - (void)API_AVAILABLE(ios(15.0))startPIP {
201
207
  [_pipController startPIP];
202
208
  }
203
209
 
204
- - (void) API_AVAILABLE(ios(15.0)) stopPIP {
210
+ - (void)API_AVAILABLE(ios(15.0))stopPIP {
205
211
  [_pipController stopPIP];
206
212
  }
207
213
 
@@ -292,6 +298,18 @@
292
298
  }
293
299
  }
294
300
 
301
+ - (void)videoView:(id)videoView didChangeVideoSize:(CGSize)size {
302
+ // Capture the callback block to avoid accessing it across threads
303
+ RCTDirectEventBlock callback = self.onDimensionsChange;
304
+ if (callback) {
305
+ NSDictionary *eventData = @{@"width" : @(size.width), @"height" : @(size.height)};
306
+
307
+ dispatch_async(dispatch_get_main_queue(), ^{
308
+ callback(eventData);
309
+ });
310
+ }
311
+ }
312
+
295
313
  @end
296
314
 
297
315
  @implementation RTCVideoViewManager
@@ -301,6 +319,7 @@ RCT_EXPORT_MODULE()
301
319
  - (RCTView *)view {
302
320
  RTCVideoView *v = [[RTCVideoView alloc] init];
303
321
  v.module = [self.bridge moduleForName:@"WebRTCModule"];
322
+ v.viewManager = self;
304
323
  v.clipsToBounds = YES;
305
324
  return v;
306
325
  }
@@ -327,6 +346,8 @@ RCT_CUSTOM_VIEW_PROPERTY(objectFit, NSString *, RTCVideoView) {
327
346
  view.objectFit = fit;
328
347
  }
329
348
 
349
+ RCT_EXPORT_VIEW_PROPERTY(onDimensionsChange, RCTDirectEventBlock)
350
+
330
351
  RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
331
352
  if (!json) {
332
353
  view.videoTrack = nil;
@@ -356,10 +377,10 @@ RCT_CUSTOM_VIEW_PROPERTY(iosPIP, NSDictionary *, RTCVideoView) {
356
377
  }
357
378
  }
358
379
 
359
- RCT_EXPORT_METHOD(startIOSPIP:(nonnull NSNumber *)reactTag) {
380
+ RCT_EXPORT_METHOD(startIOSPIP : (nonnull NSNumber *)reactTag) {
360
381
  if (@available(iOS 15.0, *)) {
361
382
  RCTUIManager *uiManager = [self.bridge moduleForClass:[RCTUIManager class]];
362
- [uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
383
+ [uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
363
384
  UIView *view = viewRegistry[reactTag];
364
385
  if (!view || ![view isKindOfClass:[RTCVideoView class]]) {
365
386
  RCTLogError(@"Cannot find RTCVideoView with tag #%@", reactTag);
@@ -370,10 +391,10 @@ RCT_EXPORT_METHOD(startIOSPIP:(nonnull NSNumber *)reactTag) {
370
391
  }
371
392
  }
372
393
 
373
- RCT_EXPORT_METHOD(stopIOSPIP:(nonnull NSNumber *)reactTag) {
394
+ RCT_EXPORT_METHOD(stopIOSPIP : (nonnull NSNumber *)reactTag) {
374
395
  if (@available(iOS 15.0, *)) {
375
396
  RCTUIManager *uiManager = [self.bridge moduleForClass:[RCTUIManager class]];
376
- [uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
397
+ [uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
377
398
  UIView *view = viewRegistry[reactTag];
378
399
  if (!view || ![view isKindOfClass:[RTCVideoView class]]) {
379
400
  RCTLogError(@"Cannot find RTCVideoView with tag #%@", reactTag);
@@ -1,9 +1,9 @@
1
+ #import <AVKit/AVKit.h>
1
2
  #import <Foundation/Foundation.h>
2
3
  #import <React/RCTViewManager.h>
3
- #import <AVKit/AVKit.h>
4
4
  #import <WebRTC/RTCVideoRenderer.h>
5
5
 
6
- @interface SampleBufferVideoCallView : UIView <RTCVideoRenderer>
6
+ @interface SampleBufferVideoCallView : UIView<RTCVideoRenderer>
7
7
 
8
8
  @property(nonnull, nonatomic, readonly) AVSampleBufferDisplayLayer *sampleBufferLayer;
9
9
  @property(nonatomic, assign) BOOL shouldRender;