theta-client-react-native
Version:
This library provides a way to control RICOH THETA using.
120 lines (114 loc) • 3.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ContinuousCaptureBuilder = exports.ContinuousCapture = void 0;
var _capture = require("./capture");
var _NativeThetaClientReactNative = _interopRequireDefault(require("../NativeThetaClientReactNative"));
var _notifyController = require("../theta-repository/notify-controller");
var _options = require("../theta-repository/options");
var _thetaRepository = require("../theta-repository");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const NOTIFY_PROGRESS = 'CONTINUOUS-PROGRESS';
const NOTIFY_CAPTURING = 'CONTINUOUS-CAPTURING';
/**
* ContinuousCapture class
*/
class ContinuousCapture {
constructor(notify) {
this.notify = notify;
}
/**
* start continuous shooting
* @param onProgress the block for continuous shooting onProgress
* @param onCapturing Called when change capture status
* @return promise of captured file url
*/
async startCapture(onProgress, 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 (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.startContinuousCapture().then(result => {
resolve(result ?? undefined);
}).catch(error => {
reject(error);
}).finally(() => {
this.notify.removeNotify(NOTIFY_PROGRESS);
this.notify.removeNotify(NOTIFY_CAPTURING);
});
});
}
/**
* Get Number of shots for continuous shooting.
* @returns ContinuousNumberEnum
*/
async getContinuousNumber() {
const options = await (0, _thetaRepository.getOptions)([_options.OptionNameEnum.ContinuousNumber]);
return (options === null || options === void 0 ? void 0 : options.continuousNumber) ?? _options.ContinuousNumberEnum.UNSUPPORTED;
}
}
/**
* ContinuousCaptureBuilder class
*/
exports.ContinuousCapture = ContinuousCapture;
class ContinuousCaptureBuilder extends _capture.CaptureBuilder {
/** construct ContinuousCaptureBuilder instance */
constructor() {
super();
this.interval = undefined;
}
/**
* set interval of checking continuous shooting status command
* @param timeMillis interval
* @returns ContinuousCaptureBuilder
*/
setCheckStatusCommandInterval(timeMillis) {
this.interval = timeMillis;
return this;
}
/**
* Set photo file format.
* Continuous shooting only supports 5.5K and 11K
* @param {PhotoFileFormatEnum} fileFormat Photo file format to set
* @return PhotoCaptureBuilder
*/
setFileFormat(fileFormat) {
this.options.fileFormat = fileFormat;
return this;
}
/**
* Builds an instance of a ContinuousCapture that has all the combined
* parameters of the Options that have been added to the Builder.
* @return promise of ContinuousCapture 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.getContinuousCaptureBuilder();
await _NativeThetaClientReactNative.default.buildContinuousCapture(params);
resolve(new ContinuousCapture(_notifyController.NotifyController.instance));
} catch (error) {
reject(error);
}
});
}
}
exports.ContinuousCaptureBuilder = ContinuousCaptureBuilder;
//# sourceMappingURL=continuous-capture.js.map