UNPKG

theta-client-react-native

Version:

This library provides a way to control RICOH THETA using.

116 lines (111 loc) 4 kB
import { CaptureBuilder } from './capture'; import { NativeModules } from 'react-native'; import { NotifyController } from '../theta-repository/notify-controller'; const ThetaClientReactNative = NativeModules.ThetaClientReactNative; const NOTIFY_PROGRESS = 'SHOT-COUNT-SPECIFIED-INTERVAL-PROGRESS'; const NOTIFY_STOP_ERROR = 'SHOT-COUNT-SPECIFIED-INTERVAL-STOP-ERROR'; const NOTIFY_CAPTURING = 'SHOT-COUNT-SPECIFIED-INTERVAL-CAPTURING'; /** * ShotCountSpecifiedIntervalCapture class */ export class ShotCountSpecifiedIntervalCapture { constructor(notify) { this.notify = notify; } /** * start interval shooting with the shot count specified * @param onProgress the block for interval shooting with the shot count specified 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_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.startShotCountSpecifiedIntervalCapture().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 shooting with the shot count specified */ async cancelCapture() { return await ThetaClientReactNative.cancelShotCountSpecifiedIntervalCapture(); } } /** * ShotCountSpecifiedIntervalCaptureBuilder class */ export class ShotCountSpecifiedIntervalCaptureBuilder extends CaptureBuilder { /** construct ShotCountSpecifiedIntervalCaptureBuilder instance */ constructor(shotCount) { super(); this.interval = undefined; this.shotCount = shotCount; } /** * set interval of checking interval shooting with the shot count specified status command * @param timeMillis interval * @returns ShotCountSpecifiedIntervalCaptureBuilder */ setCheckStatusCommandInterval(timeMillis) { this.interval = timeMillis; return this; } /** * Set shooting interval (sec.) for interval shooting. * @param {interval} interval sec. * @return ShotCountSpecifiedIntervalCaptureBuilder */ setCaptureInterval(interval) { this.options.captureInterval = interval; return this; } /** * Builds an instance of a ShotCountSpecifiedIntervalCapture that has all the combined * parameters of the Options that have been added to the Builder. * @return promise of ShotCountSpecifiedIntervalCapture 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.getShotCountSpecifiedIntervalCaptureBuilder(this.shotCount); await ThetaClientReactNative.buildShotCountSpecifiedIntervalCapture(params); resolve(new ShotCountSpecifiedIntervalCapture(NotifyController.instance)); } catch (error) { reject(error); } }); } } //# sourceMappingURL=shot-count-specified-interval-capture.js.map