camstreamerlib
Version:
Helper library for CamStreamer ACAP applications.
37 lines (36 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultClient = void 0;
const utils_1 = require("../internal/utils");
class DefaultClient {
domain;
constructor(domain = '') {
this.domain = domain;
}
get = (params) => {
return this.fetchWithTimeout((0, utils_1.addParametersToPath)(params.path, params.parameters), {
method: 'GET',
headers: params.headers,
}, params.timeout);
};
post = (params) => {
return this.fetchWithTimeout((0, utils_1.addParametersToPath)(params.path, params.parameters), {
method: 'POST',
body: params.data,
headers: params.headers,
}, params.timeout);
};
async fetchWithTimeout(path, options, timeout) {
const controller = new AbortController();
const timeoutId = timeout !== undefined ? setTimeout(() => controller.abort(), timeout) : null;
try {
return await fetch(`${this.domain}${path}`, { ...options, signal: controller.signal });
}
finally {
if (timeoutId) {
clearTimeout(timeoutId);
}
}
}
}
exports.DefaultClient = DefaultClient;