ts-onvif
Version:
Client to ONVIF devices
260 lines • 9.71 kB
JavaScript
;
/**
* Imaging ver20 module
* @author Andrew D.Laptev <a.d.laptev@gmail.com>
* @see https://www.onvif.org/ver20/imaging/wsdl/imaging.wsdl
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const service_1 = __importDefault(require("./service"));
const toOnvifXMLSchemaObject_1 = require("./utils/toOnvifXMLSchemaObject");
/**
* Imaging service
* @example
* ```ts
* const is = await cam.imaging.getImagingSettings();
* is.brightness = 70;
* await cam.imaging.setImagingSettings({
* imagingSettings: is,
* forcePersistence: true,
* });
* ```
*/
class Imaging extends service_1.default {
constructor(onvif) {
super(onvif, 'imaging');
}
videoSourceToken(videoSourceToken) {
return videoSourceToken ?? this.onvif.activeSource.videoSourceToken;
}
static backlightCompensationToBuild(backlightCompensation) {
return {
Mode: backlightCompensation.mode,
...(backlightCompensation.level !== undefined && { Level: backlightCompensation.level }),
};
}
static exposureToBuild(exposure) {
return {
Mode: exposure.mode,
...(exposure.priority && { Priority: exposure.priority }),
...(exposure.window && {
Window: {
Bottom: exposure.window.bottom,
Top: exposure.window.top,
Right: exposure.window.right,
Left: exposure.window.left,
},
}),
...(exposure.minExposureTime && { MinExposureTime: exposure.minExposureTime }),
...(exposure.maxExposureTime && { MaxExposureTime: exposure.maxExposureTime }),
...(exposure.minGain && { MinGain: exposure.minGain }),
...(exposure.maxGain && { MaxGain: exposure.maxGain }),
...(exposure.minIris && { MinIris: exposure.minIris }),
...(exposure.maxIris && { MaxIris: exposure.maxIris }),
...(exposure.exposureTime && { ExposureTime: exposure.exposureTime }),
...(exposure.gain && { Gain: exposure.gain }),
...(exposure.iris && { Iris: exposure.iris }),
};
}
static focusConfigurationToBuild(focus) {
return {
$: {
...(focus.AFMode && { AFMode: (0, toOnvifXMLSchemaObject_1.stringListToBuild)(focus.AFMode) }),
},
AutoFocusMode: focus.autoFocusMode,
...(focus.defaultSpeed && { DefaultSpeed: focus.defaultSpeed }),
...(focus.nearLimit && { NearLimit: focus.nearLimit }),
...(focus.farLimit && { FarLimit: focus.farLimit }),
...(focus.extension && { Extension: focus.extension }),
};
}
static wideDynamicRangeToBuild(wideDynamicRange) {
return {
Mode: wideDynamicRange.mode,
...(wideDynamicRange.level && { Level: wideDynamicRange.level }),
};
}
static whiteBalanceToBuild(whiteBalance) {
return {
Mode: whiteBalance.mode,
...(whiteBalance.crGain && { CrGain: whiteBalance.crGain }),
...(whiteBalance.cbGain && { CbGain: whiteBalance.cbGain }),
...(whiteBalance.extension && { Extension: whiteBalance.extension }),
};
}
static imagingSettingsToBuild(settings) {
return {
...(settings.backlightCompensation && {
BacklightCompensation: Imaging.backlightCompensationToBuild(settings.backlightCompensation),
}),
...(settings.brightness && { Brightness: settings.brightness }),
...(settings.colorSaturation && { ColorSaturation: settings.colorSaturation }),
...(settings.contrast && { Contrast: settings.contrast }),
...(settings.exposure && { Exposure: Imaging.exposureToBuild(settings.exposure) }),
...(settings.focus && { Focus: Imaging.focusConfigurationToBuild(settings.focus) }),
...(settings.irCutFilter && { IrCutFilter: settings.irCutFilter }),
...(settings.sharpness && { Sharpness: settings.sharpness }),
...(settings.wideDynamicRange && {
WideDynamicRange: Imaging.wideDynamicRangeToBuild(settings.wideDynamicRange),
}),
...(settings.whiteBalance && {
WhiteBalance: Imaging.whiteBalanceToBuild(settings.whiteBalance),
}),
...(settings.extension && { Extension: settings.extension }),
};
}
static focusMoveToBuild(focus) {
return {
...(focus.absolute && {
Absolute: {
Position: focus.absolute.position,
...(focus.absolute.speed && { Speed: focus.absolute.speed }),
},
}),
...(focus.relative && {
Relative: {
Distance: focus.relative.distance,
...(focus.relative.speed && { Speed: focus.relative.speed }),
},
}),
...(focus.continuous && {
Continuous: {
Speed: focus.continuous.speed,
},
}),
};
}
/**
* Returns the capabilities of the imaging service.
*/
async getServiceCapabilities() {
const response = await this.request({
GetServiceCapabilities: {},
});
return response.getServiceCapabilitiesResponse?.capabilities ?? {};
}
/**
* Get the imaging configuration for the requested video source.
* @param options
*/
async getImagingSettings({ videoSourceToken } = {}) {
const response = await this.request({
GetImagingSettings: {
VideoSourceToken: this.videoSourceToken(videoSourceToken),
},
});
return response.getImagingSettingsResponse.imagingSettings;
}
/**
* Set the imaging configuration for the requested video source.
* @param options
*/
async setImagingSettings({ videoSourceToken, imagingSettings, forcePersistence, }) {
await this.request({
SetImagingSettings: {
VideoSourceToken: this.videoSourceToken(videoSourceToken),
ImagingSettings: Imaging.imagingSettingsToBuild(imagingSettings),
...(forcePersistence && { ForcePersistence: forcePersistence }),
},
});
}
/**
* Get valid ranges for imaging parameters that have device-specific ranges.
* @param options
*/
async getOptions({ videoSourceToken } = {}) {
const response = await this.request({
GetOptions: {
VideoSourceToken: this.videoSourceToken(videoSourceToken),
},
});
return response.getOptionsResponse.imagingOptions;
}
/**
* Move the focus lens in absolute, relative, or continuous manner.
* @param options
*/
async move({ videoSourceToken, focus }) {
await this.request({
Move: {
VideoSourceToken: this.videoSourceToken(videoSourceToken),
Focus: Imaging.focusMoveToBuild(focus),
},
});
}
/**
* Get valid ranges for focus lens move options.
* @param options
*/
async getMoveOptions({ videoSourceToken } = {}) {
const response = await this.request({
GetMoveOptions: {
VideoSourceToken: this.videoSourceToken(videoSourceToken),
},
});
return response.getMoveOptionsResponse.moveOptions;
}
/**
* Stop ongoing focus movement for the requested video source.
* @param options
*/
async stop({ videoSourceToken } = {}) {
await this.request({
Stop: {
VideoSourceToken: this.videoSourceToken(videoSourceToken),
},
});
}
/**
* Get imaging status for the requested video source.
* @param options
*/
async getStatus({ videoSourceToken } = {}) {
const response = await this.request({
GetStatus: {
VideoSourceToken: this.videoSourceToken(videoSourceToken),
},
});
return response.getStatusResponse.status;
}
/**
* Get imaging presets available for the requested video source.
* @param options
*/
async getPresets({ videoSourceToken } = {}) {
const response = await this.request({
GetPresets: {
VideoSourceToken: this.videoSourceToken(videoSourceToken),
},
}, { array: ['preset'] });
return response.getPresetsResponse.preset ?? [];
}
/**
* Get the current imaging preset for the requested video source.
* @param options
*/
async getCurrentPreset({ videoSourceToken } = {}) {
const response = await this.request({
GetCurrentPreset: {
VideoSourceToken: this.videoSourceToken(videoSourceToken),
},
});
return response.getCurrentPresetResponse.preset;
}
/**
* Apply an imaging preset to the requested video source.
* @param options
*/
async setCurrentPreset({ videoSourceToken, presetToken }) {
await this.request({
SetCurrentPreset: {
VideoSourceToken: this.videoSourceToken(videoSourceToken),
PresetToken: presetToken,
},
});
}
}
exports.default = Imaging;
//# sourceMappingURL=imaging.js.map