UNPKG

ts-onvif

Version:

Client to ONVIF devices

311 lines 11.7 kB
"use strict"; /** * AccessControl ver10 module * @author Andrew D.Laptev <a.d.laptev@gmail.com> * @see https://www.onvif.org/ver10/accesscontrol/wsdl/accesscontrol.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"); /** * AccessControl service * @example * ```ts * const list = await cam.accessControl.getAccessPointInfoList(); * const token = list.accessPointInfo![0].token; * console.log((await cam.accessControl.getAccessPointState({ token })).enabled); * await cam.accessControl.disableAccessPoint({ token }); * ``` */ class AccessControl extends service_1.default { constructor(onvif) { super(onvif, 'accesscontrol'); } static accessPointCapabilitiesToBuild(capabilities) { return { $: { DisableAccessPoint: capabilities.disableAccessPoint, ...(capabilities.duress !== undefined && { Duress: capabilities.duress }), ...(capabilities.anonymousAccess !== undefined && { AnonymousAccess: capabilities.anonymousAccess, }), ...(capabilities.accessTaken !== undefined && { AccessTaken: capabilities.accessTaken }), ...(capabilities.externalAuthorization !== undefined && { ExternalAuthorization: capabilities.externalAuthorization, }), ...(capabilities.supportedRecognitionTypes && { SupportedRecognitionTypes: (0, toOnvifXMLSchemaObject_1.stringListToBuild)(capabilities.supportedRecognitionTypes), }), ...(capabilities.identifierAccess !== undefined && { IdentifierAccess: capabilities.identifierAccess, }), ...(capabilities.supportedFeedbackTypes && { SupportedFeedbackTypes: (0, toOnvifXMLSchemaObject_1.stringListToBuild)(capabilities.supportedFeedbackTypes), }), }, ...(capabilities.supportedSecurityLevels && { SupportedSecurityLevels: capabilities.supportedSecurityLevels, }), ...(capabilities.extension && { Extension: capabilities.extension }), }; } static accessPointInfoToBuild(accessPoint) { return { $: { token: accessPoint.token }, Name: accessPoint.name, ...(accessPoint.description && { Description: accessPoint.description }), ...(accessPoint.areaFrom && { AreaFrom: accessPoint.areaFrom }), ...(accessPoint.areaTo && { AreaTo: accessPoint.areaTo }), ...(accessPoint.entityType !== undefined && { EntityType: accessPoint.entityType }), Entity: accessPoint.entity, Capabilities: AccessControl.accessPointCapabilitiesToBuild(accessPoint.capabilities), }; } static accessPointToBuild(accessPoint) { return { ...AccessControl.accessPointInfoToBuild(accessPoint), ...(accessPoint.authenticationProfileToken && { AuthenticationProfileToken: accessPoint.authenticationProfileToken, }), ...(accessPoint.extension && { Extension: accessPoint.extension }), }; } static areaInfoToBuild(area) { return { $: { token: area.token }, Name: area.name, ...(area.description && { Description: area.description }), }; } static areaToBuild(area) { return { ...AccessControl.areaInfoToBuild(area), ...(area.extension && { Extension: area.extension }), }; } /** * Returns the capabilities of the access control service. */ async getServiceCapabilities() { const response = await this.request({ GetServiceCapabilities: {} }); return response.getServiceCapabilitiesResponse?.capabilities ?? {}; } /** * Returns a list of access point info items. * @param options */ async getAccessPointInfoList(options = {}) { const response = await this.request({ GetAccessPointInfoList: { ...(options.limit !== undefined && { Limit: options.limit }), ...(options.startReference && { StartReference: options.startReference }), }, }, { array: ['accessPointInfo'] }); return response.getAccessPointInfoListResponse ?? {}; } /** * Returns access point info items for the requested tokens. * @param options */ async getAccessPointInfo({ token }) { const response = await this.request({ GetAccessPointInfo: { Token: token } }, { array: ['accessPointInfo'] }); return response.getAccessPointInfoResponse ?? {}; } /** * Returns a list of access point items. * @param options */ async getAccessPointList(options = {}) { const response = await this.request({ GetAccessPointList: { ...(options.limit !== undefined && { Limit: options.limit }), ...(options.startReference && { StartReference: options.startReference }), }, }, { array: ['accessPoint'] }); return response.getAccessPointListResponse ?? {}; } /** * Returns access point items for the requested tokens. * @param options */ async getAccessPoints({ token }) { const response = await this.request({ GetAccessPoints: { Token: token } }, { array: ['accessPoint'] }); return response.getAccessPointsResponse ?? {}; } /** * Creates a new access point. * @param options */ async createAccessPoint({ accessPoint }) { const response = await this.request({ CreateAccessPoint: { AccessPoint: AccessControl.accessPointToBuild(accessPoint) }, }); return response.createAccessPointResponse.token; } /** * Creates or replaces an access point (requires ClientSuppliedTokenSupported). * @param options */ async setAccessPoint({ accessPoint }) { await this.request({ SetAccessPoint: { AccessPoint: AccessControl.accessPointToBuild(accessPoint) } }); } /** * Modifies an existing access point. * @param options */ async modifyAccessPoint({ accessPoint }) { await this.request({ ModifyAccessPoint: { AccessPoint: AccessControl.accessPointToBuild(accessPoint) } }); } /** * Deletes an access point. * @param options */ async deleteAccessPoint({ token }) { await this.request({ DeleteAccessPoint: { Token: token } }); } /** * Sets the authentication profile of an access point. * @param options */ async setAccessPointAuthenticationProfile({ token, authenticationProfileToken, }) { await this.request({ SetAccessPointAuthenticationProfile: { Token: token, AuthenticationProfileToken: authenticationProfileToken, }, }); } /** * Deletes the authentication profile reference from an access point. * @param options */ async deleteAccessPointAuthenticationProfile({ token }) { await this.request({ DeleteAccessPointAuthenticationProfile: { Token: token } }); } /** * Returns a list of area info items. * @param options */ async getAreaInfoList(options = {}) { const response = await this.request({ GetAreaInfoList: { ...(options.limit !== undefined && { Limit: options.limit }), ...(options.startReference && { StartReference: options.startReference }), }, }, { array: ['areaInfo'] }); return response.getAreaInfoListResponse ?? {}; } /** * Returns area info items for the requested tokens. * @param options */ async getAreaInfo({ token }) { const response = await this.request({ GetAreaInfo: { Token: token } }, { array: ['areaInfo'] }); return response.getAreaInfoResponse ?? {}; } /** * Returns a list of area items. * @param options */ async getAreaList(options = {}) { const response = await this.request({ GetAreaList: { ...(options.limit !== undefined && { Limit: options.limit }), ...(options.startReference && { StartReference: options.startReference }), }, }, { array: ['area'] }); return response.getAreaListResponse ?? {}; } /** * Returns area items for the requested tokens. * @param options */ async getAreas({ token }) { const response = await this.request({ GetAreas: { Token: token } }, { array: ['area'] }); return response.getAreasResponse ?? {}; } /** * Creates a new area. * @param options */ async createArea({ area }) { const response = await this.request({ CreateArea: { Area: AccessControl.areaToBuild(area) } }); return response.createAreaResponse.token; } /** * Creates or replaces an area (requires ClientSuppliedTokenSupported). * @param options */ async setArea({ area }) { await this.request({ SetArea: { Area: AccessControl.areaToBuild(area) } }); } /** * Modifies an existing area. * @param options */ async modifyArea({ area }) { await this.request({ ModifyArea: { Area: AccessControl.areaToBuild(area) } }); } /** * Deletes an area. * @param options */ async deleteArea({ token }) { await this.request({ DeleteArea: { Token: token } }); } /** * Returns the current state of an access point. * @param options */ async getAccessPointState({ token }) { const response = await this.request({ GetAccessPointState: { Token: token } }); return response.getAccessPointStateResponse.accessPointState; } /** * Enables an access point. * @param options */ async enableAccessPoint({ token }) { await this.request({ EnableAccessPoint: { Token: token } }); } /** * Disables an access point. * @param options */ async disableAccessPoint({ token }) { await this.request({ DisableAccessPoint: { Token: token } }); } /** * Informs the device about an external authorization decision. * @param options */ async externalAuthorization({ accessPointToken, credentialToken, reason, decision, }) { await this.request({ ExternalAuthorization: { AccessPointToken: accessPointToken, ...(credentialToken && { CredentialToken: credentialToken }), ...(reason && { Reason: reason }), Decision: decision, }, }); } /** * Provides feedback for an access point. * @param options */ async feedback({ accessPointToken, feedbackType, recognitionType, textMessage }) { await this.request({ Feedback: { AccessPointToken: accessPointToken, FeedbackType: feedbackType, ...(recognitionType && { RecognitionType: recognitionType }), ...(textMessage && { TextMessage: textMessage }), }, }); } } exports.default = AccessControl; //# sourceMappingURL=accesscontrol.js.map