camstreamerlib
Version:
Helper library for CamStreamer ACAP applications.
54 lines (53 loc) • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AxisCameraStationEvents = void 0;
const utils_1 = require("../../internal/utils");
const ProxyClient_1 = require("../../internal/ProxyClient");
const DefaultClient_1 = require("../DefaultClient");
class AxisCameraStationEvents {
sourceKey;
client;
constructor(clientOptions, sourceKey) {
this.sourceKey = sourceKey;
this.client = new DefaultClient_1.DefaultClient(clientOptions);
}
getClient(proxyParams) {
return proxyParams ? new ProxyClient_1.ProxyClient(this.client, proxyParams) : this.client;
}
async sendEvent(data, eventType, options) {
const dateString = this.getDate();
const event = {
addExternalDataRequest: {
occurrenceTime: dateString,
source: this.sourceKey,
externalDataType: eventType,
data: data,
},
};
const eventData = JSON.stringify(event);
const agent = this.getClient(options?.proxyParams);
const res = await agent.post({
path: '/Acs/Api/ExternalDataFacade/AddExternalData',
data: eventData,
headers: {
'Content-Type': 'application/json',
'Content-Length': eventData.length.toString(),
},
timeout: options?.timeout,
});
if (!res.ok) {
throw new Error(`ACS status code: ${res.status}`);
}
}
getDate() {
const date = new Date();
const year = date.getUTCFullYear();
const month = (0, utils_1.pad)(date.getUTCMonth() + 1, 2);
const day = (0, utils_1.pad)(date.getUTCDate(), 2);
const hours = (0, utils_1.pad)(date.getUTCHours(), 2);
const minutes = (0, utils_1.pad)(date.getUTCMinutes(), 2);
const seconds = (0, utils_1.pad)(date.getUTCSeconds(), 2);
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
}
exports.AxisCameraStationEvents = AxisCameraStationEvents;