UNPKG

ts-onvif

Version:

Client to ONVIF devices

126 lines 4.63 kB
"use strict"; /** * Federated Search ver10 module * @author Andrew D.Laptev <a.d.laptev@gmail.com> * @see https://www.onvif.org/ver10/federatedsearch.wsdl */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FederatedSearch = void 0; const service_1 = __importDefault(require("./service")); /** * Federated Search service * @example * ```ts * const caps = await cam.federatedSearch.getServiceCapabilities(); * const features = await cam.federatedSearch.getServiceFeatures({ inputCapabilities: {} }); * ``` */ class FederatedSearch extends service_1.default { constructor(onvif, service) { super(onvif, service); } static termTypeToBuild(term) { return { $: { href: term.href }, ...(term.name && { Name: term.name }), ...(term.description && { Description: term.description }), ...(term.term && { Term: FederatedSearch.oneOrMany(term.term, FederatedSearch.termTypeToBuild), }), }; } static oneOrMany(items, builder) { if (!items?.length) { return undefined; } const built = items.map((item) => builder(item)); return built.length === 1 ? built[0] : built; } static registerDatabaseToBuild(database) { return { ServiceID: database.serviceID, ...(database.recordingSearchInterfaceRegistration !== undefined && { RecordingSearchInterfaceRegistration: database.recordingSearchInterfaceRegistration, }), ...(database.supportedQFProfile && { SupportedQFProfile: FederatedSearch.termTypeToBuild(database.supportedQFProfile), }), ...(database.supportedMetadata && { SupportedMetadata: FederatedSearch.oneOrMany(database.supportedMetadata, (metadata) => metadata), }), ...(database.supportedExampleMediaTypes !== undefined && { SupportedExampleMediaTypes: database.supportedExampleMediaTypes, }), ...(database.supportedResultMediaTypes !== undefined && { SupportedResultMediaTypes: database.supportedResultMediaTypes, }), ...(database.supportedQueryTypes && { SupportedQueryTypes: FederatedSearch.oneOrMany(database.supportedQueryTypes, FederatedSearch.termTypeToBuild), }), ...(database.supportedExpressions && { SupportedExpressions: FederatedSearch.oneOrMany(database.supportedExpressions, FederatedSearch.termTypeToBuild), }), ...(database.extension && { Extension: database.extension }), }; } /** * Returns the capabilities of the federated search service. */ async getServiceCapabilities() { const response = await this.request({ GetServiceCapabilities: {}, }); return response.getServiceCapabilitiesResponse?.capabilities ?? {}; } /** * Returns service features matching the requested capabilities. * @param options */ async getServiceFeatures({ inputCapabilities }) { const response = await this.request({ GetServiceFeatures: { InputCapabilities: inputCapabilities, }, }); return response.getServiceFeaturesResponse ?? {}; } /** * Executes a federated search query. * @param options */ async search({ inputQuery }) { const response = await this.request({ Search: { InputQuery: inputQuery, }, }); return response.searchResponse ?? {}; } /** * Returns results from a previous search query. * @param options */ async getSearchResults({ results }) { const response = await this.request({ GetSearchResults: { Results: results, }, }, { array: ['resultItem'] }); return response.getSearchResultsResponse ?? {}; } /** * Registers a database with the federated search service. * @param options */ async registerDatabase(database) { const response = await this.request({ RegisterDatabase: FederatedSearch.registerDatabaseToBuild(database), }); return response.registerDatabaseResponse ?? {}; } } exports.FederatedSearch = FederatedSearch; //# sourceMappingURL=federatedsearch.js.map