UNPKG

theta-client-react-native

Version:

This library provides a way to control RICOH THETA using.

646 lines (595 loc) 18.9 kB
import ThetaClientReactNative from '../NativeThetaClientReactNative'; import { PhotoCaptureBuilder, VideoCaptureBuilder, TimeShiftCaptureBuilder, TimeShiftManualCaptureBuilder, LimitlessIntervalCaptureBuilder, ShotCountSpecifiedIntervalCaptureBuilder, CompositeIntervalCaptureBuilder, BurstCaptureBuilder, ContinuousCaptureBuilder, MultiBracketCaptureBuilder } from '../capture'; import { NotifyController } from './notify-controller'; import { EventWebSocket } from './event-websocket'; import { convertOptions, convertVideoFormatsImpl } from './libs'; export { ThetaWebApiError } from './theta-web-api-error'; const NOTIFY_API_LOG = 'API-LOG'; let apiLogListener; async function setNotifyApiLogListener(listener) { if (listener) { NotifyController.instance.addNotify(NOTIFY_API_LOG, event => { listener(event.params.message); }); } else { NotifyController.instance.removeNotify(NOTIFY_API_LOG); } await ThetaClientReactNative.setApiLogListener(listener != null); } /** * Set up a log listener for THETA API calls * * @param listener Called when there is a THETA API request and response; if undefined, unregister. */ export async function setApiLogListener(listener) { if (!NotifyController.instance.isInit()) { NotifyController.instance.init(); } apiLogListener = listener; await setNotifyApiLogListener(apiLogListener); } /** * initialize theta client sdk * * @function initialize * @param {string} endPoint optional endpoint of camera * @param {ThetaConfig} config Configuration of initialize. If null, get from THETA. * @param {ThetaTimeout} timeout Timeout of HTTP call. * @return promise of boolean result **/ export async function initialize(endPoint = 'http://192.168.1.1', config, timeout) { NotifyController.instance.init(); if (apiLogListener) { await setNotifyApiLogListener(apiLogListener); } return ThetaClientReactNative.initialize(endPoint, config ?? null, timeout ?? null); } /** * Returns whether it is initialized or not. * * @function isInitialized * @return promise of boolean result **/ export function isInitialized() { return ThetaClientReactNative.isInitialized(); } /** * Turn off/on (reboot) the camera. * Supported models are THETA A1 only. * * Error when connecting in CL mode for Japan-bound models only * * @function reboot * @return promise */ export function reboot() { return ThetaClientReactNative.reboot(); } /** * Reset all device settings and capture settings. * After reset, the camera will be restarted. * * @function reset * @return promise of boolean result */ export function reset() { return ThetaClientReactNative.reset(); } /** * Get PhotoCaptureBuilder for take a picture. * * @function getPhotoCaptureBuilder * @return created PhotoCaptureBuilder */ export function getPhotoCaptureBuilder() { return new PhotoCaptureBuilder(); } /** * Get TimeShiftCaptureBuilder for time-shift. * * @function getTimeShiftCaptureBuilder * @return created TimeShiftCaptureBuilder */ export function getTimeShiftCaptureBuilder() { return new TimeShiftCaptureBuilder(); } /** * Get TimeShiftManualCaptureBuilder for manual time-shift. * * @function getTimeShiftManualCaptureBuilder * @return created TimeShiftManualCaptureBuilder */ export function getTimeShiftManualCaptureBuilder() { return new TimeShiftManualCaptureBuilder(); } /** * Get VideoCapture.Builder for capture video. * * @function getVideoCaptureBuilder * @return created VideoCaptureBuilder instance */ export function getVideoCaptureBuilder() { return new VideoCaptureBuilder(); } /** * Get LimitlessIntervalCapture.Builder for take limitless interval shooting. * * @function getLimitlessIntervalCaptureBuilder * @return created LimitlessIntervalCaptureBuilder instance */ export function getLimitlessIntervalCaptureBuilder() { return new LimitlessIntervalCaptureBuilder(); } /** * Get ShotCountSpecifiedIntervalCapture.Builder for take interval shooting with the shot count specified. * * @function getShotCountSpecifiedIntervalCaptureBuilder * @param {shotCount} shot count specified * @return created ShotCountSpecifiedIntervalCaptureBuilder instance */ export function getShotCountSpecifiedIntervalCaptureBuilder(shotCount) { return new ShotCountSpecifiedIntervalCaptureBuilder(shotCount); } /** * Get CompositeIntervalCapture.Builder for take interval composite shooting. * * @function getCompositeIntervalCaptureBuilder * @param {shootingTimeSec} Shooting time for interval composite shooting (sec) * @return created CompositeIntervalCaptureBuilder instance */ export function getCompositeIntervalCaptureBuilder(shootingTimeSec) { return new CompositeIntervalCaptureBuilder(shootingTimeSec); } /** * Get BurstCapture.Builder for take burst shooting. * * @function getBurstCaptureBuilder * @param burstOption Burst shooting setting. * @return created BurstCaptureBuilder instance */ export function getBurstCaptureBuilder(burstCaptureNum, burstBracketStep, burstCompensation, burstMaxExposureTime, burstEnableIsoControl, burstOrder) { return new BurstCaptureBuilder(burstCaptureNum, burstBracketStep, burstCompensation, burstMaxExposureTime, burstEnableIsoControl, burstOrder); } /** * Get MultiBracketCapture.Builder for take multi bracket shooting. * * @function getMultiBracketCaptureBuilder * @return created MultiBracketCaptureBuilder instance */ export function getMultiBracketCaptureBuilder() { return new MultiBracketCaptureBuilder(); } /** * Get ContinuousCapture.Builder for take limitless interval shooting. * * @function getContinuousCaptureBuilder * @return created ContinuousCaptureBuilder instance */ export function getContinuousCaptureBuilder() { return new ContinuousCaptureBuilder(); } /** * Start live preview. * preview frame (JPEG DataURL) send THETA_EVENT_NAME event as * { * "data": "DataURL of JPEG Frame" * } * * @function StartLivePreview * @return promise of boolean result */ export function getLivePreview() { return ThetaClientReactNative.getLivePreview(); } /** * Stop live preview. * * @function StopLivePreview * @return promise of boolean result */ export function stopLivePreview() { return ThetaClientReactNative.stopLivePreview(); } /** * Restore setting to THETA * * @function restoreSettings * @return promise of boolean result */ export function restoreSettings() { return ThetaClientReactNative.restoreSettings(); } /** * Stop running self-timer. * * @function stopSelfTimer * @return promise of boolean result */ export function stopSelfTimer() { return ThetaClientReactNative.stopSelfTimer(); } /** * Converts the movie format of a saved movie. * * @function convertVideoFormats * @param {string} fileUrl URL of a saved movie file to convert * @param {boolean} toLowResolution If true generates lower resolution * video, otherwise same resolution. * @param {boolean} applyTopBottomCorrection apply Top/bottom * correction. This parameter is ignored on Theta X. * @param onProgress the block for convertVideoFormats progress * @return promise of URL of a converted movie file. */ export function convertVideoFormats(fileUrl, toLowResolution, applyTopBottomCorrection, onProgress) { return convertVideoFormatsImpl(fileUrl, toLowResolution, applyTopBottomCorrection, onProgress); } /** * Cancels the movie format conversion. * * @function cancelVideoConvert * @return promise of boolean result */ export function cancelVideoConvert() { return ThetaClientReactNative.cancelVideoConvert(); } /** * Turns the wireless LAN off. * * @function finishWlan * @return promise of boolean result */ export function finishWlan() { return ThetaClientReactNative.finishWlan(); } /** * Registers identification information (UUID) of a BLE device. * * @function setBluetoothDevice * @param {string} uuid UUID of the BLE device to set. * @return promise of String result */ export function setBluetoothDevice(uuid) { return ThetaClientReactNative.setBluetoothDevice(uuid); } /** * Returns the connected THETA model. * * @function getThetaModel * @return promise of THETA model **/ export async function getThetaModel() { const result = await ThetaClientReactNative.getThetaModel(); return result ? result : undefined; } /** * Get basic information about Theta. * * @function getThetaInfo * @return promise of ThetaInfo **/ export function getThetaInfo() { return ThetaClientReactNative.getThetaInfo(); } /** * Acquires open source license information related to the camera. * * @function getThetaLicense * @return Promise of string result, HTML string of the license. */ export function getThetaLicense() { return ThetaClientReactNative.getThetaLicense(); } /** * Get current state of Theta. * * @function getThetaState * @return promise of ThetaState **/ export function getThetaState() { return ThetaClientReactNative.getThetaState(); } /** * Lists information of images and videos in Theta. * * @function listFiles * @param {FileTypeEnum} fileType Type of the files to be listed. * @param {number} startPosition The position of the first file to be * returned in the list. 0 represents the first file. If * startPosition is larger than the position of the last file, an * empty list is returned. * @param {number} entryCount Desired number of entries to return. If * entryCount is more than the number of remaining files, just * return entries of actual remaining files. * @param {StorageEnum} storage Desired storage. If omitted, return current storage. (RICOH THETA X Version 2.00.0 or later) * @return promise with a list of file information and number of totalEntries. * see [camera.listFiles](https://github.com/ricohapi/theta-api-specs/blob/main/theta-web-api-v2.1/commands/camera.list_files.md). */ export function listFiles(fileTypeEnum, startPosition = 0, entryCount, storage) { return ThetaClientReactNative.listFiles(fileTypeEnum, startPosition, entryCount, storage ?? null); } /** * Delete files in Theta. * * @function deleteFiles * @param {string[]} fileUrls URLs of the file to be deleted. * @return promise of boolean result */ export function deleteFiles(fileUrls) { return ThetaClientReactNative.deleteFiles(fileUrls); } /** * Delete all files in Theta. * * @function deleteAllFiles * @return promise of boolean result */ export function deleteAllFiles() { return ThetaClientReactNative.deleteAllFiles(); } /** * Delete all image files in Theta. * * @function deleteAllImageFiles * @return promise of boolean result */ export function deleteAllImageFiles() { return ThetaClientReactNative.deleteAllImageFiles(); } /** * Delete all video files in Theta. * * @function deleteAllVideoFiles * @return promise of boolean result */ export function deleteAllVideoFiles() { return ThetaClientReactNative.deleteAllVideoFiles(); } /** * Acquires the properties and property support specifications for * shooting, the camera, etc. * * @function getOptions * @param {OptionNameEnum[]} optionNames List of OptionNameEnum. * @return promise of Options acquired */ export async function getOptions(optionNames) { const response = await ThetaClientReactNative.getOptions(optionNames); const { options, json } = response; const result = convertOptions(options, json); return result; } /** * Property settings for shooting, the camera, etc. * * @function setOptions * @param {Options} options Camera setting options. * @return promise of boolean result */ export function setOptions(options) { return ThetaClientReactNative.setOptions(options); } /** * Get metadata of a still image * * @function getMetadata * @param {string} fileUrl URL of a still image file to get metadata * @return promise of MetaInfo */ export function getMetadata(fileUrl) { return ThetaClientReactNative.getMetadata(fileUrl); } /** * Acquires the access point list used in client mode. * * @function listAccessPoints * @return promise of AccessPoint list */ export function listAccessPoints() { return ThetaClientReactNative.listAccessPoints(); } /** * Set access point. IP address is set dynamically. * * @function setAccessPointDynamically * @param {string} ssid SSID of the access point. * @param {} params - Optional parameters for additional configuration. * @param {boolean} params.ssidStealth true if SSID stealth is enabled. * @param {AuthModeEnum} params.authMode Authentication mode. * @param {string} params.password Password. Not set if authMode is “NONE”. * @param {number} params.connectionPriority Connection priority 1 to 5. * @param {Proxy} params.proxy Proxy information to be used for the access point. * @return promise of boolean result */ export function setAccessPointDynamically(ssid, params) { const { ssidStealth, authMode, password, connectionPriority, proxy } = params ?? {}; return ThetaClientReactNative.setAccessPointDynamically({ ssid, ssidStealth, authMode, password, connectionPriority, proxy }); } /** * Set access point. IP address is set statically. * * @function setAccessPointStatically * @param {string} ssid SSID of the access point. * @param {string} ipAddress IP address assigns to Theta. * @param {string} subnetMask Subnet mask. * @param {string} defaultGateway Default gateway. * @param {} params - Optional parameters for additional configuration. * @param {boolean} params.ssidStealth True if SSID stealth is enabled. * @param {AuthModeEnum} params.authMode Authentication mode. * @param {string} params.password Password. Not set if authMode is “NONE”. * @param {number} params.connectionPriority Connection priority 1 to 5. * @param {string} params.dns1 Primary DNS server. * @param {string} params.dns2 Secondary DNS server. * @param {Proxy} params.proxy Proxy information to be used for the access point. * @return promise of boolean result */ export function setAccessPointStatically(ssid, ipAddress, subnetMask, defaultGateway, params) { const { ssidStealth, authMode, password, connectionPriority, dns1, dns2, proxy } = params ?? {}; return ThetaClientReactNative.setAccessPointStatically({ ssid, ssidStealth, authMode, password, connectionPriority, ipAddress, subnetMask, defaultGateway, dns1, dns2, proxy }); } /** * Updates the connection priority of the access point. * * @function setAccessPointConnectionPriority * @param {string} ssid SSID of the access point. * @param {number} connectionPriority Connection priority 1 to 5. * @param {boolean} ssidStealth True if SSID stealth is enabled. * @return promise of boolean result */ export function setAccessPointConnectionPriority(ssid, connectionPriority, ssidStealth) { return ThetaClientReactNative.setAccessPointConnectionPriority(ssid, connectionPriority, ssidStealth); } /** * Deletes access point information used in client mode. * * @function deleteAccessPoint * @param {string} ssid SSID of the access point to delete. * @return promise of boolean result */ export function deleteAccessPoint(ssid) { return ThetaClientReactNative.deleteAccessPoint(ssid); } /** * Acquires the shooting properties set by the camera._setMySetting command. * Just for Theta V and later. * * @function getMySetting * @param captureMode The target shooting mode * @returns Options of my setting */ export function getMySetting(captureMode) { return ThetaClientReactNative.getMySetting(captureMode); } /** * Acquires the shooting properties set by the camera._setMySetting command. * Just for Theta S and SC. * * @function getMySetting * @param optionNames List of option names to acquire * @returns Options of my setting */ export function getMySettingFromOldModel(optionNames) { return ThetaClientReactNative.getMySettingFromOldModel(optionNames); } /** * Registers shooting conditions in My Settings * @function setMySetting * @param captureMode The target shooting mode. RICOH THETA S and SC do not support My Settings in video capture mode. * @param options registered to My Settings * @returns Promise of boolean result */ export function setMySetting(captureMode, options) { return ThetaClientReactNative.setMySetting(captureMode, options); } /** * Delete shooting conditions in My Settings. Supported just by Theta X and Z1. * @param captureMode The target shooting mode * @returns Promise of boolean result */ export function deleteMySetting(captureMode) { return ThetaClientReactNative.deleteMySetting(captureMode); } /** * Acquires a list of installed plugins * @function listPlugins * @return A list of the plugins installed in Theta. */ export function listPlugins() { return ThetaClientReactNative.listPlugins(); } /** * Sets the installed plugin for boot. Supported just by Theta V. * @function setPlugin * @param packageName Package name of the target plugin. * @return Promise of boolean result */ export function setPlugin(packageName) { return ThetaClientReactNative.setPlugin(packageName); } /** * Start the plugin specified by the [packageName]. * @function startPlugin * @param packageName Package name of the target plugin. * @return Promise of boolean result */ export function startPlugin(packageName) { return ThetaClientReactNative.startPlugin(packageName); } /** * Stop the running plugin. * @function stopPlugin * @return Promise of boolean result */ export function stopPlugin() { return ThetaClientReactNative.stopPlugin(); } /** * Acquires the license for the installed plugin. * @function getPluginLicense * @param packageName Package name of the target plugin. * @return Promise of string result, HTML string of the license. */ export function getPluginLicense(packageName) { return ThetaClientReactNative.getPluginLicense(packageName); } /** * Return the plugin orders. Supported just by Theta X and Z1. * @function getPluginOrders * @return Promise of string[] result, list of package names of plugins. */ export function getPluginOrders() { return ThetaClientReactNative.getPluginOrders(); } /** * Sets the plugin orders. Supported just by Theta X and Z1. * @function setPluginOrders * @param plugins list of package names of plugins. * For Z1, list size must be three. No restrictions for the size for X. * When not specifying, set an empty string. * If an empty string is placed mid-way, it will be moved to the front. * Specifying zero package name will result in an error * @return Promise of boolean result */ export function setPluginOrders(plugins) { return ThetaClientReactNative.setPluginOrders(plugins); } export async function getEventWebSocket() { await ThetaClientReactNative.getEventWebSocket(); return new EventWebSocket(NotifyController.instance); } //# sourceMappingURL=theta-repository.js.map