UNPKG

theta-client-react-native

Version:

This library provides a way to control RICOH THETA using.

111 lines (104 loc) 3.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PhotoCaptureBuilder = exports.PhotoCapture = void 0; var _capture = require("./capture"); var _NativeThetaClientReactNative = _interopRequireDefault(require("../NativeThetaClientReactNative")); var _notifyController = require("../theta-repository/notify-controller"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const NOTIFY_CAPTURING = 'PHOTO-CAPTURING'; /** * PhotoCapture class */ 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 _NativeThetaClientReactNative.default.takePicture(); return fileUrl ?? undefined; } catch (error) { throw error; } finally { this.notify.removeNotify(NOTIFY_CAPTURING); } } } /** * PhotoCaptureBaseBuilder class */ exports.PhotoCapture = PhotoCapture; class PhotoCaptureBuilder extends _capture.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 _NativeThetaClientReactNative.default.getPhotoCaptureBuilder(); await _NativeThetaClientReactNative.default.buildPhotoCapture(params); resolve(new PhotoCapture(_notifyController.NotifyController.instance)); } catch (error) { reject(error); } }); } } exports.PhotoCaptureBuilder = PhotoCaptureBuilder; //# sourceMappingURL=photo-capture.js.map