react-native-webrtc 124.0.4 → 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 (71) hide show
  1. package/android/build.gradle +2 -1
  2. package/android/consumer-rules.pro +2 -0
  3. package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +29 -3
  4. package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +181 -72
  5. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +22 -7
  6. package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +5 -0
  7. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +4 -2
  8. package/ios/RCTWebRTC/CaptureController.h +3 -0
  9. package/ios/RCTWebRTC/CaptureController.m +13 -0
  10. package/ios/RCTWebRTC/I420Converter.h +21 -0
  11. package/ios/RCTWebRTC/I420Converter.m +156 -0
  12. package/ios/RCTWebRTC/PIPController.h +24 -0
  13. package/ios/RCTWebRTC/PIPController.m +242 -0
  14. package/ios/RCTWebRTC/RTCVideoViewManager.h +23 -0
  15. package/ios/RCTWebRTC/RTCVideoViewManager.m +105 -23
  16. package/ios/RCTWebRTC/SampleBufferVideoCallView.h +12 -0
  17. package/ios/RCTWebRTC/SampleBufferVideoCallView.m +180 -0
  18. package/ios/RCTWebRTC/ScreenCaptureController.m +8 -0
  19. package/ios/RCTWebRTC/VideoCaptureController.h +2 -0
  20. package/ios/RCTWebRTC/VideoCaptureController.m +96 -30
  21. package/ios/RCTWebRTC/WebRTCModule+RTCAudioSession.m +20 -0
  22. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +40 -14
  23. package/ios/RCTWebRTC/WebRTCModuleOptions.h +1 -0
  24. package/ios/RCTWebRTC.xcodeproj/project.pbxproj +4 -0
  25. package/lib/commonjs/Constraints.js +2 -0
  26. package/lib/commonjs/Constraints.js.map +1 -0
  27. package/lib/commonjs/MediaDevices.js.map +1 -1
  28. package/lib/commonjs/MediaStreamTrack.js +26 -3
  29. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  30. package/lib/commonjs/RTCAudioSession.js +33 -0
  31. package/lib/commonjs/RTCAudioSession.js.map +1 -0
  32. package/lib/commonjs/RTCPIPView.js +42 -0
  33. package/lib/commonjs/RTCPIPView.js.map +1 -0
  34. package/lib/commonjs/RTCView.js.map +1 -1
  35. package/lib/commonjs/getUserMedia.js.map +1 -1
  36. package/lib/commonjs/index.js +28 -0
  37. package/lib/commonjs/index.js.map +1 -1
  38. package/lib/module/Constraints.js +2 -0
  39. package/lib/module/Constraints.js.map +1 -0
  40. package/lib/module/MediaDevices.js.map +1 -1
  41. package/lib/module/MediaStreamTrack.js +27 -4
  42. package/lib/module/MediaStreamTrack.js.map +1 -1
  43. package/lib/module/RTCAudioSession.js +26 -0
  44. package/lib/module/RTCAudioSession.js.map +1 -0
  45. package/lib/module/RTCPIPView.js +30 -0
  46. package/lib/module/RTCPIPView.js.map +1 -0
  47. package/lib/module/RTCView.js.map +1 -1
  48. package/lib/module/getUserMedia.js.map +1 -1
  49. package/lib/module/index.js +3 -1
  50. package/lib/module/index.js.map +1 -1
  51. package/lib/typescript/Constraints.d.ts +19 -0
  52. package/lib/typescript/MediaDevices.d.ts +2 -1
  53. package/lib/typescript/MediaStreamTrack.d.ts +26 -5
  54. package/lib/typescript/RTCAudioSession.d.ts +10 -0
  55. package/lib/typescript/RTCPIPView.d.ts +14 -0
  56. package/lib/typescript/RTCView.d.ts +44 -1
  57. package/lib/typescript/getUserMedia.d.ts +4 -4
  58. package/lib/typescript/index.d.ts +5 -3
  59. package/package.json +2 -1
  60. package/src/.eslintrc.cjs +1 -1
  61. package/src/Constraints.ts +21 -0
  62. package/src/MediaDevices.ts +2 -2
  63. package/src/MediaStreamTrack.ts +41 -7
  64. package/src/RTCAudioSession.ts +25 -0
  65. package/src/RTCPIPView.tsx +46 -0
  66. package/src/RTCView.ts +50 -2
  67. package/src/getUserMedia.ts +4 -3
  68. package/src/index.ts +12 -3
  69. package/tsconfig.json +3 -1
  70. package/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  71. package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
@@ -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
@@ -6,6 +6,7 @@
6
6
  #import <WebRTC/RTCVideoTrack.h>
7
7
 
8
8
  #import "RTCMediaStreamTrack+React.h"
9
+ #import "WebRTCModuleOptions.h"
9
10
  #import "WebRTCModule+RTCMediaStream.h"
10
11
  #import "WebRTCModule+RTCPeerConnection.h"
11
12
 
@@ -77,12 +78,14 @@
77
78
  NSDictionary *settings = @{};
78
79
  if ([track.kind isEqualToString:@"video"]) {
79
80
  RTCVideoTrack *videoTrack = (RTCVideoTrack *)track;
80
- if ([videoTrack.captureController isKindOfClass:[VideoCaptureController class]]) {
81
- VideoCaptureController *vcc = (VideoCaptureController *)videoTrack.captureController;
82
- AVCaptureDeviceFormat *format = vcc.selectedFormat;
83
- CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
84
- settings = @{@"height" : @(dimensions.height), @"width" : @(dimensions.width), @"frameRate" : @(30)};
81
+ if ([videoTrack.captureController isKindOfClass:[CaptureController class]]) {
82
+ settings = [videoTrack.captureController getSettings];
85
83
  }
84
+ } else if ([track.kind isEqualToString:@"audio"]) {
85
+ settings = @{
86
+ @"deviceId": @"audio",
87
+ @"groupId": @"",
88
+ };
86
89
  }
87
90
 
88
91
  [trackInfos addObject:@{
@@ -116,6 +119,7 @@
116
119
  RTCCameraVideoCapturer *videoCapturer = [[RTCCameraVideoCapturer alloc] initWithDelegate:videoSource];
117
120
  VideoCaptureController *videoCaptureController =
118
121
  [[VideoCaptureController alloc] initWithCapturer:videoCapturer andConstraints:constraints[@"video"]];
122
+ videoCaptureController.enableMultitaskingCameraAccess = [WebRTCModuleOptions sharedInstance].enableMultitaskingCameraAccess;
119
123
  videoTrack.captureController = videoCaptureController;
120
124
  [videoCaptureController startCapture];
121
125
  #endif
@@ -234,10 +238,14 @@ RCT_EXPORT_METHOD(getUserMedia
234
238
  NSDictionary *settings = @{};
235
239
  if ([track.kind isEqualToString:@"video"]) {
236
240
  RTCVideoTrack *videoTrack = (RTCVideoTrack *)track;
237
- VideoCaptureController *vcc = (VideoCaptureController *)videoTrack.captureController;
238
- AVCaptureDeviceFormat *format = vcc.selectedFormat;
239
- CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
240
- settings = @{@"height" : @(dimensions.height), @"width" : @(dimensions.width), @"frameRate" : @(30)};
241
+ if ([videoTrack.captureController isKindOfClass:[CaptureController class]]) {
242
+ settings = [videoTrack.captureController getSettings];
243
+ }
244
+ } else if ([track.kind isEqualToString:@"audio"]) {
245
+ settings = @{
246
+ @"deviceId": @"audio",
247
+ @"groupId": @"",
248
+ };
241
249
  }
242
250
 
243
251
  [tracks addObject:@{
@@ -267,11 +275,11 @@ RCT_EXPORT_METHOD(enumerateDevices : (RCTResponseSenderBlock)callback) {
267
275
  if (@available(macos 14.0, ios 17.0, tvos 17.0, *)) {
268
276
  [deviceTypes addObject:AVCaptureDeviceTypeExternal];
269
277
  }
270
- AVCaptureDeviceDiscoverySession *videoevicesSession =
278
+ AVCaptureDeviceDiscoverySession *videoDevicesSession =
271
279
  [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:deviceTypes
272
280
  mediaType:AVMediaTypeVideo
273
281
  position:AVCaptureDevicePositionUnspecified];
274
- for (AVCaptureDevice *device in videoevicesSession.devices) {
282
+ for (AVCaptureDevice *device in videoDevicesSession.devices) {
275
283
  NSString *position = @"unknown";
276
284
  if (device.position == AVCaptureDevicePositionBack) {
277
285
  position = @"environment";
@@ -397,14 +405,32 @@ RCT_EXPORT_METHOD(mediaStreamTrackSetEnabled : (nonnull NSNumber *)pcId : (nonnu
397
405
  #endif
398
406
  }
399
407
 
400
- RCT_EXPORT_METHOD(mediaStreamTrackSwitchCamera : (nonnull NSString *)trackID) {
408
+ RCT_EXPORT_METHOD(mediaStreamTrackApplyConstraints : (nonnull NSString *)trackID : (NSDictionary *)constraints : (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
401
409
  #if TARGET_OS_TV
410
+ reject(@"unsupported_platform", @"tvOS is not supported", nil);
402
411
  return;
403
412
  #else
404
413
  RTCMediaStreamTrack *track = self.localTracks[trackID];
405
414
  if (track) {
406
- RTCVideoTrack *videoTrack = (RTCVideoTrack *)track;
407
- [(VideoCaptureController *)videoTrack.captureController switchCamera];
415
+ if ([track.kind isEqualToString:@"video"]) {
416
+ RTCVideoTrack *videoTrack = (RTCVideoTrack *)track;
417
+ if ([videoTrack.captureController isKindOfClass:[CaptureController class]]) {
418
+ CaptureController *vcc = (CaptureController *)videoTrack.captureController;
419
+ NSError* error = nil;
420
+ [vcc applyConstraints:constraints error:&error];
421
+ if (error) {
422
+ reject(@"E_INVALID", error.localizedDescription, error);
423
+ } else {
424
+ resolve([vcc getSettings]);
425
+ }
426
+ }
427
+ } else {
428
+ RCTLogWarn(@"mediaStreamTrackApplyConstraints() track is not video");
429
+ reject(@"E_INVALID", @"Can't apply constraints on audio tracks", nil);
430
+ }
431
+ } else {
432
+ RCTLogWarn(@"mediaStreamTrackApplyConstraints() track is null");
433
+ reject(@"E_INVALID", @"Could not get track", nil);
408
434
  }
409
435
  #endif
410
436
  }
@@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN
10
10
  @property(nonatomic, strong, nullable) id<RTCAudioDevice> audioDevice;
11
11
  @property(nonatomic, strong, nullable) NSDictionary *fieldTrials;
12
12
  @property(nonatomic, assign) RTCLoggingSeverity loggingSeverity;
13
+ @property(nonatomic, assign) BOOL enableMultitaskingCameraAccess;
13
14
 
14
15
  #pragma mark - This class is a singleton
15
16
 
@@ -24,6 +24,7 @@
24
24
  4EE3A8D425B841DD00FAA24A /* ScreenCapturer.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EE3A8CD25B841DD00FAA24A /* ScreenCapturer.m */; };
25
25
  D3FF699919D2664B25C9D458 /* Pods_RCTWebRTC.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A20F721AD842563B66292D5B /* Pods_RCTWebRTC.framework */; };
26
26
  D74EF94829652169000742E1 /* TrackCapturerEventsEmitter.m in Sources */ = {isa = PBXBuildFile; fileRef = D74EF94629652169000742E1 /* TrackCapturerEventsEmitter.m */; };
27
+ D7F0711E2C6DC91F0031F594 /* WebRTCModule+RTCAudioSession.m in Sources */ = {isa = PBXBuildFile; fileRef = D7F0711D2C6DC91F0031F594 /* WebRTCModule+RTCAudioSession.m */; };
27
28
  DEC96577264176C10052DB35 /* DataChannelWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = DEC96576264176C10052DB35 /* DataChannelWrapper.m */; };
28
29
  /* End PBXBuildFile section */
29
30
 
@@ -75,6 +76,7 @@
75
76
  D74EF94529652148000742E1 /* CapturerEventsDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CapturerEventsDelegate.h; path = RCTWebRTC/CapturerEventsDelegate.h; sourceTree = SOURCE_ROOT; };
76
77
  D74EF94629652169000742E1 /* TrackCapturerEventsEmitter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TrackCapturerEventsEmitter.m; path = RCTWebRTC/TrackCapturerEventsEmitter.m; sourceTree = SOURCE_ROOT; };
77
78
  D74EF94729652169000742E1 /* TrackCapturerEventsEmitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TrackCapturerEventsEmitter.h; path = RCTWebRTC/TrackCapturerEventsEmitter.h; sourceTree = SOURCE_ROOT; };
79
+ D7F0711D2C6DC91F0031F594 /* WebRTCModule+RTCAudioSession.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "WebRTCModule+RTCAudioSession.m"; path = "RCTWebRTC/WebRTCModule+RTCAudioSession.m"; sourceTree = SOURCE_ROOT; };
78
80
  D7F99C122938F4E0000A2450 /* WebRTCModule+RTCMediaStream.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "WebRTCModule+RTCMediaStream.h"; path = "RCTWebRTC/WebRTCModule+RTCMediaStream.h"; sourceTree = SOURCE_ROOT; };
79
81
  DEC96576264176C10052DB35 /* DataChannelWrapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = DataChannelWrapper.m; path = RCTWebRTC/DataChannelWrapper.m; sourceTree = "<group>"; };
80
82
  DEC96579264176DF0052DB35 /* DataChannelWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = DataChannelWrapper.h; path = RCTWebRTC/DataChannelWrapper.h; sourceTree = "<group>"; };
@@ -131,6 +133,7 @@
131
133
  4EE3A8AF25B8413200FAA24A /* VideoCaptureController.h */,
132
134
  0BDDA6DF20C18B6B00B38B45 /* VideoCaptureController.m */,
133
135
  4EE3A8B525B8414A00FAA24A /* WebRTCModule+Permissions.m */,
136
+ D7F0711D2C6DC91F0031F594 /* WebRTCModule+RTCAudioSession.m */,
134
137
  4EE3A8B825B8415900FAA24A /* WebRTCModule+RTCDataChannel.h */,
135
138
  4EE3A8B925B8415900FAA24A /* WebRTCModule+RTCDataChannel.m */,
136
139
  D7F99C122938F4E0000A2450 /* WebRTCModule+RTCMediaStream.h */,
@@ -262,6 +265,7 @@
262
265
  4EC498BC25B8777F00E76218 /* ScreenCapturePickerViewManager.m in Sources */,
263
266
  4EE3A8B225B8414000FAA24A /* WebRTCModule.m in Sources */,
264
267
  4EE3A8D225B841DD00FAA24A /* CaptureController.m in Sources */,
268
+ D7F0711E2C6DC91F0031F594 /* WebRTCModule+RTCAudioSession.m in Sources */,
265
269
  D74EF94829652169000742E1 /* TrackCapturerEventsEmitter.m in Sources */,
266
270
  4EE3A8D125B841DD00FAA24A /* SocketConnection.m in Sources */,
267
271
  4EE3A8BD25B8416500FAA24A /* WebRTCModule+RTCMediaStream.m in Sources */,
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=Constraints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["Constraints.ts"],"sourcesContent":["\nexport type MediaTrackConstraints = {\n width?: ConstrainNumber;\n height?: ConstrainNumber;\n frameRate?: ConstrainNumber;\n facingMode?: ConstrainString;\n deviceId?: ConstrainString;\n groupId?: ConstrainString;\n}\n\ntype ConstrainNumber = number | {\n exact?: number,\n ideal?: number,\n max?: number,\n min?: number,\n}\n\ntype ConstrainString = string | {\n exact?: string,\n ideal?: string,\n}"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"names":["_index","require","_reactNative","_getDisplayMedia","_interopRequireDefault","_getUserMedia","obj","__esModule","default","WebRTCModule","NativeModules","MediaDevices","EventTarget","enumerateDevices","Promise","resolve","getDisplayMedia","getUserMedia","constraints","proto","prototype","defineEventAttribute","_default","exports"],"sources":["MediaDevices.ts"],"sourcesContent":["import { EventTarget, Event, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport getDisplayMedia from './getDisplayMedia';\nimport getUserMedia from './getUserMedia';\n\nconst { WebRTCModule } = NativeModules;\n\ntype MediaDevicesEventMap = {\n devicechange: Event<'devicechange'>\n}\n\nclass MediaDevices extends EventTarget<MediaDevicesEventMap> {\n /**\n * W3C \"Media Capture and Streams\" compatible {@code enumerateDevices}\n * implementation.\n */\n enumerateDevices() {\n return new Promise(resolve => WebRTCModule.enumerateDevices(resolve));\n }\n\n /**\n * W3C \"Screen Capture\" compatible {@code getDisplayMedia} implementation.\n * See: https://w3c.github.io/mediacapture-screen-share/\n *\n * @returns {Promise}\n */\n getDisplayMedia() {\n return getDisplayMedia();\n }\n\n /**\n * W3C \"Media Capture and Streams\" compatible {@code getUserMedia}\n * implementation.\n * See: https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-enumeratedevices\n *\n * @param {*} constraints\n * @returns {Promise}\n */\n getUserMedia(constraints) {\n return getUserMedia(constraints);\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = MediaDevices.prototype;\n\ndefineEventAttribute(proto, 'devicechange');\n\n\nexport default new MediaDevices();\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,aAAA,GAAAD,sBAAA,CAAAH,OAAA;AAA0C,SAAAG,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE1C,MAAM;EAAEG;AAAa,CAAC,GAAGC,0BAAa;AAMtC,MAAMC,YAAY,SAASC,kBAAW,CAAuB;EACzD;AACJ;AACA;AACA;EACIC,gBAAgBA,CAAA,EAAG;IACf,OAAO,IAAIC,OAAO,CAACC,OAAO,IAAIN,YAAY,CAACI,gBAAgB,CAACE,OAAO,CAAC,CAAC;EACzE;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACIC,eAAeA,CAAA,EAAG;IACd,OAAO,IAAAA,wBAAe,EAAC,CAAC;EAC5B;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;EACIC,YAAYA,CAACC,WAAW,EAAE;IACtB,OAAO,IAAAD,qBAAY,EAACC,WAAW,CAAC;EACpC;AACJ;;AAEA;AACA;AACA;AACA,MAAMC,KAAK,GAAGR,YAAY,CAACS,SAAS;AAEpC,IAAAC,2BAAoB,EAACF,KAAK,EAAE,cAAc,CAAC;AAAC,IAAAG,QAAA,GAG7B,IAAIX,YAAY,CAAC,CAAC;AAAAY,OAAA,CAAAf,OAAA,GAAAc,QAAA"}
1
+ {"version":3,"names":["_index","require","_reactNative","_getDisplayMedia","_interopRequireDefault","_getUserMedia","obj","__esModule","default","WebRTCModule","NativeModules","MediaDevices","EventTarget","enumerateDevices","Promise","resolve","getDisplayMedia","getUserMedia","constraints","proto","prototype","defineEventAttribute","_default","exports"],"sources":["MediaDevices.ts"],"sourcesContent":["import { EventTarget, Event, defineEventAttribute } from 'event-target-shim/index';\nimport { NativeModules } from 'react-native';\n\nimport getDisplayMedia from './getDisplayMedia';\nimport getUserMedia, { Constraints } from './getUserMedia';\n\nconst { WebRTCModule } = NativeModules;\n\ntype MediaDevicesEventMap = {\n devicechange: Event<'devicechange'>\n}\n\nclass MediaDevices extends EventTarget<MediaDevicesEventMap> {\n /**\n * W3C \"Media Capture and Streams\" compatible {@code enumerateDevices}\n * implementation.\n */\n enumerateDevices() {\n return new Promise(resolve => WebRTCModule.enumerateDevices(resolve));\n }\n\n /**\n * W3C \"Screen Capture\" compatible {@code getDisplayMedia} implementation.\n * See: https://w3c.github.io/mediacapture-screen-share/\n *\n * @returns {Promise}\n */\n getDisplayMedia() {\n return getDisplayMedia();\n }\n\n /**\n * W3C \"Media Capture and Streams\" compatible {@code getUserMedia}\n * implementation.\n * See: https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-enumeratedevices\n *\n * @param {*} constraints\n * @returns {Promise}\n */\n getUserMedia(constraints: Constraints) {\n return getUserMedia(constraints);\n }\n}\n\n/**\n * Define the `onxxx` event handlers.\n */\nconst proto = MediaDevices.prototype;\n\ndefineEventAttribute(proto, 'devicechange');\n\n\nexport default new MediaDevices();\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,gBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,aAAA,GAAAD,sBAAA,CAAAH,OAAA;AAA2D,SAAAG,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE3D,MAAM;EAAEG;AAAa,CAAC,GAAGC,0BAAa;AAMtC,MAAMC,YAAY,SAASC,kBAAW,CAAuB;EACzD;AACJ;AACA;AACA;EACIC,gBAAgBA,CAAA,EAAG;IACf,OAAO,IAAIC,OAAO,CAACC,OAAO,IAAIN,YAAY,CAACI,gBAAgB,CAACE,OAAO,CAAC,CAAC;EACzE;;EAEA;AACJ;AACA;AACA;AACA;AACA;EACIC,eAAeA,CAAA,EAAG;IACd,OAAO,IAAAA,wBAAe,EAAC,CAAC;EAC5B;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;EACIC,YAAYA,CAACC,WAAwB,EAAE;IACnC,OAAO,IAAAD,qBAAY,EAACC,WAAW,CAAC;EACpC;AACJ;;AAEA;AACA;AACA;AACA,MAAMC,KAAK,GAAGR,YAAY,CAACS,SAAS;AAEpC,IAAAC,2BAAoB,EAACF,KAAK,EAAE,cAAc,CAAC;AAAC,IAAAG,QAAA,GAG7B,IAAIX,YAAY,CAAC,CAAC;AAAAY,OAAA,CAAAf,OAAA,GAAAc,QAAA"}
@@ -71,6 +71,8 @@ class MediaStreamTrack extends _index.EventTarget {
71
71
  *
72
72
  * This is how the reference application (AppRTCMobile) implements camera
73
73
  * switching.
74
+ *
75
+ * @deprecated Use applyConstraints instead.
74
76
  */
75
77
  _switchCamera() {
76
78
  if (this.remote) {
@@ -79,7 +81,10 @@ class MediaStreamTrack extends _index.EventTarget {
79
81
  if (this.kind !== 'video') {
80
82
  throw new Error('Only implemented for video tracks');
81
83
  }
82
- WebRTCModule.mediaStreamTrackSwitchCamera(this.id);
84
+ const constraints = (0, _RTCUtil.deepClone)(this._settings);
85
+ delete constraints.deviceId;
86
+ constraints.facingMode = this._settings.facingMode === 'user' ? 'environment' : 'user';
87
+ this.applyConstraints(constraints);
83
88
  }
84
89
  _setVideoEffect(name) {
85
90
  if (this.remote) {
@@ -116,8 +121,26 @@ class MediaStreamTrack extends _index.EventTarget {
116
121
  }
117
122
  WebRTCModule.mediaStreamTrackSetVolume(this.remote ? this._peerConnectionId : -1, this.id, volume);
118
123
  }
119
- applyConstraints() {
120
- throw new Error('Not implemented.');
124
+
125
+ /**
126
+ * Applies a new set of constraints to the track.
127
+ *
128
+ * @param constraints An object listing the constraints
129
+ * to apply to the track's constrainable properties; any existing
130
+ * constraints are replaced with the new values specified, and any
131
+ * constrainable properties not included are restored to their default
132
+ * constraints. If this parameter is omitted, all currently set custom
133
+ * constraints are cleared.
134
+ */
135
+ async applyConstraints(constraints) {
136
+ if (this.kind !== 'video') {
137
+ throw new Error('Only implemented for video tracks');
138
+ }
139
+ const normalized = (0, _RTCUtil.normalizeConstraints)({
140
+ video: constraints !== null && constraints !== void 0 ? constraints : true
141
+ });
142
+ this._settings = await WebRTCModule.mediaStreamTrackApplyConstraints(this.id, normalized.video);
143
+ this._constraints = constraints !== null && constraints !== void 0 ? constraints : {};
121
144
  }
122
145
  clone() {
123
146
  throw new Error('Not implemented.');