theta-client-react-native
Version:
This library provides a way to control RICOH THETA using.
122 lines (117 loc) • 3.98 kB
JavaScript
import { CaptureBuilder } from './capture';
import { NotifyController } from '../theta-repository/notify-controller';
import ThetaClientReactNative from '../NativeThetaClientReactNative';
const NOTIFY_PROGRESS = 'BURST-PROGRESS';
const NOTIFY_STOP_ERROR = 'BURST-STOP-ERROR';
const NOTIFY_CAPTURING = 'BURST-CAPTURING';
/**
* BurstCapture class
*/
export class BurstCapture {
constructor(notify) {
this.notify = notify;
}
/**
* start burst shooting
* @param onProgress the block for burst shooting onProgress
* @param onStopFailed Called when stopCapture error occurs
* @param onCapturing Called when change capture status
* @return promise of captured file url
*/
async startCapture(onProgress, onStopFailed, 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 (onStopFailed) {
this.notify.addNotify(NOTIFY_STOP_ERROR, event => {
onStopFailed(event.params);
});
}
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.startBurstCapture().then(result => {
resolve(result ?? undefined);
}).catch(error => {
reject(error);
}).finally(() => {
this.notify.removeNotify(NOTIFY_PROGRESS);
this.notify.removeNotify(NOTIFY_STOP_ERROR);
this.notify.removeNotify(NOTIFY_CAPTURING);
});
});
}
/**
* cancel burst shooting
*/
async cancelCapture() {
return await ThetaClientReactNative.cancelBurstCapture();
}
}
/**
* BurstCaptureBuilder class
*/
export class BurstCaptureBuilder extends CaptureBuilder {
/** construct BurstCaptureBuilder instance */
constructor(burstCaptureNum, burstBracketStep, burstCompensation, burstMaxExposureTime, burstEnableIsoControl, burstOrder) {
super();
this.interval = undefined;
this.burstCaptureNum = burstCaptureNum;
this.burstBracketStep = burstBracketStep;
this.burstCompensation = burstCompensation;
this.burstMaxExposureTime = burstMaxExposureTime;
this.burstEnableIsoControl = burstEnableIsoControl;
this.burstOrder = burstOrder;
}
/**
* set interval of checking burst shooting status command
* @param timeMillis interval
* @returns BurstCaptureBuilder
*/
setCheckStatusCommandInterval(timeMillis) {
this.interval = timeMillis;
return this;
}
/**
* BurstMode setting.
* When this is set to ON, burst shooting is enabled,
* and a screen dedicated to burst shooting is displayed in Live View.
* @param mode BurstMode
* @return BurstCaptureBuilder
*/
setBurstMode(mode) {
this.options.burstMode = mode;
return this;
}
/**
* Builds an instance of a BurstCapture that has all the combined
* parameters of the Options that have been added to the Builder.
* @return promise of BurstCapture 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.getBurstCaptureBuilder(this.burstCaptureNum, this.burstBracketStep, this.burstCompensation, this.burstMaxExposureTime, this.burstEnableIsoControl, this.burstOrder);
await ThetaClientReactNative.buildBurstCapture(params);
resolve(new BurstCapture(NotifyController.instance));
} catch (error) {
reject(error);
}
});
}
}
//# sourceMappingURL=burst-capture.js.map