UNPKG

theta-client-react-native

Version:

This library provides a way to control RICOH THETA using.

149 lines (142 loc) 4.32 kB
import { CaptureBuilder } from './capture'; import ThetaClientReactNative from '../NativeThetaClientReactNative'; import { NotifyController } from '../theta-repository/notify-controller'; const NOTIFY_NAME = 'TIME-SHIFT-PROGRESS'; const NOTIFY_STOP_ERROR = 'TIME-SHIFT-STOP-ERROR'; const NOTIFY_CAPTURING = 'TIME-SHIFT-CAPTURING'; /** * TimeShiftCapture class */ export class TimeShiftCapture { constructor(notify) { this.notify = notify; } /** * start time-shift * @param onProgress the block for time-shift onProgress * @param onStopFailed the block for error of cancelCapture * @param onCapturing Called when change capture status * @return promise of captured file url */ async startCapture(onProgress, onStopFailed, onCapturing) { if (onProgress) { this.notify.addNotify(NOTIFY_NAME, event => { var _event$params; onProgress((_event$params = event.params) === null || _event$params === void 0 ? void 0 : _event$params.completion); }); } if (onStopFailed) { this.notify.addNotify(NOTIFY_STOP_ERROR, event => { onStopFailed(event.params); }); } if (onCapturing) { this.notify.addNotify(NOTIFY_CAPTURING, event => { var _event$params2; if ((_event$params2 = event.params) !== null && _event$params2 !== void 0 && _event$params2.status) { onCapturing(event.params.status); } }); } return new Promise(async (resolve, reject) => { await ThetaClientReactNative.startTimeShiftCapture().then(result => { resolve(result ?? undefined); }).catch(error => { reject(error); }).finally(() => { this.notify.removeNotify(NOTIFY_NAME); this.notify.removeNotify(NOTIFY_STOP_ERROR); this.notify.removeNotify(NOTIFY_CAPTURING); }); }); } /** * cancel time-shift */ async cancelCapture() { return await ThetaClientReactNative.cancelTimeShiftCapture(); } } /** * TimeShiftCaptureBuilder class */ export class TimeShiftCaptureBuilder extends CaptureBuilder { /** construct TimeShiftCaptureBuilder instance */ constructor() { super(); this.interval = undefined; } /** * set interval of checking time-shift status command * @param timeMillis interval * @returns TimeShiftCaptureBuilder */ setCheckStatusCommandInterval(timeMillis) { this.interval = timeMillis; return this; } /** * Set is front first. * @param isFrontFirst is front first * @returns TimeShiftCaptureBuilder */ setIsFrontFirst(isFrontFirst) { this.checkAndInitTimeShiftSetting(); if (this.options.timeShift != null) { this.options.timeShift.isFrontFirst = isFrontFirst; } return this; } /** * set time (sec) before 1st lens shooting * @param interval 1st interval * @returns TimeShiftCaptureBuilder */ setFirstInterval(interval) { this.checkAndInitTimeShiftSetting(); if (this.options.timeShift != null) { this.options.timeShift.firstInterval = interval; } return this; } /** * set time (sec) from 1st lens shooting until start of 2nd lens shooting. * @param interval 2nd interval * @returns TimeShiftCaptureBuilder */ setSecondInterval(interval) { this.checkAndInitTimeShiftSetting(); if (this.options.timeShift != null) { this.options.timeShift.secondInterval = interval; } return this; } checkAndInitTimeShiftSetting() { if (this.options.timeShift == null) { this.options.timeShift = {}; } } /** * Builds an instance of a TimeShiftCapture that has all the combined * parameters of the Options that have been added to the Builder. * * @return promise of TimeShiftCapture instance */ build() { let params = { ...this.options, // Cannot pass negative values in IOS, use objects _capture_interval: this.interval ?? -1 }; return new Promise(async (resolve, reject) => { try { await ThetaClientReactNative.getTimeShiftCaptureBuilder(); await ThetaClientReactNative.buildTimeShiftCapture(params); resolve(new TimeShiftCapture(NotifyController.instance)); } catch (error) { reject(error); } }); } } //# sourceMappingURL=time-shift-capture.js.map