theta-client-react-native
Version:
This library provides a way to control RICOH THETA using.
135 lines (127 loc) • 4.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.VideoCaptureBuilder = exports.VideoCapture = 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 = 'VIDEO-CAPTURE-STOP-ERROR';
const NOTIFY_CAPTURING = 'VIDEO-CAPTURE-CAPTURING';
const NOTIFY_STARTED = 'VIDEO-CAPTURE-STARTED';
/**
* VideoCapture class
*/
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 _NativeThetaClientReactNative.default.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() {
_NativeThetaClientReactNative.default.stopVideoCapture();
}
}
/**
* VideoCaptureBuilder class
*/
exports.VideoCapture = VideoCapture;
class VideoCaptureBuilder extends _capture.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 _NativeThetaClientReactNative.default.getVideoCaptureBuilder();
await _NativeThetaClientReactNative.default.buildVideoCapture(params);
resolve(new VideoCapture(_notifyController.NotifyController.instance));
} catch (error) {
reject(error);
}
});
}
}
exports.VideoCaptureBuilder = VideoCaptureBuilder;
//# sourceMappingURL=video-capture.js.map