camstreamerlib
Version:
Helper library for CamStreamer ACAP applications.
41 lines (40 loc) • 1.71 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProxyClient = void 0;
const utils_1 = require("./utils");
class ProxyClient {
client;
proxyParams;
constructor(client, proxyParams) {
this.client = client;
this.proxyParams = proxyParams;
}
get(params) {
const { path, parameters, headers, timeout } = params;
const targetPath = (0, utils_1.addParametersToPath)(path, parameters);
const { realPath, realHeaders } = this.getReal(targetPath, headers);
return this.client.get({ path: realPath, headers: realHeaders, timeout });
}
post(params) {
const { path, data, parameters, headers, timeout } = params;
const targetPath = (0, utils_1.addParametersToPath)(path, parameters);
const { realPath, realHeaders } = this.getReal(targetPath, headers);
return this.client.post({ path: realPath, data, headers: realHeaders, timeout });
}
getReal(targetPath, headers) {
return {
realPath: this.proxyParams.path,
realHeaders: {
...(headers ?? {}),
'x-target-camera-protocol': this.proxyParams.target.port === 443 ? 'https' : 'http',
'x-target-camera-path': targetPath,
'x-target-camera-ip': this.proxyParams.target.ip,
'x-target-camera-mdns': this.proxyParams.target.mdnsName,
'x-target-camera-port': String(this.proxyParams.target.port),
'x-target-camera-pass': this.proxyParams.target.pass,
'x-target-camera-user': this.proxyParams.target.user,
},
};
}
}
exports.ProxyClient = ProxyClient;