UNPKG

ts-onvif

Version:

Client to ONVIF devices

142 lines 5.26 kB
"use strict"; /** * Action Engine ver10 module * @author Andrew D.Laptev <a.d.laptev@gmail.com> * @see https://www.onvif.org/ver10/actionengine.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"); /** * Action Engine service * @example * ```typescript * await cam.connect(); * const caps = await cam.actionEngine.getServiceCapabilities(); * const supported = await cam.actionEngine.getSupportedActions(); * const actions = await cam.actionEngine.getActions(); * const triggers = await cam.actionEngine.getActionTriggers(); * ``` */ class ActionEngine extends service_1.default { constructor(onvif) { super(onvif, 'actionengine'); } static tokensToBuild(tokens) { if (!tokens?.length) { return undefined; } return tokens.length === 1 ? tokens[0] : tokens; } static actionConfigurationToBuild(configuration) { return { $: { Name: configuration.name, Type: configuration.type }, Parameters: (0, toOnvifXMLSchemaObject_1.itemList)(configuration.parameters), }; } static actionToBuild(action) { return { $: { token: action.token }, Configuration: ActionEngine.actionConfigurationToBuild(action.configuration), }; } static actionTriggerConfigurationToBuild(configuration) { return { TopicExpression: configuration.topicExpression, ...(configuration.contentExpression !== undefined && { ContentExpression: configuration.contentExpression, }), ...(configuration.actionToken && { ActionToken: ActionEngine.tokensToBuild(configuration.actionToken), }), ...(configuration.extension && { Extension: configuration.extension }), }; } static actionTriggerToBuild(actionTrigger) { return { $: { token: actionTrigger.token }, Configuration: ActionEngine.actionTriggerConfigurationToBuild(actionTrigger.configuration), }; } /** * Returns the capabilities of the action engine service. */ async getServiceCapabilities() { const response = await this.request({ GetServiceCapabilities: {} }, { array: ['actionCapabilities'] }); return response.getServiceCapabilitiesResponse?.capabilities ?? {}; } /** * Returns the action types supported by the device. */ async getSupportedActions(_options = {}) { const response = await this.request({ GetSupportedActions: {} }, { array: ['actionDescription', 'actionContentSchemaLocation'] }); return response.getSupportedActionsResponse.supportedActions; } /** * Returns the configured actions. */ async getActions(_options = {}) { const response = await this.request({ GetActions: {} }, { array: ['action'] }); return response.getActionsResponse.action ?? []; } /** * Creates one or more actions. */ async createActions({ action = [] }) { const response = await this.request({ CreateActions: { Action: action.map(ActionEngine.actionConfigurationToBuild) } }, { array: ['action'] }); return response.createActionsResponse.action ?? []; } /** * Deletes one or more actions. */ async deleteActions({ token }) { await this.request({ DeleteActions: { Token: ActionEngine.tokensToBuild(token), }, }); } /** * Modifies one or more actions. */ async modifyActions({ action = [] }) { await this.request({ ModifyActions: { Action: action.map(ActionEngine.actionToBuild) } }); } /** * Returns the configured action triggers. */ async getActionTriggers(_options = {}) { const response = await this.request({ GetActionTriggers: {} }, { array: ['actionTrigger'] }); return response.getActionTriggersResponse.actionTrigger ?? []; } /** * Creates one or more action triggers. */ async createActionTriggers({ actionTrigger = [] }) { const response = await this.request({ CreateActionTriggers: { ActionTrigger: actionTrigger?.map(ActionEngine.actionTriggerConfigurationToBuild) } }, { array: ['actionTrigger'] }); return response.createActionTriggersResponse.actionTrigger ?? []; } /** * Modifies one or more action triggers. */ async modifyActionTriggers({ actionTrigger = [] }) { await this.request({ ModifyActionTriggers: { ActionTrigger: actionTrigger.map(ActionEngine.actionTriggerToBuild) }, }); } /** * Deletes one or more action triggers. */ async deleteActionTriggers({ token }) { await this.request({ DeleteActionTriggers: { Token: ActionEngine.tokensToBuild(token), }, }); } } exports.default = ActionEngine; //# sourceMappingURL=actionengine.js.map