theta-client-react-native
Version:
This library provides a way to control RICOH THETA using.
158 lines (150 loc) • 4.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TimeShiftCaptureBuilder = exports.TimeShiftCapture = 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_NAME = 'TIME-SHIFT-PROGRESS';
const NOTIFY_STOP_ERROR = 'TIME-SHIFT-STOP-ERROR';
const NOTIFY_CAPTURING = 'TIME-SHIFT-CAPTURING';
/**
* TimeShiftCapture class
*/
class TimeShiftCapture {
constructor(notify) {
this.notify = notify;
}
/**
* start time-shift
* @param onProgress the block for time-shift onProgress
* @param onStopFailed the block for error of cancelCapture
* @param onCapturing Called when change capture status
* @return promise of captured file url
*/
async startCapture(onProgress, onStopFailed, onCapturing) {
if (onProgress) {
this.notify.addNotify(NOTIFY_NAME, 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 _NativeThetaClientReactNative.default.startTimeShiftCapture().then(result => {
resolve(result ?? undefined);
}).catch(error => {
reject(error);
}).finally(() => {
this.notify.removeNotify(NOTIFY_NAME);
this.notify.removeNotify(NOTIFY_STOP_ERROR);
this.notify.removeNotify(NOTIFY_CAPTURING);
});
});
}
/**
* cancel time-shift
*/
async cancelCapture() {
return await _NativeThetaClientReactNative.default.cancelTimeShiftCapture();
}
}
/**
* TimeShiftCaptureBuilder class
*/
exports.TimeShiftCapture = TimeShiftCapture;
class TimeShiftCaptureBuilder extends _capture.CaptureBuilder {
/** construct TimeShiftCaptureBuilder instance */
constructor() {
super();
this.interval = undefined;
}
/**
* set interval of checking time-shift status command
* @param timeMillis interval
* @returns TimeShiftCaptureBuilder
*/
setCheckStatusCommandInterval(timeMillis) {
this.interval = timeMillis;
return this;
}
/**
* Set is front first.
* @param isFrontFirst is front first
* @returns TimeShiftCaptureBuilder
*/
setIsFrontFirst(isFrontFirst) {
this.checkAndInitTimeShiftSetting();
if (this.options.timeShift != null) {
this.options.timeShift.isFrontFirst = isFrontFirst;
}
return this;
}
/**
* set time (sec) before 1st lens shooting
* @param interval 1st interval
* @returns TimeShiftCaptureBuilder
*/
setFirstInterval(interval) {
this.checkAndInitTimeShiftSetting();
if (this.options.timeShift != null) {
this.options.timeShift.firstInterval = interval;
}
return this;
}
/**
* set time (sec) from 1st lens shooting until start of 2nd lens shooting.
* @param interval 2nd interval
* @returns TimeShiftCaptureBuilder
*/
setSecondInterval(interval) {
this.checkAndInitTimeShiftSetting();
if (this.options.timeShift != null) {
this.options.timeShift.secondInterval = interval;
}
return this;
}
checkAndInitTimeShiftSetting() {
if (this.options.timeShift == null) {
this.options.timeShift = {};
}
}
/**
* Builds an instance of a TimeShiftCapture that has all the combined
* parameters of the Options that have been added to the Builder.
*
* @return promise of TimeShiftCapture 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.getTimeShiftCaptureBuilder();
await _NativeThetaClientReactNative.default.buildTimeShiftCapture(params);
resolve(new TimeShiftCapture(_notifyController.NotifyController.instance));
} catch (error) {
reject(error);
}
});
}
}
exports.TimeShiftCaptureBuilder = TimeShiftCaptureBuilder;
//# sourceMappingURL=time-shift-capture.js.map