react-native-webrtc 124.0.4 → 124.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -0
- package/android/build.gradle +3 -2
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +30 -3
- package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +180 -73
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +53 -24
- package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionNotification.java +11 -19
- package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionService.java +0 -2
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +4 -2
- package/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +25 -0
- package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +6 -4
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +20 -14
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +37 -0
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +15 -9
- package/android/src/main/java/org/webrtc/Camera1Helper.java +0 -1
- package/android/src/main/java/org/webrtc/Camera2Helper.java +4 -3
- package/ios/RCTWebRTC/CaptureController.h +3 -0
- package/ios/RCTWebRTC/CaptureController.m +12 -0
- package/ios/RCTWebRTC/I420Converter.h +22 -0
- package/ios/RCTWebRTC/I420Converter.m +164 -0
- package/ios/RCTWebRTC/PIPController.h +24 -0
- package/ios/RCTWebRTC/PIPController.m +234 -0
- package/ios/RCTWebRTC/RTCVideoViewManager.h +23 -0
- package/ios/RCTWebRTC/RTCVideoViewManager.m +131 -28
- package/ios/RCTWebRTC/SampleBufferVideoCallView.h +12 -0
- package/ios/RCTWebRTC/SampleBufferVideoCallView.m +178 -0
- package/ios/RCTWebRTC/ScreenCaptureController.m +4 -0
- package/ios/RCTWebRTC/VideoCaptureController.h +3 -0
- package/ios/RCTWebRTC/VideoCaptureController.m +95 -30
- package/ios/RCTWebRTC/WebRTCModule+Permissions.m +4 -8
- package/ios/RCTWebRTC/WebRTCModule+RTCAudioSession.m +20 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +31 -40
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +5 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +93 -28
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +26 -55
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +11 -28
- package/ios/RCTWebRTC/WebRTCModuleOptions.h +1 -0
- package/ios/RCTWebRTC/videoEffects/ProcessorProvider.h +9 -0
- package/ios/RCTWebRTC/videoEffects/ProcessorProvider.m +23 -0
- package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.h +13 -0
- package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.m +23 -0
- package/ios/RCTWebRTC/videoEffects/VideoFrameProcessor.h +8 -0
- package/ios/RCTWebRTC.xcodeproj/project.pbxproj +4 -0
- package/lib/commonjs/Constraints.js +2 -0
- package/lib/commonjs/Constraints.js.map +1 -0
- package/lib/commonjs/MediaDevices.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +31 -5
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCAudioSession.js +33 -0
- package/lib/commonjs/RTCAudioSession.js.map +1 -0
- package/lib/commonjs/RTCPIPView.js +38 -0
- package/lib/commonjs/RTCPIPView.js.map +1 -0
- package/lib/commonjs/RTCPeerConnection.js +2 -4
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCUtil.js +2 -3
- package/lib/commonjs/RTCUtil.js.map +1 -1
- package/lib/commonjs/RTCView.js.map +1 -1
- package/lib/commonjs/getUserMedia.js.map +1 -1
- package/lib/commonjs/index.js +28 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Constraints.js +2 -0
- package/lib/module/Constraints.js.map +1 -0
- package/lib/module/MediaDevices.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +32 -6
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCAudioSession.js +26 -0
- package/lib/module/RTCAudioSession.js.map +1 -0
- package/lib/module/RTCPIPView.js +26 -0
- package/lib/module/RTCPIPView.js.map +1 -0
- package/lib/module/RTCPeerConnection.js +2 -4
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCUtil.js +2 -3
- package/lib/module/RTCUtil.js.map +1 -1
- package/lib/module/RTCView.js.map +1 -1
- package/lib/module/getUserMedia.js.map +1 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/Constraints.d.ts +19 -0
- package/lib/typescript/MediaDevices.d.ts +2 -1
- package/lib/typescript/MediaStreamTrack.d.ts +27 -5
- package/lib/typescript/RTCAudioSession.d.ts +10 -0
- package/lib/typescript/RTCPIPView.d.ts +15 -0
- package/lib/typescript/RTCPeerConnection.d.ts +2 -1
- package/lib/typescript/RTCUtil.d.ts +7 -1
- package/lib/typescript/RTCView.d.ts +58 -1
- package/lib/typescript/getUserMedia.d.ts +4 -4
- package/lib/typescript/index.d.ts +5 -3
- package/package.json +2 -1
- package/src/.eslintrc.cjs +1 -1
- package/src/Constraints.ts +21 -0
- package/src/MediaDevices.ts +2 -2
- package/src/MediaStreamTrack.ts +47 -9
- package/src/RTCAudioSession.ts +25 -0
- package/src/RTCPIPView.tsx +47 -0
- package/src/RTCPeerConnection.ts +4 -5
- package/src/RTCUtil.ts +10 -3
- package/src/RTCView.ts +60 -2
- package/src/getUserMedia.ts +4 -3
- package/src/index.ts +12 -3
- package/tools/release.sh +1 -1
- package/tsconfig.json +3 -1
- package/ios/RCTWebRTC.xcodeproj/xcuserdata/saghul.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/tools/build-webrtc.py +0 -344
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#import "PIPController.h"
|
|
2
|
+
#import <AVKit/AVKit.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
|
+
if (self = [super init]) {
|
|
20
|
+
self.sourceView = sourceView;
|
|
21
|
+
|
|
22
|
+
_fallbackView = [[UIView alloc] initWithFrame:CGRectZero];
|
|
23
|
+
_fallbackView.translatesAutoresizingMaskIntoConstraints = false;
|
|
24
|
+
|
|
25
|
+
SampleBufferVideoCallView *subview = [[SampleBufferVideoCallView alloc] initWithFrame:CGRectZero];
|
|
26
|
+
_sampleView = subview;
|
|
27
|
+
_sampleView.translatesAutoresizingMaskIntoConstraints = false;
|
|
28
|
+
_pipCallViewController = [[AVPictureInPictureVideoCallViewController alloc] init];
|
|
29
|
+
|
|
30
|
+
[self addToCallViewController:_fallbackView];
|
|
31
|
+
|
|
32
|
+
_contentSource = [[AVPictureInPictureControllerContentSource alloc]
|
|
33
|
+
initWithActiveVideoCallSourceView:sourceView
|
|
34
|
+
contentViewController:_pipCallViewController];
|
|
35
|
+
|
|
36
|
+
_pipController = [[AVPictureInPictureController alloc] initWithContentSource:_contentSource];
|
|
37
|
+
_pipController.canStartPictureInPictureAutomaticallyFromInline = YES;
|
|
38
|
+
_pipController.delegate = self;
|
|
39
|
+
|
|
40
|
+
[_pipController addObserver:self
|
|
41
|
+
forKeyPath:@"pictureInPictureActive"
|
|
42
|
+
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
|
|
43
|
+
context:nil];
|
|
44
|
+
|
|
45
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
46
|
+
selector:@selector(applicationWillEnterForeground:)
|
|
47
|
+
name:UIApplicationWillEnterForegroundNotification
|
|
48
|
+
object:nil];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return self;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
- (void)observeValueForKeyPath:(NSString *)keyPath
|
|
55
|
+
ofObject:(id)object
|
|
56
|
+
change:(NSDictionary *)change
|
|
57
|
+
context:(void *)context {
|
|
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 name:UIApplicationDidBecomeActiveNotification object:nil];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@end
|
|
165
|
+
|
|
166
|
+
@implementation PIPController (AVPictureInPictureControllerDelegate)
|
|
167
|
+
|
|
168
|
+
/*!
|
|
169
|
+
@method pictureInPictureControllerWillStartPictureInPicture:
|
|
170
|
+
@param pictureInPictureController
|
|
171
|
+
The Picture in Picture controller.
|
|
172
|
+
@abstract Delegate can implement this method to be notified when Picture in Picture will start.
|
|
173
|
+
*/
|
|
174
|
+
- (void)pictureInPictureControllerWillStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
|
175
|
+
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/*!
|
|
179
|
+
@method pictureInPictureControllerDidStartPictureInPicture:
|
|
180
|
+
@param pictureInPictureController
|
|
181
|
+
The Picture in Picture controller.
|
|
182
|
+
@abstract Delegate can implement this method to be notified when Picture in Picture did start.
|
|
183
|
+
*/
|
|
184
|
+
- (void)pictureInPictureControllerDidStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
|
185
|
+
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/*!
|
|
189
|
+
@method pictureInPictureController:failedToStartPictureInPictureWithError:
|
|
190
|
+
@param pictureInPictureController
|
|
191
|
+
The Picture in Picture controller.
|
|
192
|
+
@param error
|
|
193
|
+
An error describing why it failed.
|
|
194
|
+
@abstract Delegate can implement this method to be notified when Picture in Picture failed to start.
|
|
195
|
+
*/
|
|
196
|
+
- (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController
|
|
197
|
+
failedToStartPictureInPictureWithError:(NSError *)error {
|
|
198
|
+
NSLog(@"%@: %@", NSStringFromSelector(_cmd), [error localizedDescription]); // Objective-C
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/*!
|
|
202
|
+
@method pictureInPictureControllerWillStopPictureInPicture:
|
|
203
|
+
@param pictureInPictureController
|
|
204
|
+
The Picture in Picture controller.
|
|
205
|
+
@abstract Delegate can implement this method to be notified when Picture in Picture will stop.
|
|
206
|
+
*/
|
|
207
|
+
- (void)pictureInPictureControllerWillStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
|
208
|
+
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/*!
|
|
212
|
+
@method pictureInPictureControllerDidStopPictureInPicture:
|
|
213
|
+
@param pictureInPictureController
|
|
214
|
+
The Picture in Picture controller.
|
|
215
|
+
@abstract Delegate can implement this method to be notified when Picture in Picture did stop.
|
|
216
|
+
*/
|
|
217
|
+
- (void)pictureInPictureControllerDidStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {
|
|
218
|
+
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/*!
|
|
222
|
+
@method pictureInPictureController:restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:
|
|
223
|
+
@param pictureInPictureController
|
|
224
|
+
The Picture in Picture controller.
|
|
225
|
+
@param completionHandler
|
|
226
|
+
The completion handler the delegate needs to call after restore.
|
|
227
|
+
@abstract Delegate can implement this method to restore the user interface before Picture in Picture stops.
|
|
228
|
+
*/
|
|
229
|
+
- (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController
|
|
230
|
+
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL restored))completionHandler {
|
|
231
|
+
NSLog(@"%@", NSStringFromSelector(_cmd)); // Objective-C
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@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
|
|
@@ -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,37 +15,15 @@
|
|
|
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.
|
|
46
25
|
*/
|
|
47
|
-
@interface RTCVideoView : RCTView
|
|
26
|
+
@interface RTCVideoView : RCTView<RTCVideoViewDelegate>
|
|
48
27
|
|
|
49
28
|
/**
|
|
50
29
|
* The indicator which determines whether this {@code RTCVideoView} is to mirror
|
|
@@ -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
|
*/
|
|
@@ -70,6 +53,9 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
70
53
|
@property(nonatomic, readonly) RTCMTLVideoView *videoView;
|
|
71
54
|
#endif
|
|
72
55
|
|
|
56
|
+
// Add a reference to the view manager
|
|
57
|
+
@property(nonatomic, weak) RTCVideoViewManager *viewManager;
|
|
58
|
+
|
|
73
59
|
/**
|
|
74
60
|
* The {@link RTCVideoTrack}, if any, which this instance renders.
|
|
75
61
|
*/
|
|
@@ -80,11 +66,14 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
80
66
|
*/
|
|
81
67
|
@property(nonatomic, weak) WebRTCModule *module;
|
|
82
68
|
|
|
69
|
+
@property(nonatomic, copy) RCTDirectEventBlock onDimensionsChange;
|
|
70
|
+
|
|
83
71
|
@end
|
|
84
72
|
|
|
85
73
|
@implementation RTCVideoView
|
|
86
74
|
|
|
87
75
|
@synthesize videoView = _videoView;
|
|
76
|
+
@synthesize pipController = _pipController;
|
|
88
77
|
|
|
89
78
|
/**
|
|
90
79
|
* Tells this view that its window object changed.
|
|
@@ -127,7 +116,9 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
127
116
|
RTCMTLVideoView *subview = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
|
|
128
117
|
_videoView = subview;
|
|
129
118
|
#endif
|
|
119
|
+
_objectFit = RTCVideoViewObjectFitCover;
|
|
130
120
|
[self addSubview:self.videoView];
|
|
121
|
+
self.videoView.delegate = self;
|
|
131
122
|
}
|
|
132
123
|
|
|
133
124
|
return self;
|
|
@@ -135,14 +126,14 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
135
126
|
|
|
136
127
|
#if TARGET_OS_OSX
|
|
137
128
|
- (void)layout {
|
|
138
|
-
|
|
129
|
+
[super layout];
|
|
139
130
|
#else
|
|
140
131
|
- (void)layoutSubviews {
|
|
141
|
-
|
|
132
|
+
[super layoutSubviews];
|
|
142
133
|
#endif
|
|
143
134
|
|
|
144
|
-
|
|
145
|
-
|
|
135
|
+
CGRect bounds = self.bounds;
|
|
136
|
+
self.videoView.frame = bounds;
|
|
146
137
|
}
|
|
147
138
|
|
|
148
139
|
/**
|
|
@@ -160,6 +151,66 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
160
151
|
}
|
|
161
152
|
}
|
|
162
153
|
|
|
154
|
+
- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)atIndex {
|
|
155
|
+
// All subviews are treated as fallback views
|
|
156
|
+
[_pipController insertFallbackView:subview];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
- (void)API_AVAILABLE(ios(15.0))setPIPOptions:(NSDictionary *)pipOptions {
|
|
160
|
+
if (!pipOptions) {
|
|
161
|
+
_pipController = nil;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
BOOL enabled = YES;
|
|
166
|
+
BOOL startAutomatically = YES;
|
|
167
|
+
BOOL stopAutomatically = YES;
|
|
168
|
+
|
|
169
|
+
CGSize preferredSize = CGSizeZero;
|
|
170
|
+
|
|
171
|
+
if ([pipOptions objectForKey:@"enabled"]) {
|
|
172
|
+
enabled = [pipOptions[@"enabled"] boolValue];
|
|
173
|
+
}
|
|
174
|
+
if ([pipOptions objectForKey:@"startAutomatically"]) {
|
|
175
|
+
startAutomatically = [pipOptions[@"startAutomatically"] boolValue];
|
|
176
|
+
}
|
|
177
|
+
if ([pipOptions objectForKey:@"stopAutomatically"]) {
|
|
178
|
+
stopAutomatically = [pipOptions[@"stopAutomatically"] boolValue];
|
|
179
|
+
}
|
|
180
|
+
if ([pipOptions objectForKey:@"preferredSize"]) {
|
|
181
|
+
NSDictionary *sizeDict = pipOptions[@"preferredSize"];
|
|
182
|
+
id width = sizeDict[@"width"];
|
|
183
|
+
id height = sizeDict[@"height"];
|
|
184
|
+
|
|
185
|
+
if ([width isKindOfClass:[NSNumber class]] && [height isKindOfClass:[NSNumber class]]) {
|
|
186
|
+
preferredSize = CGSizeMake([width doubleValue], [height doubleValue]);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!enabled) {
|
|
191
|
+
_pipController = nil;
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (!_pipController) {
|
|
196
|
+
_pipController = [[PIPController alloc] initWithSourceView:self];
|
|
197
|
+
_pipController.videoTrack = _videoTrack;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
_pipController.startAutomatically = startAutomatically;
|
|
201
|
+
_pipController.stopAutomatically = stopAutomatically;
|
|
202
|
+
_pipController.objectFit = _objectFit;
|
|
203
|
+
_pipController.preferredSize = preferredSize;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
- (void)API_AVAILABLE(ios(15.0))startPIP {
|
|
207
|
+
[_pipController startPIP];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
- (void)API_AVAILABLE(ios(15.0))stopPIP {
|
|
211
|
+
[_pipController stopPIP];
|
|
212
|
+
}
|
|
213
|
+
|
|
163
214
|
/**
|
|
164
215
|
* Implements the setter of the {@link #objectFit} property of this
|
|
165
216
|
* {@code RTCVideoView}.
|
|
@@ -178,6 +229,9 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
178
229
|
self.videoView.videoContentMode = UIViewContentModeScaleAspectFit;
|
|
179
230
|
}
|
|
180
231
|
#endif
|
|
232
|
+
if (@available(iOS 15.0, *)) {
|
|
233
|
+
_pipController.objectFit = fit;
|
|
234
|
+
}
|
|
181
235
|
}
|
|
182
236
|
}
|
|
183
237
|
|
|
@@ -198,6 +252,7 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
198
252
|
});
|
|
199
253
|
}
|
|
200
254
|
|
|
255
|
+
[_pipController setVideoTrack:videoTrack];
|
|
201
256
|
_videoTrack = videoTrack;
|
|
202
257
|
|
|
203
258
|
// Clear the videoView by rendering a 2x2 blank frame.
|
|
@@ -243,6 +298,18 @@ typedef NS_ENUM(NSInteger, RTCVideoViewObjectFit) {
|
|
|
243
298
|
}
|
|
244
299
|
}
|
|
245
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
|
+
|
|
246
313
|
@end
|
|
247
314
|
|
|
248
315
|
@implementation RTCVideoViewManager
|
|
@@ -252,6 +319,7 @@ RCT_EXPORT_MODULE()
|
|
|
252
319
|
- (RCTView *)view {
|
|
253
320
|
RTCVideoView *v = [[RTCVideoView alloc] init];
|
|
254
321
|
v.module = [self.bridge moduleForName:@"WebRTCModule"];
|
|
322
|
+
v.viewManager = self;
|
|
255
323
|
v.clipsToBounds = YES;
|
|
256
324
|
return v;
|
|
257
325
|
}
|
|
@@ -278,6 +346,8 @@ RCT_CUSTOM_VIEW_PROPERTY(objectFit, NSString *, RTCVideoView) {
|
|
|
278
346
|
view.objectFit = fit;
|
|
279
347
|
}
|
|
280
348
|
|
|
349
|
+
RCT_EXPORT_VIEW_PROPERTY(onDimensionsChange, RCTDirectEventBlock)
|
|
350
|
+
|
|
281
351
|
RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
|
|
282
352
|
if (!json) {
|
|
283
353
|
view.videoTrack = nil;
|
|
@@ -301,6 +371,39 @@ RCT_CUSTOM_VIEW_PROPERTY(streamURL, NSString *, RTCVideoView) {
|
|
|
301
371
|
});
|
|
302
372
|
}
|
|
303
373
|
|
|
374
|
+
RCT_CUSTOM_VIEW_PROPERTY(iosPIP, NSDictionary *, RTCVideoView) {
|
|
375
|
+
if (@available(iOS 15.0, *)) {
|
|
376
|
+
[view setPIPOptions:json];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
RCT_EXPORT_METHOD(startIOSPIP : (nonnull NSNumber *)reactTag) {
|
|
381
|
+
if (@available(iOS 15.0, *)) {
|
|
382
|
+
RCTUIManager *uiManager = [self.bridge moduleForClass:[RCTUIManager class]];
|
|
383
|
+
[uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
384
|
+
UIView *view = viewRegistry[reactTag];
|
|
385
|
+
if (!view || ![view isKindOfClass:[RTCVideoView class]]) {
|
|
386
|
+
RCTLogError(@"Cannot find RTCVideoView with tag #%@", reactTag);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
[(RTCVideoView *)view startPIP];
|
|
390
|
+
}];
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
RCT_EXPORT_METHOD(stopIOSPIP : (nonnull NSNumber *)reactTag) {
|
|
395
|
+
if (@available(iOS 15.0, *)) {
|
|
396
|
+
RCTUIManager *uiManager = [self.bridge moduleForClass:[RCTUIManager class]];
|
|
397
|
+
[uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
398
|
+
UIView *view = viewRegistry[reactTag];
|
|
399
|
+
if (!view || ![view isKindOfClass:[RTCVideoView class]]) {
|
|
400
|
+
RCTLogError(@"Cannot find RTCVideoView with tag #%@", reactTag);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
[(RTCVideoView *)view stopPIP];
|
|
404
|
+
}];
|
|
405
|
+
}
|
|
406
|
+
}
|
|
304
407
|
+ (BOOL)requiresMainQueueSetup {
|
|
305
408
|
return NO;
|
|
306
409
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#import <AVKit/AVKit.h>
|
|
2
|
+
#import <Foundation/Foundation.h>
|
|
3
|
+
#import <React/RCTViewManager.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
|