UNPKG

onvif-nvt-ts

Version:

Wrapper for ONVIF spec to control NVT (Network Video Transitter) devices. Forked and added TypeScript support from onvif-nvt.

74 lines 3.07 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const camera_1 = __importDefault(require("./camera")); const Util = __importStar(require("./utils/util")); /** * If the OnvifManager class is used to connect to a camera, it will * manage your devices (cameras). It stores cameras by address. You * can use address to retrieve the camera. */ class OnvifManager { constructor() { this.cameras = {}; } /** * Connects to an ONVIF device. * @param address The address of the ONVIF device (ie: 10.10.1.20) * @param port The port of the ONVIF device. Defaults to 80. * @param username The user name used to make a connection. * @param password The password used to make a connection. * @param servicePath The service path for the camera. If null or 'undefined' the default path according to the ONVIF spec will be used. */ connect(address, port, username, password, servicePath) { const promise = new Promise((resolve, reject) => { let errMsg = ''; if ((errMsg = Util.isInvalidValue(address, 'string'))) { return reject(new Error('The "address" argument for connect is invalid: ' + errMsg)); } const cacheKey = `${address}:${port}`; const c = this.cameras[cacheKey]; if (c) { return resolve(c); } // default to port 80 if none provided port = port || 80; const camera = new camera_1.default(); return camera .connect(address, port, username, password, servicePath) .then(results => { // cache camera after successfully connecting this.cameras[cacheKey] = camera; resolve(camera); }) .catch(error => { console.error(error); reject(error); }); }); return promise; } } exports.default = new OnvifManager(); //# sourceMappingURL=onvif-nvt.js.map