UNPKG

tethr

Version:

Controlls USB-connected cameras, webcam, and smartphone camera from browser

578 lines 18.6 kB
import EventEmitter from 'eventemitter3'; import { ConfigNameList, } from './configs'; import { isntNil, UnsupportedConfigDesc, UnsupportedOperationResult, } from './util'; export class Tethr extends EventEmitter { constructor() { super(); } emit(eventName, ...args) { const ret = super.emit(eventName, ...args); if (eventName.endsWith('Change')) { this.emit('change', eventName.slice(0, -6), args[0]); } return ret; } // eslint-disable-next-line @typescript-eslint/no-unused-vars setLog(log) { null; } /** * Export all writable configs to a plain object. */ async exportConfigs() { const configs = (await Promise.all(ConfigNameList.map(async (name) => { const desc = await this.getDesc(name); // Export only writable configs if (desc.value === null || !desc.writable) return null; return [name, desc.value]; }))).filter(isntNil); return Object.fromEntries(configs); } /** * Apply all writable configs. */ async importConfigs(configs) { for (const name of ConfigNameList) { const value = configs[name]; if (value === undefined) continue; await this.set(name, value); } } // Config async get(name) { return (await this.getDesc(name)).value; } async set(name, value) { const setterName = `set${name[0].toUpperCase()}${name.slice(1)}`; if (!this[setterName]) { console.error(`No such config: ${name}`); return { status: 'invalid parameter' }; } return this[setterName](value); } async getDesc(name) { const getterName = `get${name[0].toUpperCase()}${name.slice(1)}Desc`; if (!this[getterName]) { console.error(`No such config: ${name}`); return UnsupportedConfigDesc; } return this[getterName](); } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setAperture(value) { return UnsupportedOperationResult; } async getAperture() { return (await this.getApertureDesc()).value; } async getApertureDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setAutoFocusFrameCenter(value) { return UnsupportedOperationResult; } async getAutoFocusFrameCenter() { return (await this.getAutoFocusFrameCenterDesc()).value; } async getAutoFocusFrameCenterDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setAutoFocusFrameSize(value) { return UnsupportedOperationResult; } async getAutoFocusFrameSize() { return (await this.getAutoFocusFrameSizeDesc()).value; } async getAutoFocusFrameSizeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setBatteryLevel(value) { return UnsupportedOperationResult; } async getBatteryLevel() { return (await this.getBatteryLevelDesc()).value; } async getBatteryLevelDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setBurstInterval(value) { return UnsupportedOperationResult; } async getBurstInterval() { return (await this.getBurstIntervalDesc()).value; } async getBurstIntervalDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setBurstNumber(value) { return UnsupportedOperationResult; } async getBurstNumber() { return (await this.getBurstNumberDesc()).value; } async getBurstNumberDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setCanRunAutoFocus(value) { return UnsupportedOperationResult; } async getCanRunAutoFocus() { return (await this.getCanRunAutoFocusDesc()).value; } async getCanRunAutoFocusDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setCanRunManualFocus(value) { return UnsupportedOperationResult; } async getCanRunManualFocus() { return (await this.getCanRunManualFocusDesc()).value; } async getCanRunManualFocusDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setCanStartLiveview(value) { return UnsupportedOperationResult; } async getCanStartLiveview() { return (await this.getCanStartLiveviewDesc()).value; } async getCanStartLiveviewDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setCanTakePhoto(value) { return UnsupportedOperationResult; } async getCanTakePhoto() { return (await this.getCanTakePhotoDesc()).value; } async getCanTakePhotoDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setCaptureDelay(value) { return UnsupportedOperationResult; } async getCaptureDelay() { return (await this.getCaptureDelayDesc()).value; } async getCaptureDelayDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setColorMode(value) { return UnsupportedOperationResult; } async getColorMode() { return (await this.getColorModeDesc()).value; } async getColorModeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setColorTemperature(value) { return UnsupportedOperationResult; } async getColorTemperature() { return (await this.getColorTemperatureDesc()).value; } async getColorTemperatureDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setCompressionSetting(value) { return UnsupportedOperationResult; } async getCompressionSetting() { return (await this.getCompressionSettingDesc()).value; } async getCompressionSettingDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setContrast(value) { return UnsupportedOperationResult; } async getContrast() { return (await this.getContrastDesc()).value; } async getContrastDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setDateTime(value) { return UnsupportedOperationResult; } async getDateTime() { return (await this.getDateTimeDesc()).value; } async getDateTimeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setDestinationToSave(value) { return UnsupportedOperationResult; } async getDestinationToSave() { return (await this.getDestinationToSaveDesc()).value; } async getDestinationToSaveDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setDigitalZoom(value) { return UnsupportedOperationResult; } async getDigitalZoom() { return (await this.getDigitalZoomDesc()).value; } async getDigitalZoomDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setDriveMode(value) { return UnsupportedOperationResult; } async getDriveMode() { return (await this.getDriveModeDesc()).value; } async getDriveModeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setExposureComp(value) { return UnsupportedOperationResult; } async getExposureComp() { return (await this.getExposureCompDesc()).value; } async getExposureCompDesc() { return UnsupportedConfigDesc; } async setExposureMeteringMode( // eslint-disable-next-line @typescript-eslint/no-unused-vars value) { return UnsupportedOperationResult; } async getExposureMeteringMode() { return (await this.getExposureMeteringModeDesc()).value; } async getExposureMeteringModeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setExposureMode(value) { return UnsupportedOperationResult; } async getExposureMode() { return (await this.getExposureModeDesc()).value; } async getExposureModeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setFacingMode(value) { return UnsupportedOperationResult; } async getFacingMode() { return (await this.getFacingModeDesc()).value; } async getFacingModeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setFlashMode(value) { return UnsupportedOperationResult; } async getFlashMode() { return (await this.getFlashModeDesc()).value; } async getFlashModeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setFocalLength(value) { return UnsupportedOperationResult; } async getFocalLength() { return (await this.getFocalLengthDesc()).value; } async getFocalLengthDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setFocusDistance(value) { return UnsupportedOperationResult; } async getFocusDistance() { return (await this.getFocusDistanceDesc()).value; } async getFocusDistanceDesc() { return UnsupportedConfigDesc; } async setFocusMeteringMode( // eslint-disable-next-line @typescript-eslint/no-unused-vars value) { return UnsupportedOperationResult; } async getFocusMeteringMode() { return (await this.getFocusMeteringModeDesc()).value; } async getFocusMeteringModeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setFocusMode(value) { return UnsupportedOperationResult; } async getFocusMode() { return (await this.getFocusModeDesc()).value; } async getFocusModeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setFocusPeaking(value) { return UnsupportedOperationResult; } async getFocusPeaking() { return (await this.getFocusPeakingDesc()).value; } async getFocusPeakingDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setFunctionalMode(value) { return UnsupportedOperationResult; } async getFunctionalMode() { return (await this.getFunctionalModeDesc()).value; } async getFunctionalModeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setImageAspect(value) { return UnsupportedOperationResult; } async getImageAspect() { return (await this.getImageAspectDesc()).value; } async getImageAspectDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setImageQuality(value) { return UnsupportedOperationResult; } async getImageQuality() { return (await this.getImageQualityDesc()).value; } async getImageQualityDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setImageSize(value) { return UnsupportedOperationResult; } async getImageSize() { return (await this.getImageSizeDesc()).value; } async getImageSizeDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setIso(value) { return UnsupportedOperationResult; } async getIso() { return (await this.getIsoDesc()).value; } async getIsoDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setLiveview(value) { return UnsupportedOperationResult; } /** * Get the liveview stream when liveview is running. Use {@link getCanStartLiveview} to check if the camera supports this action, and {@link startLiveview} or {@link stopLiveview} to control liveview. */ async getLiveview() { return (await this.getLiveviewDesc()).value; } async getLiveviewDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setLiveviewMagnifyRatio(value) { return UnsupportedOperationResult; } async getLiveviewMagnifyRatio() { return (await this.getLiveviewMagnifyRatioDesc()).value; } async getLiveviewMagnifyRatioDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setLiveviewSize(value) { return UnsupportedOperationResult; } async getLiveviewSize() { return (await this.getLiveviewSizeDesc()).value; } async getLiveviewSizeDesc() { return UnsupportedConfigDesc; } async setManualFocusOptions( // eslint-disable-next-line @typescript-eslint/no-unused-vars value) { return UnsupportedOperationResult; } async getManualFocusOptions() { return (await this.getManualFocusOptionsDesc()).value; } async getManualFocusOptionsDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setManufacturer(value) { return UnsupportedOperationResult; } async getManufacturer() { return (await this.getManufacturerDesc()).value; } async getManufacturerDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setModel(value) { return UnsupportedOperationResult; } async getModel() { return (await this.getModelDesc()).value; } async getModelDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setSerialNumber(value) { return UnsupportedOperationResult; } async getSerialNumber() { return (await this.getSerialNumberDesc()).value; } async getSerialNumberDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setSharpness(value) { return UnsupportedOperationResult; } async getSharpness() { return (await this.getSharpnessDesc()).value; } async getSharpnessDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setShutterSpeed(value) { return UnsupportedOperationResult; } async getShutterSpeed() { return (await this.getShutterSpeedDesc()).value; } async getShutterSpeedDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setShutterSound(value) { return UnsupportedOperationResult; } async getShutterSound() { return (await this.getShutterSoundDesc()).value; } async getShutterSoundDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setTimelapseInterval(value) { return UnsupportedOperationResult; } async getTimelapseInterval() { return (await this.getTimelapseIntervalDesc()).value; } async getTimelapseIntervalDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setTimelapseNumber(value) { return UnsupportedOperationResult; } async getTimelapseNumber() { return (await this.getTimelapseNumberDesc()).value; } async getTimelapseNumberDesc() { return UnsupportedConfigDesc; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async setWhiteBalance(value) { return UnsupportedOperationResult; } async getWhiteBalance() { return (await this.getWhiteBalanceDesc()).value; } async getWhiteBalanceDesc() { return UnsupportedConfigDesc; } /** * Runs auto focus. Use {@link getCanRunAutoFocus} to check if the camera supports this action. * @category Action */ async runAutoFocus() { return UnsupportedOperationResult; } /** * Runs manual focus. Use {@link getCanRunAutoFocus} to check if the camera supports this action. * @category Action */ // eslint-disable-next-line @typescript-eslint/no-unused-vars async runManualFocus(option) { return UnsupportedOperationResult; } /** * Takes a photo. Use {@link getCanTakePhoto} to check if the camera supports this action. * @category Action */ async takePhoto( // eslint-disable-next-line @typescript-eslint/no-unused-vars option) { return UnsupportedOperationResult; } /** * Starts liveview. Use {@link getCanStartLiveview} to check if the camera supports this action. * @category Action */ async startLiveview() { return UnsupportedOperationResult; } /** * Stops liveview. * @category Action */ async stopLiveview() { return UnsupportedOperationResult; } } //# sourceMappingURL=Tethr.js.map