UNPKG

ts-onvif

Version:

Client to ONVIF devices

1,183 lines 71.3 kB
"use strict";
/**
 * Media ver20 module
 * @author Andrew D.Laptev <a.d.laptev@gmail.com>
 * @see https://www.onvif.org/specs/srv/media/ONVIF-Media2-Service-Spec.pdf
 * @see http://www.onvif.org/ver20/media/wsdl
 */
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
    var useValue = arguments.length > 2;
    for (var i = 0; i < initializers.length; i++) {
        value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
    }
    return useValue ? value : void 0;
};
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
    function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
    var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
    var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
    var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
    var _, done = false;
    for (var i = decorators.length - 1; i >= 0; i--) {
        var context = {};
        for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
        for (var p in contextIn.access) context.access[p] = contextIn.access[p];
        context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
        var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
        if (kind === "accessor") {
            if (result === void 0) continue;
            if (result === null || typeof result !== "object") throw new TypeError("Object expected");
            if (_ = accept(result.get)) descriptor.get = _;
            if (_ = accept(result.set)) descriptor.set = _;
            if (_ = accept(result.init)) initializers.unshift(_);
        }
        else if (_ = accept(result)) {
            if (kind === "field") initializers.unshift(_);
            else descriptor[key] = _;
        }
    }
    if (target) Object.defineProperty(target, contextIn.name, descriptor);
    done = true;
};
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");
let Media2 = (() => {
    let _classSuper = service_1.default;
    let _instanceExtraInitializers = [];
    let _getServiceCapabilities_decorators;
    let _getProfiles_decorators;
    let _createProfile_decorators;
    let _addConfiguration_decorators;
    let _removeConfiguration_decorators;
    let _deleteProfile_decorators;
    let _getConfigurations_decorators;
    let _getVideoSourceConfigurations_decorators;
    let _getVideoEncoderConfigurations_decorators;
    let _getAudioSourceConfigurations_decorators;
    let _getAudioEncoderConfigurations_decorators;
    let _getAnalyticsConfigurations_decorators;
    let _getMetadataConfigurations_decorators;
    let _getAudioOutputConfigurations_decorators;
    let _getAudioDecoderConfigurations_decorators;
    let _getWebRTCConfigurations_decorators;
    let _setVideoEncoderConfiguration_decorators;
    let _setVideoSourceConfiguration_decorators;
    let _setAudioEncoderConfiguration_decorators;
    let _setAudioSourceConfiguration_decorators;
    let _setMetadataConfiguration_decorators;
    let _setAudioOutputConfiguration_decorators;
    let _setAudioDecoderConfiguration_decorators;
    let _getVideoSourceConfigurationOptions_decorators;
    let _getVideoEncoderConfigurationOptions_decorators;
    let _getAudioSourceConfigurationOptions_decorators;
    let _getAudioEncoderConfigurationOptions_decorators;
    let _getMetadataConfigurationOptions_decorators;
    let _getAudioOutputConfigurationOptions_decorators;
    let _getAudioDecoderConfigurationOptions_decorators;
    let _getVideoEncoderInstances_decorators;
    let _setSynchronizationPoint_decorators;
    let _startMulticastStreaming_decorators;
    let _stopMulticastStreaming_decorators;
    let _getVideoSourceModes_decorators;
    let _setVideoSourceMode_decorators;
    let _getOSDs_decorators;
    let _setOSD_decorators;
    let _getOSDOptions_decorators;
    let _createOSD_decorators;
    let _deleteOSD_decorators;
    let _getMasks_decorators;
    let _setMask_decorators;
    let _getMaskOptions_decorators;
    let _deleteMask_decorators;
    let _getStreamUri_decorators;
    let _getSnapshotUri_decorators;
    return class Media2 extends _classSuper {
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _getServiceCapabilities_decorators = [v2];
            _getProfiles_decorators = [v2];
            _createProfile_decorators = [v2];
            _addConfiguration_decorators = [v2];
            _removeConfiguration_decorators = [v2];
            _deleteProfile_decorators = [v2];
            _getConfigurations_decorators = [v2];
            _getVideoSourceConfigurations_decorators = [v2];
            _getVideoEncoderConfigurations_decorators = [v2];
            _getAudioSourceConfigurations_decorators = [v2];
            _getAudioEncoderConfigurations_decorators = [v2];
            _getAnalyticsConfigurations_decorators = [v2];
            _getMetadataConfigurations_decorators = [v2];
            _getAudioOutputConfigurations_decorators = [v2];
            _getAudioDecoderConfigurations_decorators = [v2];
            _getWebRTCConfigurations_decorators = [v2];
            _setVideoEncoderConfiguration_decorators = [v2];
            _setVideoSourceConfiguration_decorators = [v2];
            _setAudioEncoderConfiguration_decorators = [v2];
            _setAudioSourceConfiguration_decorators = [v2];
            _setMetadataConfiguration_decorators = [v2];
            _setAudioOutputConfiguration_decorators = [v2];
            _setAudioDecoderConfiguration_decorators = [v2];
            _getVideoSourceConfigurationOptions_decorators = [v2];
            _getVideoEncoderConfigurationOptions_decorators = [v2];
            _getAudioSourceConfigurationOptions_decorators = [v2];
            _getAudioEncoderConfigurationOptions_decorators = [v2];
            _getMetadataConfigurationOptions_decorators = [v2];
            _getAudioOutputConfigurationOptions_decorators = [v2];
            _getAudioDecoderConfigurationOptions_decorators = [v2];
            _getVideoEncoderInstances_decorators = [v2];
            _setSynchronizationPoint_decorators = [v2];
            _startMulticastStreaming_decorators = [v2];
            _stopMulticastStreaming_decorators = [v2];
            _getVideoSourceModes_decorators = [v2];
            _setVideoSourceMode_decorators = [v2];
            _getOSDs_decorators = [v2];
            _setOSD_decorators = [v2];
            _getOSDOptions_decorators = [v2];
            _createOSD_decorators = [v2];
            _deleteOSD_decorators = [v2];
            _getMasks_decorators = [v2];
            _setMask_decorators = [v2];
            _getMaskOptions_decorators = [v2];
            _deleteMask_decorators = [v2];
            _getStreamUri_decorators = [v2];
            _getSnapshotUri_decorators = [v2];
            __esDecorate(this, null, _getServiceCapabilities_decorators, { kind: "method", name: "getServiceCapabilities", static: false, private: false, access: { has: obj => "getServiceCapabilities" in obj, get: obj => obj.getServiceCapabilities }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getProfiles_decorators, { kind: "method", name: "getProfiles", static: false, private: false, access: { has: obj => "getProfiles" in obj, get: obj => obj.getProfiles }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _createProfile_decorators, { kind: "method", name: "createProfile", static: false, private: false, access: { has: obj => "createProfile" in obj, get: obj => obj.createProfile }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _addConfiguration_decorators, { kind: "method", name: "addConfiguration", static: false, private: false, access: { has: obj => "addConfiguration" in obj, get: obj => obj.addConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _removeConfiguration_decorators, { kind: "method", name: "removeConfiguration", static: false, private: false, access: { has: obj => "removeConfiguration" in obj, get: obj => obj.removeConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _deleteProfile_decorators, { kind: "method", name: "deleteProfile", static: false, private: false, access: { has: obj => "deleteProfile" in obj, get: obj => obj.deleteProfile }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getConfigurations_decorators, { kind: "method", name: "getConfigurations", static: false, private: false, access: { has: obj => "getConfigurations" in obj, get: obj => obj.getConfigurations }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getVideoSourceConfigurations_decorators, { kind: "method", name: "getVideoSourceConfigurations", static: false, private: false, access: { has: obj => "getVideoSourceConfigurations" in obj, get: obj => obj.getVideoSourceConfigurations }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getVideoEncoderConfigurations_decorators, { kind: "method", name: "getVideoEncoderConfigurations", static: false, private: false, access: { has: obj => "getVideoEncoderConfigurations" in obj, get: obj => obj.getVideoEncoderConfigurations }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getAudioSourceConfigurations_decorators, { kind: "method", name: "getAudioSourceConfigurations", static: false, private: false, access: { has: obj => "getAudioSourceConfigurations" in obj, get: obj => obj.getAudioSourceConfigurations }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getAudioEncoderConfigurations_decorators, { kind: "method", name: "getAudioEncoderConfigurations", static: false, private: false, access: { has: obj => "getAudioEncoderConfigurations" in obj, get: obj => obj.getAudioEncoderConfigurations }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getAnalyticsConfigurations_decorators, { kind: "method", name: "getAnalyticsConfigurations", static: false, private: false, access: { has: obj => "getAnalyticsConfigurations" in obj, get: obj => obj.getAnalyticsConfigurations }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getMetadataConfigurations_decorators, { kind: "method", name: "getMetadataConfigurations", static: false, private: false, access: { has: obj => "getMetadataConfigurations" in obj, get: obj => obj.getMetadataConfigurations }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getAudioOutputConfigurations_decorators, { kind: "method", name: "getAudioOutputConfigurations", static: false, private: false, access: { has: obj => "getAudioOutputConfigurations" in obj, get: obj => obj.getAudioOutputConfigurations }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getAudioDecoderConfigurations_decorators, { kind: "method", name: "getAudioDecoderConfigurations", static: false, private: false, access: { has: obj => "getAudioDecoderConfigurations" in obj, get: obj => obj.getAudioDecoderConfigurations }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getWebRTCConfigurations_decorators, { kind: "method", name: "getWebRTCConfigurations", static: false, private: false, access: { has: obj => "getWebRTCConfigurations" in obj, get: obj => obj.getWebRTCConfigurations }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _setVideoEncoderConfiguration_decorators, { kind: "method", name: "setVideoEncoderConfiguration", static: false, private: false, access: { has: obj => "setVideoEncoderConfiguration" in obj, get: obj => obj.setVideoEncoderConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _setVideoSourceConfiguration_decorators, { kind: "method", name: "setVideoSourceConfiguration", static: false, private: false, access: { has: obj => "setVideoSourceConfiguration" in obj, get: obj => obj.setVideoSourceConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _setAudioEncoderConfiguration_decorators, { kind: "method", name: "setAudioEncoderConfiguration", static: false, private: false, access: { has: obj => "setAudioEncoderConfiguration" in obj, get: obj => obj.setAudioEncoderConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _setAudioSourceConfiguration_decorators, { kind: "method", name: "setAudioSourceConfiguration", static: false, private: false, access: { has: obj => "setAudioSourceConfiguration" in obj, get: obj => obj.setAudioSourceConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _setMetadataConfiguration_decorators, { kind: "method", name: "setMetadataConfiguration", static: false, private: false, access: { has: obj => "setMetadataConfiguration" in obj, get: obj => obj.setMetadataConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _setAudioOutputConfiguration_decorators, { kind: "method", name: "setAudioOutputConfiguration", static: false, private: false, access: { has: obj => "setAudioOutputConfiguration" in obj, get: obj => obj.setAudioOutputConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _setAudioDecoderConfiguration_decorators, { kind: "method", name: "setAudioDecoderConfiguration", static: false, private: false, access: { has: obj => "setAudioDecoderConfiguration" in obj, get: obj => obj.setAudioDecoderConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getVideoSourceConfigurationOptions_decorators, { kind: "method", name: "getVideoSourceConfigurationOptions", static: false, private: false, access: { has: obj => "getVideoSourceConfigurationOptions" in obj, get: obj => obj.getVideoSourceConfigurationOptions }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getVideoEncoderConfigurationOptions_decorators, { kind: "method", name: "getVideoEncoderConfigurationOptions", static: false, private: false, access: { has: obj => "getVideoEncoderConfigurationOptions" in obj, get: obj => obj.getVideoEncoderConfigurationOptions }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getAudioSourceConfigurationOptions_decorators, { kind: "method", name: "getAudioSourceConfigurationOptions", static: false, private: false, access: { has: obj => "getAudioSourceConfigurationOptions" in obj, get: obj => obj.getAudioSourceConfigurationOptions }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getAudioEncoderConfigurationOptions_decorators, { kind: "method", name: "getAudioEncoderConfigurationOptions", static: false, private: false, access: { has: obj => "getAudioEncoderConfigurationOptions" in obj, get: obj => obj.getAudioEncoderConfigurationOptions }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getMetadataConfigurationOptions_decorators, { kind: "method", name: "getMetadataConfigurationOptions", static: false, private: false, access: { has: obj => "getMetadataConfigurationOptions" in obj, get: obj => obj.getMetadataConfigurationOptions }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getAudioOutputConfigurationOptions_decorators, { kind: "method", name: "getAudioOutputConfigurationOptions", static: false, private: false, access: { has: obj => "getAudioOutputConfigurationOptions" in obj, get: obj => obj.getAudioOutputConfigurationOptions }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getAudioDecoderConfigurationOptions_decorators, { kind: "method", name: "getAudioDecoderConfigurationOptions", static: false, private: false, access: { has: obj => "getAudioDecoderConfigurationOptions" in obj, get: obj => obj.getAudioDecoderConfigurationOptions }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getVideoEncoderInstances_decorators, { kind: "method", name: "getVideoEncoderInstances", static: false, private: false, access: { has: obj => "getVideoEncoderInstances" in obj, get: obj => obj.getVideoEncoderInstances }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _setSynchronizationPoint_decorators, { kind: "method", name: "setSynchronizationPoint", static: false, private: false, access: { has: obj => "setSynchronizationPoint" in obj, get: obj => obj.setSynchronizationPoint }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _startMulticastStreaming_decorators, { kind: "method", name: "startMulticastStreaming", static: false, private: false, access: { has: obj => "startMulticastStreaming" in obj, get: obj => obj.startMulticastStreaming }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _stopMulticastStreaming_decorators, { kind: "method", name: "stopMulticastStreaming", static: false, private: false, access: { has: obj => "stopMulticastStreaming" in obj, get: obj => obj.stopMulticastStreaming }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getVideoSourceModes_decorators, { kind: "method", name: "getVideoSourceModes", static: false, private: false, access: { has: obj => "getVideoSourceModes" in obj, get: obj => obj.getVideoSourceModes }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _setVideoSourceMode_decorators, { kind: "method", name: "setVideoSourceMode", static: false, private: false, access: { has: obj => "setVideoSourceMode" in obj, get: obj => obj.setVideoSourceMode }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getOSDs_decorators, { kind: "method", name: "getOSDs", static: false, private: false, access: { has: obj => "getOSDs" in obj, get: obj => obj.getOSDs }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _setOSD_decorators, { kind: "method", name: "setOSD", static: false, private: false, access: { has: obj => "setOSD" in obj, get: obj => obj.setOSD }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getOSDOptions_decorators, { kind: "method", name: "getOSDOptions", static: false, private: false, access: { has: obj => "getOSDOptions" in obj, get: obj => obj.getOSDOptions }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _createOSD_decorators, { kind: "method", name: "createOSD", static: false, private: false, access: { has: obj => "createOSD" in obj, get: obj => obj.createOSD }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _deleteOSD_decorators, { kind: "method", name: "deleteOSD", static: false, private: false, access: { has: obj => "deleteOSD" in obj, get: obj => obj.deleteOSD }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getMasks_decorators, { kind: "method", name: "getMasks", static: false, private: false, access: { has: obj => "getMasks" in obj, get: obj => obj.getMasks }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _setMask_decorators, { kind: "method", name: "setMask", static: false, private: false, access: { has: obj => "setMask" in obj, get: obj => obj.setMask }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getMaskOptions_decorators, { kind: "method", name: "getMaskOptions", static: false, private: false, access: { has: obj => "getMaskOptions" in obj, get: obj => obj.getMaskOptions }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _deleteMask_decorators, { kind: "method", name: "deleteMask", static: false, private: false, access: { has: obj => "deleteMask" in obj, get: obj => obj.deleteMask }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getStreamUri_decorators, { kind: "method", name: "getStreamUri", static: false, private: false, access: { has: obj => "getStreamUri" in obj, get: obj => obj.getStreamUri }, metadata: _metadata }, null, _instanceExtraInitializers);
            __esDecorate(this, null, _getSnapshotUri_decorators, { kind: "method", name: "getSnapshotUri", static: false, private: false, access: { has: obj => "getSnapshotUri" in obj, get: obj => obj.getSnapshotUri }, metadata: _metadata }, null, _instanceExtraInitializers);
            if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        constructor(onvif) {
            super(onvif, 'media2');
            __runInitializers(this, _instanceExtraInitializers);
        }
        /**
         * Returns the capabilities of the media service. The result is returned in a typed answer.
         */
        async getServiceCapabilities() {
            const response = await this.request({
                GetServiceCapabilities: {},
            });
            return response.getServiceCapabilitiesResponse.capabilities;
        }
        /**
         * Retrieve the profile with the specified token or all defined media profiles.
         * - If no Type is provided the returned profiles shall contain no configuration information.
         * - If a single Type with value 'All' is provided the returned profiles shall include all associated configurations.
         * - Otherwise the requested list of configurations shall for each profile include the configurations present as Type.
         * @param options
         * @param options.token Optional token to retrieve exactly one profile.
         * @param options.type If one or more types are passed only the corresponding configurations will be returned.
         */
        async getProfiles({ token, type } = {}) {
            const response = await this.request({
                GetProfiles: {
                    ...(token !== undefined && { Token: token }),
                    Type: type !== undefined ? type : 'All',
                },
            }, { array: ['profiles'] });
            return response.getProfilesResponse.profiles;
        }
        /**
         * This operation creates a new media profile. A created profile created via this method may be deleted via the
         * DeleteProfile method. Optionally Configurations can be assigned to the profile on creation. For details regarding
         * profile assignment check also the method AddConfiguration.
         * @param options
         * @param options.name
         * @param options.configuration
         */
        async createProfile({ name, configuration }) {
            const response = await this.request({
                CreateProfile: {
                    Name: name,
                    ...(configuration && {
                        Configuration: configuration.map((configurationRef) => ({
                            Type: configurationRef.type,
                            ...(configurationRef.token && { Token: configurationRef.token }),
                        })),
                    }),
                },
            });
            return response.createProfileResponse.token;
        }
        /**
         * This operation adds one or more Configurations to an existing media profile. If a configuration exists in the media
         * profile, it will be replaced. A device shall support adding a compatible Configuration to a Profile containing a
         * VideoSourceConfiguration and shall support streaming video data of such a profile.
         *
         * Note that OSD elements must be added via the CreateOSD command.
         * @param options
         * @param options.profileToken
         * @param options.name
         * @param options.configuration
         */
        async addConfiguration({ profileToken, name, configuration }) {
            await this.request({
                AddConfiguration: {
                    ProfileToken: profileToken,
                    ...(name !== undefined && { Name: name }),
                    ...(configuration && {
                        Configuration: configuration.map((configurationRef) => ({
                            Type: configurationRef.type,
                            ...(configurationRef.token && { Token: configurationRef.token }),
                        })),
                    }),
                },
            });
        }
        /**
         * This operation removes one or more configurations from an existing media profile. Tokens appearing in the
         * configuration list shall be ignored. Presence of the "All" type shall result in an empty profile. Removing a
         * non-existing configuration shall be ignored and not result in an error. A device supporting the Media2 service
         * shall support this command
         * @param options
         * @param options.profileToken
         * @param options.configuration
         */
        async removeConfiguration({ profileToken, configuration }) {
            await this.request({
                RemoveConfiguration: {
                    ProfileToken: profileToken,
                    ...(configuration?.length && {
                        Configuration: configuration.map((configurationRef) => ({
                            Type: configurationRef.type,
                        })),
                    }),
                },
            });
        }
        /**
         * This operation deletes a profile. The device shall support the deletion of a media profile through the DeletePro-
         * file command.
         * A device signaling support for MultiTrackStreaming shall support deleting of virtual profiles via the command.
         * Note that deleting a profile of a virtual profile set may invalidate the virtual profile.
         * @param options
         * @param options.token
         */
        async deleteProfile({ token }) {
            await this.request({
                DeleteProfile: {
                    Token: token,
                },
            });
        }
        /**
         * Common function to get configurations
         * @private
         * @param options
         * @param options.entityName
         * @param options.profileToken
         * @param options.configurationToken
         */
        async getConfigurations({ entityName, profileToken, configurationToken, }) {
            const response = await this.request({
                [`Get${entityName}Configurations`]: {
                    ...(profileToken !== undefined && { ProfileToken: profileToken }),
                    ...(configurationToken !== undefined && { ConfigurationToken: configurationToken }),
                },
            }, { array: ['configurations'] });
            return response[`get${entityName}ConfigurationsResponse`].configurations;
        }
        /**
         * The `getVideoSourceConfigurations` operation allows to retrieve the video source settings of one ore more
         * configurations.
         * - If a configuration token is provided the device shall respond with the requested configuration or provide
         * an error if it does not exist.
         * - In case only a profile token is provided the device shall respond with all configurations that are compatible
         * to the provided media profile.
         * - If no tokens are provided the device shall respond with all available configurations.
         * @param options
         * @param options.profileToken
         * @param options.configurationToken
         */
        async getVideoSourceConfigurations(options) {
            return this.getConfigurations({ entityName: 'VideoSource', ...options });
        }
        /**
         * The `getVideoEncoderConfigurations` operation allows to retrieve the video encoder settings of one ore more
         * configurations.
         * - If a configuration token is provided the device shall respond with the requested configuration or provide
         * an error if it does not exist.
         * - In case only a profile token is provided the device shall respond with all configurations that are compatible
         * to the provided media profile.
         * - If no tokens are provided the device shall respond with all available configurations.
         * @param options
         * @param options.profileToken
         * @param options.configurationToken
         */
        async getVideoEncoderConfigurations(options) {
            return this.getConfigurations({ entityName: 'VideoEncoder', ...options });
        }
        /**
         * The `getAudioSourceConfigurations` operation allows to retrieve the audio source settings of one ore more
         * configurations.
         * - If a configuration token is provided the device shall respond with the requested configuration or provide
         * an error if it does not exist.
         * - In case only a profile token is provided the device shall respond with all configurations that are compatible
         * to the provided media profile.
         * - If no tokens are provided the device shall respond with all available configurations.
         * @param options
         * @param options.profileToken
         * @param options.configurationToken
         */
        async getAudioSourceConfigurations(options) {
            return this.getConfigurations({ entityName: 'AudioSource', ...options });
        }
        /**
         * The `getAudioEncoderConfigurations` operation allows to retrieve the audio encoder settings of one ore more
         * configurations.
         * - If a configuration token is provided the device shall respond with the requested configuration or provide
         * an error if it does not exist.
         * - In case only a profile token is provided the device shall respond with all configurations that are compatible
         * to the provided media profile.
         * - If no tokens are provided the device shall respond with all available configurations.
         * @param options
         * @param options.profileToken
         * @param options.configurationToken
         */
        async getAudioEncoderConfigurations(options) {
            return this.getConfigurations({ entityName: 'AudioEncoder', ...options });
        }
        /**
         * The `getAnalyticsConfigurations` operation allows to retrieve the analytics settings of one ore more
         * configurations.
         * - If a configuration token is provided the device shall respond with the requested configuration or provide
         * an error if it does not exist.
         * - In case only a profile token is provided the device shall respond with all configurations that are compatible
         * to the provided media profile.
         * - If no tokens are provided the device shall respond with all available configurations.
         * @param options
         * @param options.profileToken
         * @param options.configurationToken
         */
        async getAnalyticsConfigurations(options) {
            return this.getConfigurations({ entityName: 'Analytics', ...options });
        }
        /**
         * The `getMetadataConfigurations` operation allows to retrieve the metadata settings of one ore more
         * configurations.
         * - If a configuration token is provided the device shall respond with the requested configuration or provide
         * an error if it does not exist.
         * - In case only a profile token is provided the device shall respond with all configurations that are compatible
         * to the provided media profile.
         * - If no tokens are provided the device shall respond with all available configurations.
         * @param options
         * @param options.profileToken
         * @param options.configurationToken
         */
        async getMetadataConfigurations(options) {
            return this.getConfigurations({ entityName: 'Metadata', ...options });
        }
        /**
         * The `getAudioOutputConfigurations` operation allows to retrieve the audio output settings of one ore more
         * configurations.
         * - If a configuration token is provided the device shall respond with the requested configuration or provide
         * an error if it does not exist.
         * - In case only a profile token is provided the device shall respond with all configurations that are compatible
         * to the provided media profile.
         * - If no tokens are provided the device shall respond with all available configurations.
         * @param options
         * @param options.profileToken
         * @param options.configurationToken
         */
        async getAudioOutputConfigurations(options) {
            return this.getConfigurations({ entityName: 'AudioOutput', ...options });
        }
        /**
         * The `getAudioDecoderConfigurations` operation allows to retrieve the audio decoder settings of one ore more
         * configurations.
         * - If a configuration token is provided the device shall respond with the requested configuration or provide
         * an error if it does not exist.
         * - In case only a profile token is provided the device shall respond with all configurations that are compatible
         * to the provided media profile.
         * - If no tokens are provided the device shall respond with all available configurations.
         * @param options
         * @param options.profileToken
         * @param options.configurationToken
         */
        async getAudioDecoderConfigurations(options) {
            return this.getConfigurations({ entityName: 'AudioDecoder', ...options });
        }
        /**
         * The `getWebRTCConfigurations` operation allows to retrieve the WebRTC settings of one ore more
         * configurations.
         * - If a configuration token is provided the device shall respond with the requested configuration or provide
         * an error if it does not exist.
         * - In case only a profile token is provided the device shall respond with all configurations that are compatible
         * to the provided media profile.
         * - If no tokens are provided the device shall respond with all available configurations.
         * @protected Specs not ready yet, this method is for the future development
         * @experimental
         */
        async getWebRTCConfigurations() {
            const response = await this.request({ GetWebRTCConfigurations: {} }, { array: ['webRTCConfiguration'] });
            return response.getWebRTCConfigurationsResponse.webRTCConfiguration;
        }
        /**
         * This operation modifies a video encoder configuration. Running streams using this configuration may be immediately
         * updated according to the new settings. The changes are not guaranteed to take effect unless the client requests a
         * new stream URI and restarts any affected stream. NVC methods for changing a running stream are out of scope for
         * this specification.
         * SessionTimeout is provided as a hint for keeping rtsp session by a device. If necessary the device may adapt
         * parameter values for SessionTimeout elements without returning an error. For the time between keep alive calls the
         * client shall adhere to the timeout value signaled via RTSP.
         * @param configuration
         */
        async setVideoEncoderConfiguration(configuration) {
            await this.request({
                SetVideoEncoderConfiguration: {
                    Configuration: {
                        $: {
                            token: configuration.token,
                            GovLength: configuration.govLength,
                            AnchorFrameDistance: configuration.anchorFrameDistance,
                            Profile: configuration.profile,
                            GuaranteedFrameRate: configuration.guaranteedFrameRate,
                            Signed: configuration.signed,
                        },
                        Name: configuration.name,
                        UseCount: configuration.useCount,
                        Encoding: configuration.encoding,
                        Resolution: {
                            Width: configuration.resolution.width,
                            Height: configuration.resolution.height,
                        },
                        ...(configuration.rateControl && {
                            RateControl: {
                                ConstantBitRate: configuration.rateControl.constantBitRate,
                                FrameRateLimit: configuration.rateControl.frameRateLimit,
                                BitrateLimit: configuration.rateControl.bitrateLimit,
                            },
                        }),
                        ...(configuration.multicast && {
                            Multicast: (0, toOnvifXMLSchemaObject_1.multicastConfiguration)(configuration.multicast),
                        }),
                        Quality: configuration.quality,
                    },
                },
            });
        }
        /**
         * This operation modifies a video source configuration. Running streams using this configuration may be immediately
         * updated according to the new settings. The changes are not guaranteed to take effect unless the client requests a
         * new stream URI and restarts any affected stream. NVC methods for changing a running stream are out of scope for
         * this specification.
         * @param configuration
         */
        async setVideoSourceConfiguration(configuration) {
            await this.request({
                SetVideoSourceConfiguration: {
                    Configuration: {
                        $: {
                            token: configuration.token,
                            ViewMode: configuration.viewMode,
                        },
                        Name: configuration.name,
                        UseCount: configuration.useCount,
                        SourceToken: configuration.sourceToken,
                        Bounds: {
                            $: {
                                x: configuration.bounds.x,
                                y: configuration.bounds.y,
                                width: configuration.bounds.width,
                                height: configuration.bounds.height,
                            },
                        },
                        ...(configuration.extension && {
                            Extension: {
                                ...(configuration.extension.rotate && {
                                    Rotate: {
                                        Mode: configuration.extension.rotate.mode,
                                        Degree: configuration.extension.rotate.degree,
                                    },
                                }),
                                ...(configuration.extension.extension && {
                                    Extension: {
                                        LensDescription: configuration.extension.extension.lensDescription?.map((lensDescription) => ({
                                            FocalLength: lensDescription.focalLength,
                                            Offset: {
                                                $: {
                                                    x: lensDescription.offset.x,
                                                    y: lensDescription.offset.y,
                                                },
                                            },
                                            Projection: lensDescription.projection?.map((lensProjection) => ({
                                                Angle: lensProjection.angle,
                                                Radius: lensProjection.radius,
                                                Transmittance: lensProjection.transmittance,
                                            })),
                                            XFactor: lensDescription.XFactor,
                                        })),
                                        ...(configuration.extension.extension.sceneOrientation && {
                                            SceneOrientation: {
                                                mode: configuration.extension.extension.sceneOrientation.mode,
                                                orientation: configuration.extension.extension.sceneOrientation.orientation,
                                            },
                                        }),
                                    },
                                }),
                            },
                        }),
                    },
                },
            });
        }
        /**
         * This operation modifies an audio encoder configuration. Running streams using this configuration may be immediately
         * updated according to the new settings. The changes are not guaranteed to take effect unless the client requests a
         * new stream URI and restarts any affected streams. NVC methods for changing a running stream are out of scope for
         * this specification.
         * @param configuration
         */
        async setAudioEncoderConfiguration(configuration) {
            await this.request({
                SetAudioEncoderConfiguration: {
                    Configuration: {
                        $: {
                            token: configuration.token,
                        },
                        Name: configuration.name,
                        UseCount: configuration.useCount,
                        Encoding: configuration.encoding,
                        ...(configuration.multicast && {
                            Multicast: (0, toOnvifXMLSchemaObject_1.multicastConfiguration)(configuration.multicast),
                        }),
                        Bitrate: configuration.bitrate,
                        SampleRate: configuration.sampleRate,
                    },
                },
            });
        }
        /**
         * This operation modifies an audio source configuration. Running streams using this configuration may be immediately
         * updated according to the new settings. The changes are not guaranteed to take effect unless the client requests a
         * new stream URI and restarts any affected stream NVC methods for changing a running stream are out of scope for this
         * specification.
         * @param configuration
         */
        async setAudioSourceConfiguration(configuration) {
            await this.request({
                SetAudioSourceConfiguration: {
                    Configuration: {
                        $: {
                            token: configuration.token,
                        },
                        Name: configuration.name,
                        UseCount: configuration.useCount,
                        SourceToken: configuration.sourceToken,
                    },
                },
            });
        }
        /**
         * This operation modifies a metadata configuration. Running streams using this configuration may be updated
         * immediately according to the new settings. The changes are not guaranteed to take effect unless the client requests
         * a new stream URI and restarts any affected streams. NVC methods for changing a running stream are out of scope for
         * this specification.
         * @param configuration
         */
        async setMetadataConfiguration(configuration) {
            await this.request({
                SetMetadataConfiguration: {
                    Configuration: {
                        $: {
                            token: configuration.token,
                            CompressionType: configuration.compressionType,
                            GeoLocation: configuration.geoLocation,
                            ShapePolygon: configuration.shapePolygon,
                        },
                        Name: configuration.name,
                        UseCount: configuration.useCount,
                        ...(configuration.PTZStatus && {
                            PTZStatus: {
                                Status: configuration.PTZStatus.status,
                                Position: configuration.PTZStatus.position,
                                FieldOfView: configuration.PTZStatus.fieldOfView,
                            },
                        }),
                        ...(configuration.events && {
                            Events: {
                                Filter: configuration.events.filter,
                                SubscriptionPolicy: configuration.events.filter,
                            },
                        }),
                        Analytics: configuration.analytics,
                        ...(configuration.multicast && {
                            Multicast: (0, toOnvifXMLSchemaObject_1.multicastConfiguration)(configuration.multicast),
                        }),
                        SessionTimeout: configuration.sessionTimeout,
                        ...(configuration.analyticsEngineConfiguration && {
                            AnalyticsEngineConfiguration: {
                                ...(configuration.analyticsEngineConfiguration.analyticsModule && {
                                    AnalyticsModule: configuration.analyticsEngineConfiguration.analyticsModule.map(toOnvifXMLSchemaObject_1.config),
                                }),
                                ...(configuration.analyticsEngineConfiguration.extension && {
                                    Extension: configuration.analyticsEngineConfiguration.extension,
                                }),
                            },
                        }),
                        ...(configuration.extension && {
                            Extension: configuration.extension,
                        }),
                    },
                },
            });
        }
        /**
         * This operation modifies an audio output configuration.
         * @param configuration
         */
        async setAudioOutputConfiguration(configuration) {
            configuration.sendPrimacy = 'www.onvif.org/ver20/HalfDuplex/Server';
            await this.request({
                SetAudioOutputConfiguration: {
                    Configuration: {
                        $: {
                            token: configuration.token,
                        },
                        Name: configuration.name,
                        UseCount: configuration.useCount,
                        OutputToken: configuration.outputToken,
                        SendPrimacy: configuration.sendPrimacy,
                    },
                },
            });
        }
        /**
         * This operation modifies an audio decoder configuration.
         * @param configuration
         */
        async setAudioDecoderConfiguration(configuration) {
            configuration.sendPrimacy = 'www.onvif.org/ver20/HalfDuplex/Server';
            await this.request({
                SetAudioDecoderConfiguration: {
                    Configuration: {
                        $: {
                            token: configuration.token,
                        },
                        Name: configuration.name,
                        UseCount: configuration.useCount,
                    },
                },
            });
        }
        async getConfigurationOptions(options) {
            const { configurationToken, profileToken, entityName } = options;
            const response = await this.request({
                [`Get${entityName}ConfigurationOptions`]: {
                    ConfigurationToken: configurationToken,
                    ProfileToken: profileToken,
                },
            }, { array: ['configurations'] });
            return response[`get${entityName}ConfigurationOptionsResponse`].options;
        }
        /**
         * This operation returns the available options (supported values and ranges for video source configuration
         * parameters) when the video source parameters are reconfigured If a video source configuration is specified, the
         * options shall concern that particular configuration. If a media profile is specified, the options shall be
         * compatible with that media profile.
         * @param options
         */
        async getVideoSourceConfigurationOptions(options = {}) {
            return this.getConfigurationOptions({ ...options, entityName: 'VideoSource' });
        }
        /**
         * This operation returns the available options (supported values and ranges for video encoder configuration
         * parameters) when the video encoder parameters are reconfigured.
         *
         * This response contains the available video encoder configuration options. If a video encoder configuration is
         * specified, the options shall concern that particular configuration. If a media profile is specified, the options
         * shall be compatible with that media profile. If no tokens are specified, the options shall be considered generic
         * for the device.
         * @param options
         */
        async getVideoEncoderConfigurationOptions(options = {}) {
            return this.getConfigurationOptions({ ...options, entityName: 'VideoEncoder' });
        }
        /**
         * This operation returns the available options (supported values and ranges for audio source configuration
         * parameters) when the audio source parameters are reconfigured. If an audio source configuration is specified, the
         * options shall concern that particular configuration. If a media profile is specified, the options shall be
         * compatible with that media profile.
         * @param options
         */
        async getAudioSourceConfigurationOptions(options = {}) {
            return this.getConfigurationOptions({ ...options, entityName: 'AudioSource' });
        }
        /**
         * This operation returns the available options (supported values and ranges for audio encoder configuration
         * parameters) when the audio encoder parameters are reconfigured.
         * @param options
         */
        async getAudioEncoderConfigurationOptions(options = {}) {
            return this.getConfigurationOptions({ ...options, entityName: 'AudioEncoder' });
        }
        /**
         * This operation returns the available options (supported values and ranges for metadata configuration parameters)
         * for changing the metadata configuration.
         * @param options
         */
        async getMetadataConfigurationOptions(options = {}) {
            return this.getConfigurationOptions({ ...options, entityName: 'Metadata' });
        }
        /**
         * This operation returns the available options (supported values and ranges for audio output configuration
         * parameters) for configuring an audio output. To retrieve the EQPresetList, a valid ConfigurationToken must be
         * provided. If EQPreset is supported and isFrequencyDecibelEditable is signaled as true, the response shall include
         * the FrequencyDecibelPair.
         * @param options
         */
        async getAudioOutputConfigurationOptions(options = {}) {
            return this.getConfigurationOptions({ ...options, entityName: 'AudioOutput' });
        }
        /**
         * This command list the audio decoding capabilities for a given profile and configuration of a device.
         * @param options
         */
        async getAudioDecoderConfigurationOptions(options = {}) {
            return this.getConfigurationOptions({ ...options, entityName: 'AudioDecoder' });
        }
        /**
         * The GetVideoEncoderInstances command can be used to request the minimum number of guaranteed video encoder
         * instances (applications) per Video Source Configuration.
         * @param options
         */
        async getVideoEncoderInstances(options) {
            const { configurationToken } = options;
            const response = await this.request({
                GetVideoEncoderInstances: {
                    ConfigurationToken: configurationToken,
                },
            });
            return response.getVideoEncoderInstancesResponse.info;
        }
        async setSynchronizationPoint({ profileToken }) {
            await this.request({
                SetSynchronizationPoint: {
                    ProfileToken: profileToken,
                },
            });
        }
        /**
         * This command starts multicast streaming using a specified media profile of a device. Streaming continues until
         * StopMulticastStreaming is called for the same Profile. The streaming shall continue after a reboot of the device
         * until a StopMulticastStreaming request is received. The multicast address, port and TTL are configured in the
         * VideoEncoderConfiguration, AudioEncoderConfiguration and MetadataConfiguration respectively.
         * @param profileToken
         */
        async startMulticastStreaming({ profileToken } = {}) {
            await this.request({
                StartMulticastStreaming: {
                    ProfileToken: profileToken ?? this.onvif.activeSource?.profileToken,
                },
            });
        }
        /**
         * This command stops multicast streaming using a specified media profile of a device
         * @param profileToken
         */
        async stopMulticastStreaming({ profileToken } = {}) {
            await this.request({
                StopMulticastStreaming: {
                    ProfileToken: profileToken ?? this.onvif.activeSource?.profileToken,
                },
            });
        }
        /**
         * A device returns the information for current video source mode and settable video source modes of specified video
         * source. A device that indicates a capability of VideoSourceModes shall support this command.
         * @param options
         */
        async getVideoSourceModes(options) {
            const videoSourceToken = options?.videoSourceToken ?? this.onvif.activeSource?.videoSourceToken;
            const response = await this.request({
                GetVideoSourceModes: {
                    VideoSourceToken: videoSourceToken,
                },
            }, { array: ['videoSourceModes'] });
            const modes = response.getVideoSourceModesResponse.videoSourceModes ?? [];
            return modes.map((mode) => ({ ...mode, encodings: mode.encodings.split(' ') }));
        }
        /**
         * SetVideoSourceMode changes the media profile structure relating to video source for the specified video source
         * mode. A device that indicates a capability of VideoSourceModes shall support this command. The behavior after
         * changing the mode is not defined in this specification.
         * @param options
         */
        async setVideoSourceMode({ videoSourceToken, videoSourceModeToken }) {
            await this.request({
                SetVideoSourceMode: {
                    VideoSourceToken: videoSourceToken,
                    VideoSourceModeToken: videoSourceModeToken,
                },
            });
        }
        /**
         * This operation lists existing OSD configurations for the device.
         * - If an OSD token is provided the device shall respond with the requested configuration or provide an error if it does not exist.
         * - In case only a video source configuration token is provided the device shall respond with all configurations that exist for the video source configuration.
         * - If no tokens are provided the device shall respond with all available OSD configurations.
         * @param options
         */
        async getOSDs(options) {
            const { configurationToken, OSDToken } = options ?? {};
            const response = await this.request({
                GetOSDs: {
                    OSDToken: OSDToken,
                    ConfigurationToken: configurationToken,
                },
            }, { array: ['OSDs'] });
            return response.getOSDsResponse.OSDs;
        }
        /**
         * Set the OSD
         * @param options
         */
        async setOSD(options) {
            await this.request({
                SetOSD: {
                    OSD: {
                        $: {
                            token: options.token,
                        },
                        VideoSourceConfigurationToken: options.videoSourceConfigurationToken,
                        Type: options.type,
                        Position: {
                            Type: options.position.type,
                            Pos: options.position.pos,
                            ...(options.position.extension && { Extension: options.position.extension }),
                        },
                        ...(options.textString && {
                            TextString: {
                                IsPersistentText: options.textString.isPersistentText,
                                Type: options.textString.type,
                                DateFormat: options.textString.dateFormat,
                                TimeFormat: options.textString.timeFormat,
                                FontSize: options.textString.fontSize,
                                ...(options.textString.fontColor && {
                                    FontColor: {
                                        Color: options.textString.fontColor.color,
                                        Transparent: options.textString.fontColor.transparent,
                                    },
                                }),
                                ...(options.textString.backgroundColor && {
                                    BackgroundColor: {
                                        Color: options.textString.backgroundColor.color,
                                        Transparent: options.textString.backgroundColor.transparent,
                                    },
                                }),
                                PlainText: options.textString.plainText,
                                Extension: options.textString.extension,
                            },
                        }),
                        ...(options.image && {
                            Image: {
                                ImgPath: options.image.imgPath,
                                Extension: options.image.extension,
                            },
                        }),
                        Extension: options.extension,
                    },
                },
            });
        }
        /**
         * Get the OSD Options.
         * @param configurationToken
         */
        async getOSDOptions({ configurationToken }) {
            const response = await this.request({
                GetOSDOptions: {
                    ConfigurationToken: configurationToken,
                },
            });
            return response.getOSDOptionsResponse.OSDOptions;
        }
        /**
         * Create the OSD.
         * NB!: Unlike the reference implementation, this method returns the generated configuration, since not all
         * implementations allow you to specify the token yourself; it is often generated on the server side.
         * @param options
         */
        async createOSD(options) {
            const response = await this.request({
                CreateOSD: {
                    OSD: {
                        $: {
                            token: options.token,
                        },
                        VideoSourceConfigurationToken: options.videoSourceConfigurationToken,
                        Type: options.type,
                        Position: {
                            Type: options.position.type,
                            Pos: options.position.pos,
                            ...(options.position.extension && { Extension: options.position.extension }),
                        },
                        ...(options.textString && {
                            TextString: {
                                IsPersistentText: options.textString.isPersistentText,
                                Type: options.textString.type,
                                DateFormat: options.textString.dateFormat,
                                TimeFormat: options.textString.timeFormat,
                                FontSize: options.textString.fontSize,
                                ...(options.textString.fontColor && {
                                    FontColor: {
                                        Color: options.textString.fontColor.color,
                                        Transparent: options.textString.fontColor.transparent,
                                    },
                                }),
                                ...(options.textString.backgroundColor && {
                                    BackgroundColor: {
                                        Color: options.textString.backgroundColor.color,
                                        Transparent: options.textString.backgroundColor.transparent,
                                    },
                                }),
                                PlainText: options.textString.plainText,
                                Extension: options.textString.extension,
                            },
                        }),
                        ...(options.image && {
                            Image: {
                                ImgPath: options.image.imgPath,
                                Extension: options.image.extension,
                            },
                        }),
                        Extension: options.extension,
                    },
                },
            });
            return response.createOSDResponse;
        }
        /**
         * Delete the OSD.
         * @param OSDToken
         */
        async deleteOSD({ OSDToken }) {
            await this.request({
                DeleteOSD: {
                    OSDToken,
                },
            });
        }
        /**
         * This operation lists existing Mask configurations for the device.
         * - If an Mask token is provided the device shall respond with the requested configuration or provide an error if it does not exist.
         * - In case only a video source configuration token is provided the device shall respond with all configurations that exist for the video source configuration.
         * - If no tokens are provided the device shall respond with all available Mask configurations.
         * @param options
         */
        async getMasks(options) {
            const { configurationToken, token } = options ?? {};
            const response = await this.request({
                GetMasks: {
                    Token: token,
                    ConfigurationToken: configurationToken,
                },
            }, { array: ['masks'] });
            return response.getMasksResponse.masks ?? [];
        }
        /**
         * Create the Mask.
         * @param options
         * @example
         * const { token } = await cam.media2.createMask({
         *     type: 'Color',
         *     token: 'mask_token_1',
         *     color: { X: 1, Y: 2, Z: 3, colorspace: 'http://www.onvif.org/ver10/colorspace/YCbCr' },
         *     configurationToken: 'VideoSourceConfigurationToken_1',
         *     enabled: true,
         *     polygon: {
         *       point: [{ x: 0.1, y: 0.1 }, { x: 0.2, y: 0.2 }, { x: 0.3, y: 0.3 }],
         *     }
         *   });
         */
        async createMask(options) {
            const response = await this.request({
                CreateMask: {
                    Mask: {
                        $: {
                            token: options.token,
                        },
                        ConfigurationToken: options.configurationToken,
                        Polygon: {
                            Point: options.polygon.point?.map((point) => ({
                                $: {
                                    x: point.x,
                                    y: point.y,
                                },
                            })),
                        },
                        Name: options.name,
                        Type: options.type,
                        ...(options.color && {
                            Color: {
                                $: {
                                    Colorspace: options.color.colorspace,
                                    Likelihood: options.color.likelihood,
                                    X: options.color.x,
                                    Y: options.color.y,
                                    Z: options.color.z,
                                },
                            },
                        }),
                        Enabled: options.enabled,
                    },
                },
            });
            return response.createMaskResponse;
        }
        /**
         * Set the Mask
         * @see {@link createMask}
         * @param options
         */
        async setMask(options) {
            await this.request({
                SetMask: {
                    Mask: {
                        $: {
                            token: options.token,
                        },
                        ConfigurationToken: options.configurationToken,
                        Polygon: {
                            Point: options.polygon.point?.map((point) => ({
                                $: {
                                    x: point.x,
                                    y: point.y,
                                },
                            })),
                        },
                        Name: options.name,
                        Type: options.type,
                        ...(options.color && {
                            Color: {
                                $: {
                                    Colorspace: options.color.colorspace,
                                    Likelihood: options.color.likelihood,
                                    X: options.color.x,
                                    Y: options.color.y,
                                    Z: options.color.z,
                                },
                            },
                        }),
                        Enabled: options.enabled,
                    },
                },
            });
        }
        /**
         * Get the Mask Options.
         * @param configurationToken
         * @example
         * const res = await cam.media2.getMaskOptions({ configurationToken: 'MaskToken_1' });
         * console.log(res.types);
         */
        async getMaskOptions({ configurationToken }) {
            const response = await this.request({
                GetMaskOptions: {
                    ConfigurationToken: configurationToken,
                },
            });
            return response.getMaskOptionsResponse.options;
        }
        /**
         * Delete the Mask.
         * @param token
         */
        async deleteMask({ token }) {
            await this.request({
                DeleteMask: {
                    Token: token,
                },
            });
        }
        /**
         * This operation requests a URI that can be used to initiate a live media stream using RTSP as the control protocol.
         * The returned URI shall remain valid indefinitely even if the profile is changed.
         *
         * Defined stream types are:
         *     RtspUnicast RTSP streaming RTP as UDP Unicast.
         *     RtspMulticast RTSP streaming RTP as UDP Multicast.
         *     RTSP RTSP streaming RTP over TCP.
         *     RtspOverHttp Tunneling both the RTSP control channel and the RTP stream over HTTP or HTTPS.
         *
         * If a multicast stream is requested at least one of VideoEncoder2Configuration, AudioEncoder2Configuration and
         * MetadataConfiguration shall have a valid multicast setting.
         */
        async getStreamUri({ protocol = 'RtspUnicast', profileToken }) {
            const response = await this.request({
                GetStreamUri: {
                    Protocol: protocol,
                    ProfileToken: profileToken ?? this.onvif.activeSource?.profileToken,
                },
            });
            return response.getStreamUriResponse;
        }
        async getSnapshotUri(options) {
            const { profileToken } = options ?? {};
            const response = await this.request({
                GetSnapshotUri: {
                    ProfileToken: profileToken ?? this.onvif.activeSource?.profileToken,
                },
            });
            return response.getSnapshotUriResponse;
        }
    };
})();
exports.default = Media2;
function v2(originalMethod, context) {
    return function v2(...args) {
        if (!this.onvif.device.media2Support) {
            throw new Error('Media2 profile is not supported for this device');
        }
        return originalMethod.call(this, ...args);
    };
}
//# sourceMappingURL=media2.js.map