UNPKG

theta-client-react-native

Version:

This library provides a way to control RICOH THETA using.

126 lines (119 loc) 3.78 kB
import { CaptureBuilder } from './capture'; import ThetaClientReactNative from '../NativeThetaClientReactNative'; import { NotifyController } from '../theta-repository/notify-controller'; const NOTIFY_NAME = 'VIDEO-CAPTURE-STOP-ERROR'; const NOTIFY_CAPTURING = 'VIDEO-CAPTURE-CAPTURING'; const NOTIFY_STARTED = 'VIDEO-CAPTURE-STARTED'; /** * VideoCapture class */ export class VideoCapture { constructor(notify) { this.notify = notify; } /** * start video capture * @param onStopFailed the block for error of stopCapture * @param onCapturing Called when change capture status * @param onCaptureStarted Called when capture started * @return promise of captured file url */ startCapture(onStopFailed, onCapturing, onCaptureStarted) { if (onStopFailed) { this.notify.addNotify(NOTIFY_NAME, event => { onStopFailed(event.params); }); } 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); } }); } if (onCaptureStarted) { this.notify.addNotify(NOTIFY_STARTED, event => { var _event$params2, _event$params3; onCaptureStarted(((_event$params2 = event.params) === null || _event$params2 === void 0 ? void 0 : _event$params2.fileUrl) !== '' ? (_event$params3 = event.params) === null || _event$params3 === void 0 ? void 0 : _event$params3.fileUrl : undefined); }); } return new Promise(async (resolve, reject) => { await ThetaClientReactNative.startVideoCapture().then(result => { resolve(result ?? undefined); }).catch(error => { reject(error); }).finally(() => { this.notify.removeNotify(NOTIFY_NAME); this.notify.removeNotify(NOTIFY_CAPTURING); this.notify.removeNotify(NOTIFY_STARTED); }); }); } /** * stop video capture */ stopCapture() { ThetaClientReactNative.stopVideoCapture(); } } /** * VideoCaptureBuilder class */ export class VideoCaptureBuilder extends CaptureBuilder { /** construct VideoCaptureBuilder instance */ constructor() { super(); this.interval = undefined; } /** * set interval of checking continuous shooting status command * @param timeMillis interval * @returns VideoCaptureBuilder */ setCheckStatusCommandInterval(timeMillis) { this.interval = timeMillis; return this; } /** * Set video file format. * @param {VideoFileFormatEnum} fileFormat Video file format to set * @return VideoCaptureBuilder */ setFileFormat(fileFormat) { this.options.fileFormat = fileFormat; return this; } /** * Set maximum recordable time (in seconds) of the camera. * @param {MaxRecordableTimeEnum} time Maximum recordable time to set * @return VideoCaptureBuilder */ setMaxRecordableTime(time) { this.options.maxRecordableTime = time; return this; } /** * Builds an instance of a VideoCapture that has all the combined * parameters of the Options that have been added to the Builder. * * @return promise of VideoCapture 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.getVideoCaptureBuilder(); await ThetaClientReactNative.buildVideoCapture(params); resolve(new VideoCapture(NotifyController.instance)); } catch (error) { reject(error); } }); } } //# sourceMappingURL=video-capture.js.map