-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ios): add support for new architecture
- Loading branch information
1 parent
c9837bb
commit 340f3b5
Showing
8 changed files
with
196 additions
and
133 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// This guard prevent this file to be compiled in the old architecture. | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#import <React/RCTViewComponentView.h> | ||
#import <React/RCTConversions.h> | ||
#import <WebKit/WKDataDetectorTypes.h> | ||
#import <UIKit/UIKit.h> | ||
#import <react/renderer/components/ApiVideoLiveStreamView/Props.h> | ||
|
||
#ifndef RNLiveStreamView_h | ||
#define RNLiveStreamView_h | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RNLiveStreamView : RCTViewComponentView | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif /* RNLiveStreamView_h */ | ||
#endif /* RCT_NEW_ARCH_ENABLED */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// This guard prevent the code from being compiled in the old architecture | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#import "RNLiveStreamView.h" | ||
|
||
#import <react/renderer/components/ApiVideoLiveStreamView/ComponentDescriptors.h> | ||
#import <react/renderer/components/ApiVideoLiveStreamView/EventEmitters.h> | ||
#import <react/renderer/components/ApiVideoLiveStreamView/Props.h> | ||
#import <react/renderer/components/ApiVideoLiveStreamView/RCTComponentViewHelpers.h> | ||
|
||
#import "RCTFabricComponentsPlugins.h" | ||
|
||
// MARK: Swift classes in ObjC++ | ||
#if __has_include("react-native-livestream/react_native_livestream-Swift.h") | ||
#import "react-native-livestream/react_native_livestream-Swift.h" | ||
#else | ||
#import "react_native_livestream-Swift.h" | ||
#endif | ||
|
||
using namespace facebook::react; | ||
|
||
@class RNLiveStreamViewImpl; | ||
|
||
@interface RNLiveStreamView () <RCTApiVideoLiveStreamViewViewProtocol> | ||
|
||
@end | ||
|
||
// MARK: Implementation | ||
|
||
@implementation RNLiveStreamView { | ||
RNLiveStreamViewImpl * _view; | ||
} | ||
|
||
// MARK: Initializers | ||
- (instancetype)initWithFrame:(CGRect)frame | ||
{ | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
static const auto defaultProps = std::make_shared<const ApiVideoLiveStreamViewProps>(); | ||
_props = defaultProps; | ||
|
||
_view = [[RNLiveStreamViewImpl alloc] init]; | ||
// TODO events | ||
/*_view.onConnectionSuccess = [self]() { | ||
if (_eventEmitter) { | ||
auto liveStreamEventEmitter = std::dynamic_pointer_cast<ApiVideoLiveStreamViewEventEmitter() const>(_eventEmitter); | ||
ApiVideoLiveStreamViewEventEmitter::OnConnectionSuccess data = {}; | ||
liveStreamEventEmitter->OnConnectionSuccess(data); | ||
} | ||
}; | ||
_view.onConnectionFailed = [self](NSString* code) { | ||
if (_eventEmitter) { | ||
auto liveStreamEventEmitter = std::dynamic_pointer_cast<ApiVideoLiveStreamViewEventEmitter() const>(_eventEmitter); | ||
ApiVideoLiveStreamViewEventEmitter::OnConnectionFailed data = { | ||
.code = std::string([code UTF8String]) | ||
}; | ||
liveStreamEventEmitter->OnConnectionFailed(data); | ||
} | ||
}; | ||
_view.onDisconnect = [self]() { | ||
if (_eventEmitter) { | ||
auto liveStreamEventEmitter = std::dynamic_pointer_cast<ApiVideoLiveStreamViewEventEmitter() const>(_eventEmitter); | ||
ApiVideoLiveStreamViewEventEmitter::OnDisconnect data = {}; | ||
liveStreamEventEmitter->OnDisconnect(data); | ||
} | ||
};*/ | ||
|
||
self.contentView = _view; | ||
} | ||
return self; | ||
} | ||
|
||
// MARK: Props | ||
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps | ||
{ | ||
const auto &oldViewProps = *std::static_pointer_cast<const ApiVideoLiveStreamViewProps>(_props); | ||
const auto &newViewProps = *std::static_pointer_cast<const ApiVideoLiveStreamViewProps>(props); | ||
|
||
RNLiveStreamViewImpl *view = (RNLiveStreamViewImpl *)self.contentView; | ||
if (oldViewProps.camera != newViewProps.camera) { | ||
NSString *camera = RCTNSStringFromStringNilIfEmpty(toString(newViewProps.camera)); | ||
[view setCamera:camera]; | ||
} | ||
|
||
if ((oldViewProps.video.bitrate != newViewProps.video.bitrate) || (oldViewProps.video.fps != newViewProps.video.fps) || (oldViewProps.video.resolution != newViewProps.video.resolution) || (oldViewProps.video.gopDuration != newViewProps.video.gopDuration)) { | ||
NSString *resolution = RCTNSStringFromStringNilIfEmpty(toString(newViewProps.video.resolution)); | ||
NSDictionary *config = @{ @"bitrate" : @(newViewProps.video.bitrate), @"resolution" : resolution, @"fps" : @(newViewProps.video.fps), @"gopDuration" : @(newViewProps.video.gopDuration)}; | ||
[view setVideo:config]; | ||
} | ||
|
||
if (oldViewProps.isMuted != newViewProps.isMuted) { | ||
[view setIsMuted:newViewProps.isMuted]; | ||
} | ||
|
||
if ((oldViewProps.audio.bitrate != newViewProps.audio.bitrate) || (oldViewProps.audio.sampleRate != newViewProps.audio.sampleRate) || (oldViewProps.audio.isStereo != newViewProps.audio.isStereo)) { | ||
NSString *sampleRate = RCTNSStringFromStringNilIfEmpty(toString(newViewProps.audio.sampleRate)); | ||
NSDictionary *config = @{ @"bitrate" : @(newViewProps.audio.bitrate), @"sampleRate" : @([sampleRate intValue]), @"isStereo" : @(newViewProps.audio.isStereo)}; | ||
[view setAudio:config]; | ||
} | ||
|
||
if (oldViewProps.zoomRatio != newViewProps.zoomRatio) { | ||
[view setZoomRatio:newViewProps.zoomRatio]; | ||
} | ||
|
||
if (oldViewProps.enablePinchedZoom != newViewProps.enablePinchedZoom) { | ||
[view setEnablePinchedZoom:newViewProps.enablePinchedZoom]; | ||
} | ||
|
||
[super updateProps:props oldProps:oldProps]; | ||
} | ||
|
||
// MARK: RCTComponentViewProtocol | ||
- (void)startStreaming:(NSString *)streamKey url:(NSString *)url | ||
{ | ||
NSError *error = nil; | ||
[_view startStreaming:streamKey url:url error:&error]; | ||
|
||
} | ||
|
||
- (void)stopStreaming | ||
{ | ||
[_view stopStreaming]; | ||
} | ||
|
||
- (void)setZoomRatioCommand:(float)zoomRatio | ||
{ | ||
[_view setZoomRatioWithZoomRatio:zoomRatio]; | ||
} | ||
|
||
+ (ComponentDescriptorProvider)componentDescriptorProvider | ||
{ | ||
return concreteComponentDescriptorProvider<ApiVideoLiveStreamViewComponentDescriptor>(); | ||
} | ||
|
||
@end | ||
|
||
Class<RCTComponentViewProtocol> ApiVideoLiveStreamViewCls(void) | ||
{ | ||
return RNLiveStreamView.class; | ||
} | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.