theta-client-react-native
Version:
This library provides a way to control RICOH THETA using.
107 lines (101 loc) • 3.17 kB
JavaScript
import { CaptureBuilder } from './capture';
import ThetaClientReactNative from '../NativeThetaClientReactNative';
import { NotifyController } from '../theta-repository/notify-controller';
const NOTIFY_NAME = 'LIMITLESS-INTERVAL-CAPTURE-STOP-ERROR';
const NOTIFY_CAPTURING = 'LIMITLESS-INTERVAL-CAPTURE-CAPTURING';
/**
* LimitlessIntervalCapture class
*/
export class LimitlessIntervalCapture {
constructor(notify) {
this.notify = notify;
}
/**
* start limitless interval capture
* @param onStopFailed the block for error of stopCapture
* @param onCapturing Called when change capture status
* @return promise of captured file url
*/
startCapture(onStopFailed, onCapturing) {
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);
}
});
}
return new Promise(async (resolve, reject) => {
await ThetaClientReactNative.startLimitlessIntervalCapture().then(result => {
resolve(result ?? undefined);
}).catch(error => {
reject(error);
}).finally(() => {
this.notify.removeNotify(NOTIFY_NAME);
this.notify.removeNotify(NOTIFY_CAPTURING);
});
});
}
/**
* stop limitless interval capture
*/
stopCapture() {
ThetaClientReactNative.stopLimitlessIntervalCapture();
}
}
/**
* LimitlessIntervalCaptureBuilder class
*/
export class LimitlessIntervalCaptureBuilder extends CaptureBuilder {
/** construct LimitlessIntervalCaptureBuilder instance */
constructor() {
super();
this.interval = undefined;
}
/**
* set interval of checking continuous shooting status command
* @param timeMillis interval
* @returns LimitlessIntervalCaptureBuilder
*/
setCheckStatusCommandInterval(timeMillis) {
this.interval = timeMillis;
return this;
}
/**
* Set shooting interval (sec.) for interval shooting.
* @param {interval} interval sec.
* @return LimitlessIntervalCaptureBuilder
*/
setCaptureInterval(interval) {
this.options.captureInterval = interval;
return this;
}
/**
* Builds an instance of a LimitlessIntervalCapture that has all the combined
* parameters of the Options that have been added to the Builder.
*
* @return promise of LimitlessIntervalCapture 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.getLimitlessIntervalCaptureBuilder();
await ThetaClientReactNative.buildLimitlessIntervalCapture(params);
resolve(new LimitlessIntervalCapture(NotifyController.instance));
} catch (error) {
reject(error);
}
});
}
}
//# sourceMappingURL=limitless-interval-capture.js.map