UNPKG

theta-client-react-native

Version:

This library provides a way to control RICOH THETA using.

111 lines (106 loc) 3.55 kB
import { CaptureBuilder } from './capture'; import ThetaClientReactNative from '../NativeThetaClientReactNative'; import { NotifyController } from '../theta-repository/notify-controller'; import { ContinuousNumberEnum, OptionNameEnum } from '../theta-repository/options'; import { getOptions } from '../theta-repository'; const NOTIFY_PROGRESS = 'CONTINUOUS-PROGRESS'; const NOTIFY_CAPTURING = 'CONTINUOUS-CAPTURING'; /** * ContinuousCapture class */ export class ContinuousCapture { constructor(notify) { this.notify = notify; } /** * start continuous shooting * @param onProgress the block for continuous shooting onProgress * @param onCapturing Called when change capture status * @return promise of captured file url */ async startCapture(onProgress, 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 (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.startContinuousCapture().then(result => { resolve(result ?? undefined); }).catch(error => { reject(error); }).finally(() => { this.notify.removeNotify(NOTIFY_PROGRESS); this.notify.removeNotify(NOTIFY_CAPTURING); }); }); } /** * Get Number of shots for continuous shooting. * @returns ContinuousNumberEnum */ async getContinuousNumber() { const options = await getOptions([OptionNameEnum.ContinuousNumber]); return (options === null || options === void 0 ? void 0 : options.continuousNumber) ?? ContinuousNumberEnum.UNSUPPORTED; } } /** * ContinuousCaptureBuilder class */ export class ContinuousCaptureBuilder extends CaptureBuilder { /** construct ContinuousCaptureBuilder instance */ constructor() { super(); this.interval = undefined; } /** * set interval of checking continuous shooting status command * @param timeMillis interval * @returns ContinuousCaptureBuilder */ setCheckStatusCommandInterval(timeMillis) { this.interval = timeMillis; return this; } /** * Set photo file format. * Continuous shooting only supports 5.5K and 11K * @param {PhotoFileFormatEnum} fileFormat Photo file format to set * @return PhotoCaptureBuilder */ setFileFormat(fileFormat) { this.options.fileFormat = fileFormat; return this; } /** * Builds an instance of a ContinuousCapture that has all the combined * parameters of the Options that have been added to the Builder. * @return promise of ContinuousCapture 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.getContinuousCaptureBuilder(); await ThetaClientReactNative.buildContinuousCapture(params); resolve(new ContinuousCapture(NotifyController.instance)); } catch (error) { reject(error); } }); } } //# sourceMappingURL=continuous-capture.js.map