UNPKG

camstreamerlib

Version:

Helper library for CamStreamer ACAP applications.

53 lines (52 loc) 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DefaultClient = void 0; const utils_1 = require("../internal/utils"); const HttpRequestSender_1 = require("./HttpRequestSender"); class DefaultClient { tls; ip; port; user; pass; httpRequestSender; constructor(opt = {}) { this.tls = opt.tls ?? false; this.ip = opt.ip ?? '127.0.0.1'; this.port = opt.port ?? (this.tls ? 443 : 80); this.user = opt.user ?? ''; this.pass = opt.pass ?? ''; let agentOptions; if (opt.tlsInsecure !== undefined || opt.keepAlive !== undefined) { agentOptions = { rejectUnaurhorized: !opt.tlsInsecure, keepAlive: opt.keepAlive, }; } this.httpRequestSender = new HttpRequestSender_1.HttpRequestSender(agentOptions); } get(params) { const { path, parameters, headers, timeout } = params; const options = this.getBaseConnectionParams('GET', path, parameters, headers, timeout); return this.httpRequestSender.sendRequest(options); } post(params) { const { path, data, parameters, headers, timeout } = params; const options = this.getBaseConnectionParams('POST', path, parameters, headers, timeout); return this.httpRequestSender.sendRequest(options, data); } getBaseConnectionParams(method, path, params, headers, timeout) { return { method: method, protocol: this.tls ? 'https:' : 'http:', host: this.ip, port: this.port, path: (0, utils_1.addParametersToPath)(path, params), user: this.user, pass: this.pass, headers, timeout, }; } } exports.DefaultClient = DefaultClient;