UNPKG

theta-client-react-native

Version:

This library provides a way to control RICOH THETA using.

103 lines (97 loc) 2.72 kB
import { PhotoCaptureBuilderBase } from './capture'; import { NativeModules } from 'react-native'; import { NotifyController } from '../theta-repository/notify-controller'; const ThetaClientReactNative = NativeModules.ThetaClientReactNative; const NOTIFY_CAPTURING = 'PHOTO-CAPTURING'; /** * PhotoCapture class */ export class PhotoCapture { constructor(notify) { this.notify = notify; } /** * Take a picture * * @param onCapturing Called when change capture status * @return promise of token file url */ async takePicture(onCapturing) { if (onCapturing) { this.notify.addNotify(NOTIFY_CAPTURING, event => { var _event$params; if ((_event$params = event.params) !== null && _event$params !== void 0 && _event$params.status) { onCapturing(event.params.status); } }); } try { const fileUrl = await ThetaClientReactNative.takePicture(); return fileUrl ?? undefined; } catch (error) { throw error; } finally { this.notify.removeNotify(NOTIFY_CAPTURING); } } } /** * PhotoCaptureBaseBuilder class */ export class PhotoCaptureBuilder extends PhotoCaptureBuilderBase { /** construct PhotoCaptureBuilder instance */ constructor() { super(); this.interval = undefined; } /** * set interval of checking take picture status command * @param timeMillis interval * @returns PhotoCaptureBuilder */ setCheckStatusCommandInterval(timeMillis) { this.interval = timeMillis; return this; } /** * Set image processing filter. * @param {FilterEnum} filter Image processing filter to set * @return PhotoCaptureBuilder */ setFilter(filter) { this.options.filter = filter; return this; } /** * Set preset mode of Theta SC2 and Theta SC2 for business. * @param {FilterEnum} preset Preset mode to set * @return PhotoCaptureBuilder */ setPreset(preset) { this.options.preset = preset; return this; } /** * Builds an instance of a PhotoCapture that has all the combined * parameters of the Options that have been added to the Builder. * * @return promise of PhotoCapture 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.getPhotoCaptureBuilder(); await ThetaClientReactNative.buildPhotoCapture(params); resolve(new PhotoCapture(NotifyController.instance)); } catch (error) { reject(error); } }); } } //# sourceMappingURL=photo-capture.js.map