diff --git a/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m b/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m index d1e122c26..451e1f7ce 100644 --- a/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +++ b/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m @@ -111,10 +111,10 @@ - (RTCVideoTrack *)createVideoTrack:(NSDictionary *)constraints { return nil; #else - RTCVideoSource *videoSource = [self.peerConnectionFactory videoSource]; + self.videoSource = [self.peerConnectionFactory videoSource]; NSString *trackUUID = [[NSUUID UUID] UUIDString]; - RTCVideoTrack *videoTrack = [self.peerConnectionFactory videoTrackWithSource:videoSource trackId:trackUUID]; + RTCVideoTrack *videoTrack = [self.peerConnectionFactory videoTrackWithSource:self.videoSource trackId:trackUUID]; #if !TARGET_IPHONE_SIMULATOR NSDictionary *videoContraints = constraints[@"video"]; @@ -122,7 +122,7 @@ - (RTCVideoTrack *)createVideoTrack:(NSDictionary *)constraints { RTCCameraVideoCapturer *videoCapturer; RCTLog(@"Video constraint in create video track: %@", videoContraints); - self.videoSourceInterceptor = [[WebRTCVideoCaptureHandler alloc] initWithSource:videoSource backgroundImageData:nil]; + self.videoSourceInterceptor = [[WebRTCVideoCaptureHandler alloc] initWithSource:self.videoSource backgroundImageData:nil]; videoCapturer = [[RTCCameraVideoCapturer alloc] initWithDelegate:self.videoSourceInterceptor]; self.videoCaptureController = [[VideoCaptureController alloc] initWithCapturer:videoCapturer @@ -203,6 +203,12 @@ - (RTCVideoTrack *)createScreenCaptureVideoTrack { : (RCTResponseSenderBlock)successCallback errorCallback : (RCTResponseSenderBlock)errorCallback) { // If virtual backround is enabled, use video source interceptor before video source + int width = [constraints[@"width"] intValue]; + int height = [constraints[@"height"] intValue]; + int frameRate = [constraints[@"frameRate"] intValue]; + + [self.videoSource adaptOutputFormatToWidth:width height:height fps:frameRate]; + if (constraints[@"enableBlurBackgroud"]) { [self.videoSourceInterceptor enableWithBlur:YES backgroundImageData:nil]; } else if (constraints[@"enableVirtualBackgroud"]) { diff --git a/ios/RCTWebRTC/WebRTCModule.h b/ios/RCTWebRTC/WebRTCModule.h index 040dfde99..791a99ef5 100644 --- a/ios/RCTWebRTC/WebRTCModule.h +++ b/ios/RCTWebRTC/WebRTCModule.h @@ -35,8 +35,9 @@ static NSString *const kEventPeerConnectionOnTrack = @"peerConnectionOnTrack"; @property(nonatomic, strong) NSMutableDictionary *localStreams; @property(nonatomic, strong) NSMutableDictionary *localTracks; @property (nonatomic, strong) id videoSourceInterceptor; +@property (nonatomic, strong) RTCVideoSource *videoSource; @property (nonatomic, strong) VideoCaptureController *videoCaptureController; - (RTCMediaStream *)streamForReactTag:(NSString *)reactTag; -@end +@end \ No newline at end of file