UNPKG

theta-client-react-native

Version:

This library provides a way to control RICOH THETA using.

115 lines (110 loc) 3.77 kB
import { CaptureBuilder } from './capture'; import ThetaClientReactNative from '../NativeThetaClientReactNative'; import { NotifyController } from '../theta-repository/notify-controller'; const NOTIFY_PROGRESS = 'COMPOSITE-INTERVAL-PROGRESS'; const NOTIFY_STOP_ERROR = 'COMPOSITE-INTERVAL-STOP-ERROR'; const NOTIFY_CAPTURING = 'COMPOSITE-INTERVAL-CAPTURING'; /** * CompositeIntervalCapture class */ export class CompositeIntervalCapture { constructor(notify) { this.notify = notify; } /** * start interval composite shooting * @param onProgress the block for interval composite shooting onProgress * @param onStopFailed Called when stopCapture error occurs * @param onCapturing Called when change capture status * @return promise of captured file url */ async startCapture(onProgress, onStopFailed, onCapturing) { if (onProgress) { this.notify.addNotify(NOTIFY_PROGRESS, 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.startCompositeIntervalCapture().then(result => { resolve(result ?? undefined); }).catch(error => { reject(error); }).finally(() => { this.notify.removeNotify(NOTIFY_PROGRESS); this.notify.removeNotify(NOTIFY_STOP_ERROR); this.notify.removeNotify(NOTIFY_CAPTURING); }); }); } /** * cancel interval composite shooting */ async cancelCapture() { return await ThetaClientReactNative.cancelCompositeIntervalCapture(); } } /** * CompositeIntervalCaptureBuilder class */ export class CompositeIntervalCaptureBuilder extends CaptureBuilder { /** construct CompositeIntervalCaptureBuilder instance */ constructor(shootingTimeSec) { super(); this.interval = undefined; this.shootingTimeSec = shootingTimeSec; } /** * set interval of checking interval composite shooting status command * @param timeMillis interval * @returns CompositeIntervalCaptureBuilder */ setCheckStatusCommandInterval(timeMillis) { this.interval = timeMillis; return this; } /** * Set In-progress save interval for interval composite shooting (sec). * @param {interval} sec sec. * @return CompositeIntervalCaptureBuilder */ setCompositeShootingOutputInterval(sec) { this.options.compositeShootingOutputInterval = sec; return this; } /** * Builds an instance of a CompositeIntervalCapture that has all the combined * parameters of the Options that have been added to the Builder. * @return promise of CompositeIntervalCapture 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.getCompositeIntervalCaptureBuilder(this.shootingTimeSec); await ThetaClientReactNative.buildCompositeIntervalCapture(params); resolve(new CompositeIntervalCapture(NotifyController.instance)); } catch (error) { reject(error); } }); } } //# sourceMappingURL=composite-interval-capture.js.map