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
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright 2023-2024 LiveKit, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package org.webrtc;
18
+
19
+ import android.hardware.camera2.CameraManager;
20
+
21
+ import androidx.annotation.Nullable;
22
+
23
+ import java.util.ArrayList;
24
+ import java.util.List;
25
+
26
+ /**
27
+ * A helper to access package-protected methods used in [Camera2Session]
28
+ * <p>
29
+ * Note: cameraId as used in the Camera2XXX classes refers to the id returned
30
+ * by [CameraManager.getCameraIdList].
31
+ */
32
+ public class Camera2Helper {
33
+
34
+ @Nullable
35
+ public static List<CameraEnumerationAndroid.CaptureFormat> getSupportedFormats(CameraManager cameraManager, @Nullable String cameraId) {
36
+ return Camera2Enumerator.getSupportedFormats(cameraManager, cameraId);
37
+ }
38
+
39
+ public static Size findClosestCaptureFormat(CameraManager cameraManager, @Nullable String cameraId, int width, int height) {
40
+ List<CameraEnumerationAndroid.CaptureFormat> formats = getSupportedFormats(cameraManager, cameraId);
41
+
42
+ List<Size> sizes = new ArrayList<>();
43
+ if (formats != null) {
44
+ for (CameraEnumerationAndroid.CaptureFormat format : formats) {
45
+ sizes.add(new Size(format.width, format.height));
46
+ }
47
+ }
48
+
49
+ return CameraEnumerationAndroid.getClosestSupportedSize(sizes, width, height);
50
+ }
51
+ }
@@ -6,9 +6,12 @@ NS_ASSUME_NONNULL_BEGIN
6
6
  @interface CaptureController : NSObject
7
7
 
8
8
  @property(nonatomic, strong) id<CapturerEventsDelegate> eventsDelegate;
9
+ @property(nonatomic, copy, nullable) NSString* deviceId;
9
10
 
10
11
  - (void)startCapture;
11
12
  - (void)stopCapture;
13
+ - (NSDictionary *)getSettings;
14
+ - (void)applyConstraints:(NSDictionary *)constraints error:(NSError **)outError;
12
15
 
13
16
  @end
14
17
 
@@ -12,6 +12,19 @@
12
12
  // subclasses needs to override
13
13
  }
14
14
 
15
+ - (NSDictionary *) getSettings {
16
+ // subclasses needs to override
17
+ return @{
18
+ @"deviceId": self.deviceId
19
+ };
20
+ }
21
+
22
+ - (void)applyConstraints:(NSDictionary *)constraints error:(NSError **)outError {
23
+ *outError = [NSError errorWithDomain:@"react-native-webrtc"
24
+ code:0
25
+ userInfo:@{ NSLocalizedDescriptionKey: @"This video track does not support applyConstraints."}];
26
+ }
27
+
15
28
  @end
16
29
 
17
30
  #endif
@@ -0,0 +1,21 @@
1
+ //
2
+ // I420Converter.h
3
+ // VideoSampleCaptureRender
4
+ //
5
+ // Adapted from: https://github.com/twilio/video-ios-affectiva/blob/ed2e864324c40ad25e5a06cc2b05298b03caed09/EmoCall/I420Converter.h
6
+ // Created by Boisy Pitre on 5/21/16.
7
+ // Copyright © 2016 Twilio. All rights reserved.
8
+ //
9
+
10
+ #import <UIKit/UIKit.h>
11
+ #import <Accelerate/Accelerate.h>
12
+ #import <WebRTC/WebRTC.h>
13
+
14
+ @interface I420Converter : NSObject
15
+
16
+ - (vImage_Error)prepareForAccelerateConversion;
17
+ - (void)unprepareForAccelerateConversion;
18
+ - (CVPixelBufferRef)convertI420ToPixelBuffer:(RTCI420Buffer *)buffer;
19
+ - (void)createPixelBufferPoolWithWidth:(size_t)width height:(size_t)height;
20
+
21
+ @end
@@ -0,0 +1,156 @@
1
+ //
2
+ // I420Converter.m
3
+ // VideoSampleCaptureRender
4
+ //
5
+ // Adapted from: https://github.com/twilio/video-ios-affectiva/blob/ed2e864324c40ad25e5a06cc2b05298b03caed09/EmoCall/I420Converter.m
6
+ // Created by Boisy Pitre on 5/21/16.
7
+ // Copyright © 2016 Twilio. All rights reserved.
8
+ //
9
+
10
+ #import "I420Converter.h"
11
+
12
+ @interface I420Converter()
13
+
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;
18
+ @end
19
+
20
+ @implementation I420Converter
21
+
22
+ - (vImage_Error)prepareForAccelerateConversion
23
+ {
24
+ // Setup the YpCbCr to ARGB conversion.
25
+ if (_conversionInfo != NULL) {
26
+ return kvImageNoError;
27
+ }
28
+
29
+ // I420 uses limited range.
30
+ vImage_YpCbCrPixelRange pixelRange = { 16, 128, 235, 240, 255, 0, 255, 0 };
31
+ vImage_YpCbCrToARGB *outInfo = malloc(sizeof(vImage_YpCbCrToARGB));
32
+ vImageYpCbCrType inType = kvImage420Yp8_Cb8_Cr8;
33
+ vImageARGBType outType = kvImageARGB8888;
34
+
35
+ vImage_Error error = vImageConvert_YpCbCrToARGB_GenerateConversion(kvImage_YpCbCrToARGBMatrix_ITU_R_601_4,
36
+ &pixelRange,
37
+ outInfo,
38
+ inType,
39
+ outType,
40
+ kvImagePrintDiagnosticsToConsole);
41
+
42
+ _conversionInfo = outInfo;
43
+
44
+ return error;
45
+ }
46
+
47
+ - (void)unprepareForAccelerateConversion
48
+ {
49
+ if (_conversionInfo != NULL) {
50
+ free(_conversionInfo);
51
+ _conversionInfo = NULL;
52
+ }
53
+ if (_pixelBufferPool != NULL) {
54
+ CVPixelBufferPoolRelease(_pixelBufferPool);
55
+ _pixelBufferPool = NULL;
56
+ }
57
+ }
58
+
59
+ - (void)createPixelBufferPoolWithWidth:(size_t)width height:(size_t)height {
60
+ if (_pixelBufferPool != NULL) {
61
+ CVPixelBufferPoolRelease(_pixelBufferPool);
62
+ }
63
+
64
+ _poolWidth = width;
65
+ _poolHeight = height;
66
+ NSDictionary *pixelBufferAttributes = @{
67
+ (id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA),
68
+ (id)kCVPixelBufferWidthKey: @(width),
69
+ (id)kCVPixelBufferHeightKey: @(height),
70
+ (id)kCVPixelBufferIOSurfacePropertiesKey: @{}
71
+ };
72
+
73
+ CVReturn ret = CVPixelBufferPoolCreate(kCFAllocatorDefault, NULL, (__bridge CFDictionaryRef)pixelBufferAttributes, &_pixelBufferPool);
74
+
75
+ if (ret != kCVReturnSuccess) {
76
+ NSLog(@"Error creating pixel buffer pool: %d", ret);
77
+ _pixelBufferPool = NULL;
78
+ }
79
+ }
80
+
81
+ - (CVPixelBufferRef)convertI420ToPixelBuffer:(RTCI420Buffer *)buffer
82
+ {
83
+ if (_conversionInfo == nil) {
84
+ NSLog(@"%@: not prepared", NSStringFromSelector(_cmd));
85
+ return NULL;
86
+ }
87
+
88
+ if (_pixelBufferPool == NULL || _poolWidth != buffer.width || _poolHeight != buffer.height) {
89
+ [self createPixelBufferPoolWithWidth:buffer.width height:buffer.height];
90
+ }
91
+
92
+ CVPixelBufferRef pixelBuffer = NULL;
93
+ CVReturn status = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, _pixelBufferPool, &pixelBuffer);
94
+
95
+ if (status != kCVReturnSuccess) {
96
+ return NULL;
97
+ }
98
+
99
+ vImage_Error err = [self convertFrameVImageYUV:buffer toBuffer:pixelBuffer];
100
+
101
+ if(err != kvImageNoError) {
102
+ NSLog(@"%@: error during conversion: %ld", NSStringFromSelector(_cmd), err);
103
+ CVPixelBufferRelease(pixelBuffer);
104
+ return NULL;
105
+ }
106
+
107
+ return pixelBuffer;
108
+ }
109
+
110
+ - (vImage_Error)convertFrameVImageYUV:(RTCI420Buffer *)buffer toBuffer:(CVPixelBufferRef)pixelBufferRef
111
+ {
112
+ if (pixelBufferRef == NULL) {
113
+ return kvImageInvalidParameter;
114
+ }
115
+
116
+ // Compute info for I420 source.
117
+ vImagePixelCount width = buffer.width;
118
+ vImagePixelCount height = buffer.height;
119
+ vImagePixelCount subsampledWidth = buffer.chromaWidth;
120
+ vImagePixelCount subsampledHeight = buffer.chromaHeight;
121
+
122
+ const uint8_t *yPlane = buffer.dataY;
123
+ const uint8_t *uPlane = buffer.dataU;
124
+ const uint8_t *vPlane = buffer.dataV;
125
+ size_t yStride = (size_t)buffer.strideY;
126
+ size_t uStride = (size_t)buffer.strideU;
127
+ size_t vStride = (size_t)buffer.strideV;
128
+
129
+ // Create vImage buffers to represent each of the Y, U, and V planes
130
+ 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
+
134
+ // Create a vImage buffer for the destination pixel buffer.
135
+ CVPixelBufferLockBaseAddress(pixelBufferRef, 0);
136
+
137
+ void *pixelBufferData = CVPixelBufferGetBaseAddress(pixelBufferRef);
138
+ size_t rowBytes = CVPixelBufferGetBytesPerRow(pixelBufferRef);
139
+ vImage_Buffer destinationImageBuffer = {.data = pixelBufferData, .height = height, .width = width, .rowBytes = rowBytes};
140
+
141
+ // 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
+
146
+ CVPixelBufferUnlockBaseAddress(pixelBufferRef, 0);
147
+
148
+ return convertError;
149
+ }
150
+
151
+ - (void)dealloc {
152
+ [self unprepareForAccelerateConversion];
153
+ CVPixelBufferPoolRelease(_pixelBufferPool);
154
+ }
155
+
156
+ @end
@@ -0,0 +1,24 @@
1
+ #import <UIKit/UIKit.h>
2
+ #import <WebRTC/RTCVideoTrack.h>
3
+ #import <AVKit/AVKit.h>
4
+
5
+ #import "RTCVideoViewManager.h"
6
+
7
+ API_AVAILABLE(ios(15.0))
8
+ @interface PIPController : NSObject <AVPictureInPictureControllerDelegate>
9
+
10
+ @property(nonatomic, weak) UIView *sourceView;
11
+ @property(nonatomic, strong) RTCVideoTrack *videoTrack;
12
+
13
+ @property(nonatomic, assign) BOOL startAutomatically;
14
+ @property(nonatomic, assign) BOOL stopAutomatically;
15
+ @property(nonatomic, assign) CGSize preferredSize;
16
+
17
+ - (instancetype)initWithSourceView:(UIView *)sourceView;
18
+ - (void)togglePIP;
19
+ - (void)startPIP;
20
+ - (void)stopPIP;
21
+ - (void)insertFallbackView:(UIView *)subview;
22
+ - (void)setObjectFit:(RTCVideoViewObjectFit)fit;
23
+
24
+ @end
@@ -0,0 +1,242 @@
1
+ #import <AVKit/AVKit.h>
2
+ #import "PIPController.h"
3
+ #import "SampleBufferVideoCallView.h"
4
+
5
+ @interface PIPController ()
6
+
7
+ @property(nonatomic, strong) AVPictureInPictureVideoCallViewController *pipCallViewController;
8
+ @property(nonatomic, strong) AVPictureInPictureControllerContentSource *contentSource;
9
+ @property(nonatomic, strong) AVPictureInPictureController *pipController;
10
+ @property(nonnull, nonatomic, strong) SampleBufferVideoCallView *sampleView;
11
+
12
+ @property(nonnull, nonatomic, strong) UIView *fallbackView;
13
+
14
+ @end
15
+
16
+ @implementation PIPController
17
+
18
+ - (instancetype)initWithSourceView:(UIView *)sourceView {
19
+
20
+ if (self = [super init]) {
21
+ self.sourceView = sourceView;
22
+
23
+ _fallbackView = [[UIView alloc] initWithFrame:CGRectZero];
24
+ _fallbackView.translatesAutoresizingMaskIntoConstraints = false;
25
+
26
+ SampleBufferVideoCallView * subview = [[SampleBufferVideoCallView alloc] initWithFrame:CGRectZero];
27
+ _sampleView = subview;
28
+ _sampleView.translatesAutoresizingMaskIntoConstraints = false;
29
+ _pipCallViewController = [[AVPictureInPictureVideoCallViewController alloc] init];
30
+
31
+ [self addToCallViewController:_fallbackView];
32
+
33
+ _contentSource = [[AVPictureInPictureControllerContentSource alloc] initWithActiveVideoCallSourceView:sourceView contentViewController:_pipCallViewController];
34
+
35
+ _pipController = [[AVPictureInPictureController alloc] initWithContentSource:_contentSource];
36
+ _pipController.canStartPictureInPictureAutomaticallyFromInline = YES;
37
+ _pipController.delegate = self;
38
+
39
+ [_pipController addObserver:self
40
+ forKeyPath:@"pictureInPictureActive"
41
+ options:NSKeyValueObservingOptionInitial|NSKeyValueObservingOptionNew
42
+ context:nil];
43
+
44
+ [[NSNotificationCenter defaultCenter] addObserver:self
45
+ selector:@selector(applicationWillEnterForeground:)
46
+ name:UIApplicationWillEnterForegroundNotification
47
+ object:nil];
48
+ }
49
+
50
+ return self;
51
+ }
52
+
53
+ - (void)observeValueForKeyPath:(NSString *)keyPath
54
+ ofObject:(id)object
55
+ change:(NSDictionary *)change
56
+ context:(void *)context
57
+ {
58
+ if([keyPath isEqualToString:@"pictureInPictureActive"]) {
59
+ _sampleView.shouldRender = [change[NSKeyValueChangeNewKey] boolValue];
60
+ }
61
+ }
62
+
63
+ - (void)applicationWillEnterForeground:(NSNotification *)notification {
64
+ if (_stopAutomatically) {
65
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
66
+ [self.pipController stopPictureInPicture];
67
+ });
68
+ }
69
+ }
70
+
71
+ - (void)addToCallViewController:(UIView *)view {
72
+ [_pipCallViewController.view addSubview:view];
73
+ NSArray *constraints = @[
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]
78
+ ];
79
+ [NSLayoutConstraint activateConstraints:constraints];
80
+ }
81
+
82
+ - (void)setVideoTrack:(RTCVideoTrack *)videoTrack {
83
+ if (_videoTrack != videoTrack) {
84
+ [_videoTrack removeRenderer:_sampleView];
85
+ }
86
+
87
+ _videoTrack = videoTrack;
88
+ [videoTrack addRenderer:_sampleView];
89
+
90
+ if (_videoTrack) {
91
+ if (!_sampleView.superview) {
92
+ [self addToCallViewController:_sampleView];
93
+ }
94
+ if (_fallbackView.superview) {
95
+ [_fallbackView removeFromSuperview];
96
+ }
97
+ } else {
98
+ if (!_fallbackView.superview) {
99
+ [self addToCallViewController:_fallbackView];
100
+ }
101
+ if (_sampleView.superview) {
102
+ [_sampleView removeFromSuperview];
103
+ }
104
+ }
105
+ }
106
+
107
+ - (void)insertFallbackView:(UIView *)view {
108
+ [self.fallbackView addSubview:view];
109
+ }
110
+
111
+ - (void)setObjectFit:(RTCVideoViewObjectFit)fit {
112
+ if (fit == RTCVideoViewObjectFitCover) {
113
+ self.sampleView.sampleBufferLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
114
+ } else {
115
+ self.sampleView.sampleBufferLayer.videoGravity = AVLayerVideoGravityResizeAspect;
116
+ }
117
+ }
118
+
119
+ - (CGSize)preferredSize {
120
+ return _pipCallViewController.preferredContentSize;
121
+ }
122
+
123
+ - (void)setPreferredSize:(CGSize)size {
124
+ if (!CGSizeEqualToSize(size, _pipCallViewController.preferredContentSize)) {
125
+ _pipCallViewController.preferredContentSize = size;
126
+ [_sampleView requestScaleRecalculation];
127
+ }
128
+ }
129
+
130
+ - (BOOL)startAutomatically {
131
+ return _pipController.canStartPictureInPictureAutomaticallyFromInline;
132
+ }
133
+
134
+ - (void)setStartAutomatically:(BOOL)value {
135
+ _pipController.canStartPictureInPictureAutomaticallyFromInline = value;
136
+ }
137
+
138
+ - (void)togglePIP {
139
+ if(_pipController.isPictureInPictureActive) {
140
+ [_pipController stopPictureInPicture];
141
+ } else if(_pipController.isPictureInPicturePossible){
142
+ [_pipController startPictureInPicture];
143
+ }
144
+ }
145
+
146
+ - (void)startPIP {
147
+ if (_pipController.isPictureInPicturePossible) {
148
+ [_pipController startPictureInPicture];
149
+ }
150
+ }
151
+
152
+ - (void)stopPIP {
153
+ if(_pipController.isPictureInPictureActive) {
154
+ [_pipController stopPictureInPicture];
155
+ }
156
+ }
157
+
158
+ - (void)dealloc {
159
+ [_videoTrack removeRenderer:_sampleView];
160
+ [_pipController removeObserver:self forKeyPath:@"pictureInPictureActive"];
161
+ [[NSNotificationCenter defaultCenter] removeObserver:self
162
+ name:UIApplicationDidBecomeActiveNotification
163
+ object:nil];
164
+ }
165
+
166
+ @end
167
+
168
+ @implementation PIPController (AVPictureInPictureControllerDelegate)
169
+
170
+
171
+ /*!
172
+ @method pictureInPictureControllerWillStartPictureInPicture:
173
+ @param pictureInPictureController
174
+ The Picture in Picture controller.
175
+ @abstract Delegate can implement this method to be notified when Picture in Picture will start.
176
+ */
177
+ - (void)pictureInPictureControllerWillStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
178
+
179
+ NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
180
+ }
181
+
182
+ /*!
183
+ @method pictureInPictureControllerDidStartPictureInPicture:
184
+ @param pictureInPictureController
185
+ The Picture in Picture controller.
186
+ @abstract Delegate can implement this method to be notified when Picture in Picture did start.
187
+ */
188
+ - (void)pictureInPictureControllerDidStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
189
+
190
+ NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
191
+ }
192
+
193
+ /*!
194
+ @method pictureInPictureController:failedToStartPictureInPictureWithError:
195
+ @param pictureInPictureController
196
+ The Picture in Picture controller.
197
+ @param error
198
+ An error describing why it failed.
199
+ @abstract Delegate can implement this method to be notified when Picture in Picture failed to start.
200
+ */
201
+ - (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController failedToStartPictureInPictureWithError:(NSError *)error{
202
+
203
+ NSLog(@"%@: %@", NSStringFromSelector(_cmd), [error localizedDescription]); // Objective-C
204
+ }
205
+
206
+ /*!
207
+ @method pictureInPictureControllerWillStopPictureInPicture:
208
+ @param pictureInPictureController
209
+ The Picture in Picture controller.
210
+ @abstract Delegate can implement this method to be notified when Picture in Picture will stop.
211
+ */
212
+ - (void)pictureInPictureControllerWillStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
213
+
214
+ NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
215
+ }
216
+
217
+ /*!
218
+ @method pictureInPictureControllerDidStopPictureInPicture:
219
+ @param pictureInPictureController
220
+ The Picture in Picture controller.
221
+ @abstract Delegate can implement this method to be notified when Picture in Picture did stop.
222
+ */
223
+ - (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
224
+
225
+ NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
226
+ }
227
+
228
+ /*!
229
+ @method pictureInPictureController:restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:
230
+ @param pictureInPictureController
231
+ The Picture in Picture controller.
232
+ @param completionHandler
233
+ The completion handler the delegate needs to call after restore.
234
+ @abstract Delegate can implement this method to restore the user interface before Picture in Picture stops.
235
+ */
236
+ - (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler {
237
+
238
+ NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
239
+ }
240
+
241
+
242
+ @end
@@ -1,6 +1,29 @@
1
1
  #import <Foundation/Foundation.h>
2
2
  #import <React/RCTViewManager.h>
3
3
 
4
+ /**
5
+ * In the fashion of
6
+ * https://www.w3.org/TR/html5/embedded-content-0.html#dom-video-videowidth
7
+ * and https://www.w3.org/TR/html5/rendering.html#video-object-fit, resembles
8
+ * the CSS style {@code object-fit}.
9
+ */
10
+ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
11
+ /**
12
+ * The contain value defined by https://www.w3.org/TR/css3-images/#object-fit:
13
+ *
14
+ * The replaced content is sized to maintain its aspect ratio while fitting
15
+ * within the element's content box.
16
+ */
17
+ RTCVideoViewObjectFitContain = 1,
18
+ /**
19
+ * The cover value defined by https://www.w3.org/TR/css3-images/#object-fit:
20
+ *
21
+ * The replaced content is sized to maintain its aspect ratio while filling
22
+ * the element's entire content box.
23
+ */
24
+ RTCVideoViewObjectFitCover
25
+ };
26
+
4
27
  @interface RTCVideoViewManager : RCTViewManager
5
28
 
6
29
  @end