Skip to content

Commit

Permalink
feat: add frame rate option for startSession
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Mar 2, 2020
1 parent bf1abc5 commit acd1e48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/react-native-webrtc-ar-session/index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const checkNativeModule = () =>
'Native Module `react-native-webrtc-ar-session` is not linked.',
)

export const startCapturingARView = () => {
export const startCapturingARView = (options = {}) => {
checkNativeModule()
return RNWebRTCARSession.startSession()
return RNWebRTCARSession.startSession(options)
}

export const stopCapturingARView = () => {
Expand Down
12 changes: 10 additions & 2 deletions packages/react-native-webrtc-ar-session/ios/RNWebRTCARSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ - (void)captureARSnapshot API_AVAILABLE(ios(11.0)){
resolve(@{});
}

RCT_EXPORT_METHOD(startSession:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
RCT_EXPORT_METHOD(startSession:(NSDictionary *)options
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject
) {
NSInteger frameRate = [options[@"frameRate"] intValue];

if (@available(iOS 11.0, *)) {
_videoSource = [WebRTCModule arVideoSource];

Expand All @@ -174,10 +179,13 @@ - (void)captureARSnapshot API_AVAILABLE(ios(11.0)){
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);

if (!frameRate) {
frameRate = _arView.preferredFramesPerSecond;
}
dispatch_source_set_timer(
self.timer,
DISPATCH_TIME_NOW,
NSEC_PER_SEC / _arView.preferredFramesPerSecond,
NSEC_PER_SEC / frameRate,
NSEC_PER_SEC
);

Expand Down

0 comments on commit acd1e48

Please # to comment.