react-native-webrtc 124.0.3 → 124.0.5

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 (91) hide show
  1. package/android/build.gradle +2 -1
  2. package/android/consumer-rules.pro +2 -0
  3. package/android/src/main/AndroidManifest.xml +0 -5
  4. package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +43 -10
  5. package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +210 -66
  6. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +23 -8
  7. package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +5 -0
  8. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +4 -2
  9. package/android/src/main/java/org/webrtc/Camera1Helper.java +55 -0
  10. package/android/src/main/java/org/webrtc/Camera2Helper.java +51 -0
  11. package/ios/RCTWebRTC/CaptureController.h +3 -0
  12. package/ios/RCTWebRTC/CaptureController.m +13 -0
  13. package/ios/RCTWebRTC/I420Converter.h +21 -0
  14. package/ios/RCTWebRTC/I420Converter.m +156 -0
  15. package/ios/RCTWebRTC/PIPController.h +24 -0
  16. package/ios/RCTWebRTC/PIPController.m +242 -0
  17. package/ios/RCTWebRTC/RTCVideoViewManager.h +23 -0
  18. package/ios/RCTWebRTC/RTCVideoViewManager.m +105 -23
  19. package/ios/RCTWebRTC/SampleBufferVideoCallView.h +12 -0
  20. package/ios/RCTWebRTC/SampleBufferVideoCallView.m +180 -0
  21. package/ios/RCTWebRTC/ScreenCaptureController.m +8 -0
  22. package/ios/RCTWebRTC/VideoCaptureController.h +2 -0
  23. package/ios/RCTWebRTC/VideoCaptureController.m +96 -30
  24. package/ios/RCTWebRTC/WebRTCModule+RTCAudioSession.m +20 -0
  25. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +47 -15
  26. package/ios/RCTWebRTC/WebRTCModuleOptions.h +1 -0
  27. package/ios/RCTWebRTC.xcodeproj/project.pbxproj +4 -0
  28. package/lib/commonjs/Constraints.js +2 -0
  29. package/lib/commonjs/Constraints.js.map +1 -0
  30. package/lib/commonjs/MediaDevices.js.map +1 -1
  31. package/lib/commonjs/MediaStreamTrack.js +26 -3
  32. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  33. package/lib/commonjs/RTCAudioSession.js +33 -0
  34. package/lib/commonjs/RTCAudioSession.js.map +1 -0
  35. package/lib/commonjs/RTCPIPView.js +42 -0
  36. package/lib/commonjs/RTCPIPView.js.map +1 -0
  37. package/lib/commonjs/RTCPeerConnection.js +5 -2
  38. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  39. package/lib/commonjs/RTCRtpParameters.js +4 -3
  40. package/lib/commonjs/RTCRtpParameters.js.map +1 -1
  41. package/lib/commonjs/RTCRtpSendParameters.js +2 -1
  42. package/lib/commonjs/RTCRtpSendParameters.js.map +1 -1
  43. package/lib/commonjs/RTCView.js.map +1 -1
  44. package/lib/commonjs/getUserMedia.js.map +1 -1
  45. package/lib/commonjs/index.js +28 -0
  46. package/lib/commonjs/index.js.map +1 -1
  47. package/lib/module/Constraints.js +2 -0
  48. package/lib/module/Constraints.js.map +1 -0
  49. package/lib/module/MediaDevices.js.map +1 -1
  50. package/lib/module/MediaStreamTrack.js +27 -4
  51. package/lib/module/MediaStreamTrack.js.map +1 -1
  52. package/lib/module/RTCAudioSession.js +26 -0
  53. package/lib/module/RTCAudioSession.js.map +1 -0
  54. package/lib/module/RTCPIPView.js +30 -0
  55. package/lib/module/RTCPIPView.js.map +1 -0
  56. package/lib/module/RTCPeerConnection.js +5 -2
  57. package/lib/module/RTCPeerConnection.js.map +1 -1
  58. package/lib/module/RTCRtpParameters.js +4 -3
  59. package/lib/module/RTCRtpParameters.js.map +1 -1
  60. package/lib/module/RTCRtpSendParameters.js +2 -1
  61. package/lib/module/RTCRtpSendParameters.js.map +1 -1
  62. package/lib/module/RTCView.js.map +1 -1
  63. package/lib/module/getUserMedia.js.map +1 -1
  64. package/lib/module/index.js +3 -1
  65. package/lib/module/index.js.map +1 -1
  66. package/lib/typescript/Constraints.d.ts +19 -0
  67. package/lib/typescript/MediaDevices.d.ts +2 -1
  68. package/lib/typescript/MediaStreamTrack.d.ts +26 -5
  69. package/lib/typescript/RTCAudioSession.d.ts +10 -0
  70. package/lib/typescript/RTCPIPView.d.ts +14 -0
  71. package/lib/typescript/RTCRtpParameters.d.ts +6 -2
  72. package/lib/typescript/RTCRtpSendParameters.d.ts +6 -2
  73. package/lib/typescript/RTCView.d.ts +44 -1
  74. package/lib/typescript/getUserMedia.d.ts +4 -4
  75. package/lib/typescript/index.d.ts +5 -3
  76. package/package.json +2 -1
  77. package/src/.eslintrc.cjs +1 -1
  78. package/src/Constraints.ts +21 -0
  79. package/src/MediaDevices.ts +2 -2
  80. package/src/MediaStreamTrack.ts +41 -7
  81. package/src/RTCAudioSession.ts +25 -0
  82. package/src/RTCPIPView.tsx +46 -0
  83. package/src/RTCPeerConnection.ts +6 -2
  84. package/src/RTCRtpParameters.ts +6 -5
  85. package/src/RTCRtpSendParameters.ts +5 -5
  86. package/src/RTCView.ts +50 -2
  87. package/src/getUserMedia.ts +4 -3
  88. package/src/index.ts +12 -3
  89. package/tsconfig.json +3 -1
  90. package/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  91. package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
@@ -2,6 +2,7 @@
2
2
  #import <objc/runtime.h>
3
3
 
4
4
  #import <React/RCTLog.h>
5
+ #import <React/RCTUIManager.h>
5
6
  #import <React/RCTView.h>
6
7
 
7
8
  #import <WebRTC/RTCMediaStream.h>
@@ -14,32 +15,10 @@
14
15
  #import <WebRTC/RTCVideoFrame.h>
15
16
  #import <WebRTC/RTCVideoTrack.h>
16
17
 
18
+ #import "PIPController.h"
17
19
  #import "RTCVideoViewManager.h"
18
20
  #import "WebRTCModule.h"
19
21
 
20
- /**
21
- * In the fashion of
22
- * https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth
23
- * and https://www.w3.org/TR/html5/rendering.html#video-object-fit, resembles
24
- * the CSS style {@code object-fit}.
25
- */
26
- typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
27
- /**
28
- * The contain value defined by https://www.w3.org/TR/css3-images/#object-fit:
29
- *
30
- * The replaced content is sized to maintain its aspect ratio while fitting
31
- * within the element's content box.
32
- */
33
- RTCVideoViewObjectFitContain = 1,
34
- /**
35
- * The cover value defined by https://www.w3.org/TR/css3-images/#object-fit:
36
- *
37
- * The replaced content is sized to maintain its aspect ratio while filling
38
- * the element's entire content box.
39
- */
40
- RTCVideoViewObjectFitCover
41
- };
42
-
43
22
  /**
44
23
  * Implements an equivalent of {@code HTMLVideoElement} i.e. Web's video
45
24
  * element.
@@ -61,6 +40,10 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
61
40
  */
62
41
  @property(nonatomic) RTCVideoViewObjectFit objectFit;
63
42
 
43
+ @property(nonatomic) BOOL enablePIP;
44
+
45
+ @property(nonatomic, strong) API_AVAILABLE(ios(15.0)) PIPController *pipController;
46
+
64
47
  /**
65
48
  * The {@link RRTCVideoRenderer} which implements the actual rendering.
66
49
  */
@@ -85,6 +68,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
85
68
  @implementation RTCVideoView
86
69
 
87
70
  @synthesize videoView = _videoView;
71
+ @synthesize pipController = _pipController;
88
72
 
89
73
  /**
90
74
  * Tells this view that its window object changed.
@@ -127,6 +111,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
127
111
  RTCMTLVideoView *subview = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
128
112
  _videoView = subview;
129
113
  #endif
114
+ _objectFit = RTCVideoViewObjectFitCover;
130
115
  [self addSubview:self.videoView];
131
116
  }
132
117
 
@@ -160,6 +145,66 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
160
145
  }
161
146
  }
162
147
 
148
+ - (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex {
149
+ // All subviews are treated as fallback views
150
+ [_pipController insertFallbackView:subview];
151
+ }
152
+
153
+ - (void) API_AVAILABLE(ios(15.0)) setPIPOptions:(NSDictionary *)pipOptions {
154
+ if (!pipOptions) {
155
+ _pipController = nil;
156
+ return;
157
+ }
158
+
159
+ BOOL enabled = YES;
160
+ BOOL startAutomatically = YES;
161
+ BOOL stopAutomatically = YES;
162
+
163
+ CGSize preferredSize = CGSizeZero;
164
+
165
+ if ([pipOptions objectForKey:@"enabled"]) {
166
+ enabled = [pipOptions[@"enabled"] boolValue];
167
+ }
168
+ if ([pipOptions objectForKey:@"startAutomatically"]) {
169
+ startAutomatically = [pipOptions[@"startAutomatically"] boolValue];
170
+ }
171
+ if ([pipOptions objectForKey:@"stopAutomatically"]) {
172
+ stopAutomatically = [pipOptions[@"stopAutomatically"] boolValue];
173
+ }
174
+ if ([pipOptions objectForKey:@"preferredSize"]) {
175
+ NSDictionary *sizeDict = pipOptions[@"preferredSize"];
176
+ id width = sizeDict[@"width"];
177
+ id height = sizeDict[@"height"];
178
+
179
+ if ([width isKindOfClass:[NSNumber class]] && [height isKindOfClass:[NSNumber class]]) {
180
+ preferredSize = CGSizeMake([width doubleValue], [height doubleValue]);
181
+ }
182
+ }
183
+
184
+ if (!enabled) {
185
+ _pipController = nil;
186
+ return;
187
+ }
188
+
189
+ if (!_pipController) {
190
+ _pipController = [[PIPController alloc] initWithSourceView:self];
191
+ _pipController.videoTrack = _videoTrack;
192
+ }
193
+
194
+ _pipController.startAutomatically = startAutomatically;
195
+ _pipController.stopAutomatically = stopAutomatically;
196
+ _pipController.objectFit = _objectFit;
197
+ _pipController.preferredSize = preferredSize;
198
+ }
199
+
200
+ - (void) API_AVAILABLE(ios(15.0)) startPIP {
201
+ [_pipController startPIP];
202
+ }
203
+
204
+ - (void) API_AVAILABLE(ios(15.0)) stopPIP {
205
+ [_pipController stopPIP];
206
+ }
207
+
163
208
  /**
164
209
  * Implements the setter of the {@link #objectFit} property of this
165
210
  * {@code RTCVideoView}.
@@ -178,6 +223,9 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
178
223
  self.videoView.videoContentMode = UIViewContentModeScaleAspectFit;
179
224
  }
180
225
  #endif
226
+ if (@available(iOS 15.0, *)) {
227
+ _pipController.objectFit = fit;
228
+ }
181
229
  }
182
230
  }
183
231
 
@@ -198,6 +246,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
198
246
  });
199
247
  }
200
248
 
249
+ [_pipController setVideoTrack:videoTrack];
201
250
  _videoTrack = videoTrack;
202
251
 
203
252
  // Clear the videoView by rendering a 2x2 blank frame.
@@ -301,6 +350,39 @@ RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
301
350
  });
302
351
  }
303
352
 
353
+ RCT_CUSTOM_VIEW_PROPERTY(iosPIP, NSDictionary *, RTCVideoView) {
354
+ if (@available(iOS 15.0, *)) {
355
+ [view setPIPOptions:json];
356
+ }
357
+ }
358
+
359
+ RCT_EXPORT_METHOD(startIOSPIP:(nonnull NSNumber *)reactTag) {
360
+ if (@available(iOS 15.0, *)) {
361
+ RCTUIManager *uiManager = [self.bridge moduleForClass:[RCTUIManager class]];
362
+ [uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
363
+ UIView *view = viewRegistry[reactTag];
364
+ if (!view || ![view isKindOfClass:[RTCVideoView class]]) {
365
+ RCTLogError(@"Cannot find RTCVideoView with tag #%@", reactTag);
366
+ return;
367
+ }
368
+ [(RTCVideoView *)view startPIP];
369
+ }];
370
+ }
371
+ }
372
+
373
+ RCT_EXPORT_METHOD(stopIOSPIP:(nonnull NSNumber *)reactTag) {
374
+ if (@available(iOS 15.0, *)) {
375
+ RCTUIManager *uiManager = [self.bridge moduleForClass:[RCTUIManager class]];
376
+ [uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
377
+ UIView *view = viewRegistry[reactTag];
378
+ if (!view || ![view isKindOfClass:[RTCVideoView class]]) {
379
+ RCTLogError(@"Cannot find RTCVideoView with tag #%@", reactTag);
380
+ return;
381
+ }
382
+ [(RTCVideoView *)view stopPIP];
383
+ }];
384
+ }
385
+ }
304
386
  + (BOOL)requiresMainQueueSetup {
305
387
  return NO;
306
388
  }
@@ -0,0 +1,12 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import <React/RCTViewManager.h>
3
+ #import <AVKit/AVKit.h>
4
+ #import <WebRTC/RTCVideoRenderer.h>
5
+
6
+ @interface SampleBufferVideoCallView : UIView <RTCVideoRenderer>
7
+
8
+ @property(nonnull, nonatomic, readonly) AVSampleBufferDisplayLayer *sampleBufferLayer;
9
+ @property(nonatomic, assign) BOOL shouldRender;
10
+
11
+ - (void)requestScaleRecalculation;
12
+ @end
@@ -0,0 +1,180 @@
1
+ #import "I420Converter.h"
2
+ #import "SampleBufferVideoCallView.h"
3
+ #import <WebRTC/WebRTC.h>
4
+ #import <Accelerate/Accelerate.h>
5
+
6
+ @protocol SampleBufferRendering <AVQueuedSampleBufferRendering>
7
+
8
+ -(BOOL)requiresFlushToResumeDecoding;
9
+
10
+ @end
11
+
12
+ /** These classes already implement the required methods. */
13
+ @interface AVSampleBufferDisplayLayer () <SampleBufferRendering>
14
+ @end
15
+ @interface AVSampleBufferVideoRenderer () <SampleBufferRendering>
16
+ @end
17
+
18
+ @interface SampleBufferVideoCallView ()
19
+
20
+ @property (nonatomic, retain) I420Converter *i420Converter;
21
+ @property (nonatomic, strong) id<SampleBufferRendering> renderer;
22
+ @property (nonatomic, assign) NSInteger currentRotation;
23
+
24
+ @end
25
+
26
+ @implementation SampleBufferVideoCallView
27
+
28
+ + (Class)layerClass {
29
+ return [AVSampleBufferDisplayLayer class];
30
+ }
31
+
32
+ - (instancetype)initWithFrame:(CGRect)frame {
33
+ if (self = [super initWithFrame:frame]) {
34
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(layerFailedToDecode:) name:AVSampleBufferDisplayLayerFailedToDecodeNotification object:self.sampleBufferLayer];
35
+ if (@available(iOS 17.0, *)) {
36
+ _renderer = self.sampleBufferLayer.sampleBufferRenderer;
37
+ } else {
38
+ _renderer = self.sampleBufferLayer;
39
+ }
40
+ }
41
+ return self;
42
+ }
43
+
44
+ - (void)layerFailedToDecode:(NSNotification*)note
45
+ {
46
+ NSError *error = [[note userInfo] valueForKey:AVSampleBufferDisplayLayerFailedToDecodeNotificationErrorKey];
47
+ NSLog(@"layerFailedToDecode, error: %@", [error localizedDescription]);
48
+ }
49
+
50
+ - (AVSampleBufferDisplayLayer *)sampleBufferLayer {
51
+ return (AVSampleBufferDisplayLayer *)self.layer;
52
+ }
53
+
54
+ - (void)requestScaleRecalculation {
55
+ _currentRotation = -1;
56
+ }
57
+
58
+ - (void)recalculateScale:(RTCVideoRotation)rotation {
59
+ if (self.currentRotation != rotation) {
60
+ self.currentRotation = rotation;
61
+
62
+ CGFloat scale = 1;
63
+ if(rotation == 90 || rotation == 270) {
64
+ CGSize size = self.bounds.size;
65
+ scale = size.height / size.width;
66
+ }
67
+
68
+ self.sampleBufferLayer.transform = CATransform3DConcat(
69
+ CATransform3DMakeRotation(rotation / 180.0 * M_PI, 0.0, 0.0, 1.0),
70
+ CATransform3DMakeScale(scale, scale, 1)
71
+ );
72
+ }
73
+ }
74
+
75
+ /** The size of the video frame. */
76
+ - (void)setSize : (CGSize)size{
77
+
78
+ }
79
+
80
+ /** The frame to be displayed. */
81
+ - (void)renderFrame:(nullable RTC_OBJC_TYPE(RTCVideoFrame) *)frame {
82
+
83
+ if (!_shouldRender) {
84
+ return;
85
+ }
86
+
87
+ // Convert RTCVideoFrame to CMSampleBuffer
88
+ CMSampleBufferRef sampleBuffer = [self sampleBufferFrom:frame];
89
+ if (sampleBuffer == nil) {
90
+ return;
91
+ }
92
+
93
+ dispatch_async(dispatch_get_main_queue(), ^{
94
+
95
+ if (self.renderer.requiresFlushToResumeDecoding) {
96
+ [self.renderer flush];
97
+ }
98
+
99
+ if (!self.renderer.readyForMoreMediaData) {
100
+ return;
101
+ }
102
+
103
+ [self recalculateScale:frame.rotation];
104
+
105
+ // Display the CMSampleBuffer using AVSampleBufferDisplayLayer
106
+ [self.renderer enqueueSampleBuffer:sampleBuffer];
107
+ CFRelease(sampleBuffer);
108
+ });
109
+ }
110
+
111
+ - (CMSampleBufferRef)sampleBufferFrom:(RTCVideoFrame *)rtcVideoFrame {
112
+ // Convert RTCVideoFrame to CMSampleBuffer
113
+
114
+ // Assuming your RTCVideoFrame contains pixelBuffer
115
+ CVPixelBufferRef pixelBuffer = [self pixelBufferFrom:rtcVideoFrame];
116
+ if (!pixelBuffer) {
117
+ return nil;
118
+ }
119
+
120
+ // Create a CMVideoFormatDescription
121
+ CMVideoFormatDescriptionRef formatDescription;
122
+ CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, &formatDescription);
123
+
124
+ // Create CMSampleTimingInfo
125
+ // Timescale is 90khz according to RTCVideoFrame.h
126
+ CMSampleTimingInfo timingInfo;
127
+ timingInfo.presentationTimeStamp = CMTimeMake(rtcVideoFrame.timeStamp, 90000);
128
+ timingInfo.decodeTimeStamp = CMTimeMake(rtcVideoFrame.timeStamp, 90000);
129
+
130
+ // Create CMSampleBuffer
131
+ CMSampleBufferRef sampleBuffer;
132
+ CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, true, nil, nil, formatDescription, &timingInfo, &sampleBuffer);
133
+
134
+ CFArrayRef attachments = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, YES);
135
+ CFMutableDictionaryRef dict = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachments, 0);
136
+
137
+ CFDictionarySetValue(dict, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
138
+ CVPixelBufferRelease(pixelBuffer);
139
+ return sampleBuffer;
140
+ }
141
+
142
+ /**
143
+ * The CVPixelBufferRef returned from this function must be released when finished using it.
144
+ */
145
+ -(CVPixelBufferRef)pixelBufferFrom:(RTCVideoFrame *)videoFrame {
146
+ if ([videoFrame.buffer isKindOfClass:[RTCCVPixelBuffer class]]) {
147
+ CVPixelBufferRef pixelBuffer = [((RTCCVPixelBuffer *) videoFrame.buffer) pixelBuffer];
148
+ CVPixelBufferRetain(pixelBuffer);
149
+ return [((RTCCVPixelBuffer *) videoFrame.buffer) pixelBuffer];
150
+ } else {
151
+ return [self pixelBufferFromI420:[videoFrame.buffer toI420]];
152
+ }
153
+ }
154
+
155
+ /**
156
+ * The CVPixelBufferRef returned from this function must be released when finished using it.
157
+ */
158
+ -(CVPixelBufferRef)pixelBufferFromI420:(RTCI420Buffer *)i420Buffer {
159
+ if (_i420Converter == nil) {
160
+ I420Converter * converter = [[I420Converter alloc] init];
161
+ vImage_Error err = [converter prepareForAccelerateConversion];
162
+
163
+ if(err != kvImageNoError) {
164
+ NSLog(@"Error when preparing i420Converter: %ld", err);
165
+ return NULL;
166
+ }
167
+
168
+ _i420Converter = converter;
169
+ }
170
+
171
+ CVPixelBufferRef convertedPixelBuffer = [_i420Converter convertI420ToPixelBuffer:i420Buffer];
172
+
173
+ return convertedPixelBuffer;
174
+ }
175
+
176
+ -(void)dealloc {
177
+ [_i420Converter unprepareForAccelerateConversion];
178
+ }
179
+
180
+ @end
@@ -29,6 +29,7 @@ NSString *const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
29
29
  self = [super init];
30
30
  if (self) {
31
31
  self.capturer = capturer;
32
+ self.deviceId = @"screen-capture";
32
33
  }
33
34
 
34
35
  return self;
@@ -53,6 +54,13 @@ NSString *const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";
53
54
  [self.capturer stopCapture];
54
55
  }
55
56
 
57
+ - (NSDictionary *)getSettings {
58
+ return @{
59
+ @"deviceId": self.deviceId,
60
+ @"groupId": @"",
61
+ @"frameRate" : @(30)
62
+ };
63
+ }
56
64
  // MARK: CapturerEventsDelegate Methods
57
65
 
58
66
  - (void)capturerDidEnd:(RTCVideoCapturer *)capturer {
@@ -8,11 +8,13 @@
8
8
  @interface VideoCaptureController : CaptureController
9
9
  @property(nonatomic, readonly, strong) AVCaptureDeviceFormat *selectedFormat;
10
10
  @property(nonatomic, readonly, assign) int frameRate;
11
+ @property(nonatomic, assign) BOOL enableMultitaskingCameraAccess;
11
12
 
12
13
  - (instancetype)initWithCapturer:(RTCCameraVideoCapturer *)capturer andConstraints:(NSDictionary *)constraints;
13
14
  - (void)startCapture;
14
15
  - (void)stopCapture;
15
16
  - (void)switchCamera;
17
+ - (void)applyConstraints:(NSDictionary *)constraints error:(NSError **)outError;
16
18
 
17
19
  @end
18
20
  #endif
@@ -9,7 +9,6 @@
9
9
  @property(nonatomic, strong) RTCCameraVideoCapturer *capturer;
10
10
  @property(nonatomic, strong) AVCaptureDeviceFormat *selectedFormat;
11
11
  @property(nonatomic, strong) AVCaptureDevice *device;
12
- @property(nonatomic, copy) NSString *deviceId;
13
12
  @property(nonatomic, assign) BOOL running;
14
13
  @property(nonatomic, assign) BOOL usingFrontCamera;
15
14
  @property(nonatomic, assign) int width;
@@ -25,31 +24,7 @@
25
24
  if (self) {
26
25
  self.capturer = capturer;
27
26
  self.running = NO;
28
-
29
- // Default to the front camera.
30
- self.usingFrontCamera = YES;
31
-
32
- self.deviceId = constraints[@"deviceId"];
33
- self.width = [constraints[@"width"] intValue];
34
- self.height = [constraints[@"height"] intValue];
35
- self.frameRate = [constraints[@"frameRate"] intValue];
36
-
37
- id facingMode = constraints[@"facingMode"];
38
-
39
- if (facingMode && [facingMode isKindOfClass:[NSString class]]) {
40
- AVCaptureDevicePosition position;
41
- if ([facingMode isEqualToString:@"environment"]) {
42
- position = AVCaptureDevicePositionBack;
43
- } else if ([facingMode isEqualToString:@"user"]) {
44
- position = AVCaptureDevicePositionFront;
45
- } else {
46
- // If the specified facingMode value is not supported, fall back
47
- // to the front camera.
48
- position = AVCaptureDevicePositionFront;
49
- }
50
-
51
- self.usingFrontCamera = position == AVCaptureDevicePositionFront;
52
- }
27
+ [self applyConstraints:constraints error:nil];
53
28
  }
54
29
 
55
30
  return self;
@@ -67,6 +42,7 @@
67
42
  AVCaptureDevicePosition position =
68
43
  self.usingFrontCamera ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack;
69
44
  self.device = [self findDeviceForPosition:position];
45
+ self.deviceId = self.device.uniqueID;
70
46
  }
71
47
 
72
48
  if (!self.device) {
@@ -86,6 +62,19 @@
86
62
 
87
63
  self.selectedFormat = format;
88
64
 
65
+ AVCaptureSession *session = self.capturer.captureSession;
66
+ if (@available(iOS 16.0, *)) {
67
+ BOOL enable = self.enableMultitaskingCameraAccess;
68
+ BOOL shouldChange = session.multitaskingCameraAccessEnabled != enable;
69
+ BOOL canChange = !enable || (enable && session.isMultitaskingCameraAccessSupported);
70
+
71
+ if(shouldChange && canChange) {
72
+ [session beginConfiguration];
73
+ [session setMultitaskingCameraAccessEnabled:enable];
74
+ [session commitConfiguration];
75
+ }
76
+ }
77
+
89
78
  RCTLog(@"[VideoCaptureController] Capture will start");
90
79
 
91
80
  // Starting the capture happens on another thread. Wait for it.
@@ -128,14 +117,91 @@
128
117
  dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
129
118
  }
130
119
 
131
- - (void)switchCamera {
132
- self.usingFrontCamera = !self.usingFrontCamera;
133
- self.deviceId = nil;
120
+ - (void)applyConstraints:(NSDictionary *)constraints error:(NSError **)outError {
121
+ // Clear device to prepare for starting camera with new constraints.
134
122
  self.device = nil;
135
123
 
136
- [self startCapture];
124
+ BOOL hasChanged = NO;
125
+
126
+ NSString *deviceId = constraints[@"deviceId"];
127
+ int width = [constraints[@"width"] intValue];
128
+ int height = [constraints[@"height"] intValue];
129
+ int frameRate = [constraints[@"frameRate"] intValue];
130
+
131
+ if (self.width != width) {
132
+ hasChanged = YES;
133
+ self.width = width;
134
+ }
135
+
136
+ if (self.height != height) {
137
+ hasChanged = YES;
138
+ self.height = height;
139
+ }
140
+
141
+ if (self.frameRate != frameRate) {
142
+ hasChanged = YES;
143
+ self.frameRate = frameRate;
144
+ }
145
+
146
+ id facingMode = constraints[@"facingMode"];
147
+
148
+ if (!facingMode && !deviceId) {
149
+ // Default to front camera.
150
+ facingMode = @"user";
151
+ }
152
+
153
+ if (facingMode && [facingMode isKindOfClass:[NSString class]]) {
154
+ AVCaptureDevicePosition position;
155
+ if ([facingMode isEqualToString:@"environment"]) {
156
+ position = AVCaptureDevicePositionBack;
157
+ } else if ([facingMode isEqualToString:@"user"]) {
158
+ position = AVCaptureDevicePositionFront;
159
+ } else {
160
+ // If the specified facingMode value is not supported, fall back
161
+ // to the front camera.
162
+ position = AVCaptureDevicePositionFront;
163
+ }
164
+
165
+ BOOL usingFrontCamera = position == AVCaptureDevicePositionFront;
166
+ if (self.usingFrontCamera != usingFrontCamera) {
167
+ hasChanged = YES;
168
+ self.usingFrontCamera = usingFrontCamera;
169
+ }
170
+ }
171
+
172
+ if (!deviceId) {
173
+ AVCaptureDevicePosition position =
174
+ self.usingFrontCamera ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack;
175
+ deviceId = [self findDeviceForPosition:position].uniqueID;
176
+ }
177
+
178
+ if (self.deviceId != deviceId && ![self.deviceId isEqualToString:deviceId]) {
179
+ hasChanged = YES;
180
+ self.deviceId = deviceId;
181
+ }
182
+
183
+
184
+ if (self.running && hasChanged) {
185
+ [self startCapture];
186
+ }
137
187
  }
138
188
 
189
+ - (NSDictionary *)getSettings {
190
+ AVCaptureDeviceFormat *format = self.selectedFormat;
191
+ CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
192
+ NSMutableDictionary *settings = [[NSMutableDictionary alloc] initWithDictionary:@{
193
+ @"groupId": @"",
194
+ @"height" : @(dimensions.height),
195
+ @"width" : @(dimensions.width),
196
+ @"frameRate" : @(30),
197
+ @"facingMode" : self.usingFrontCamera ? @"user" : @"environment"
198
+ }];
199
+
200
+ if (self.deviceId) {
201
+ settings[@"deviceId"] = self.deviceId;
202
+ }
203
+ return settings;
204
+ }
139
205
  #pragma mark NSKeyValueObserving
140
206
 
141
207
  - (void)observeValueForKeyPath:(NSString *)keyPath
@@ -0,0 +1,20 @@
1
+ #import <objc/runtime.h>
2
+
3
+ #import <React/RCTBridge.h>
4
+ #import <React/RCTBridgeModule.h>
5
+
6
+ #import "WebRTCModule.h"
7
+
8
+ @implementation WebRTCModule (RTCAudioSession)
9
+
10
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(audioSessionDidActivate) {
11
+ [[RTCAudioSession sharedInstance] audioSessionDidActivate:[AVAudioSession sharedInstance]];
12
+ return nil;
13
+ }
14
+
15
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(audioSessionDidDeactivate) {
16
+ [[RTCAudioSession sharedInstance] audioSessionDidDeactivate:[AVAudioSession sharedInstance]];
17
+ return nil;
18
+ }
19
+
20
+ @end