camstreamerlib
Version:
Helper library for CamStreamer ACAP applications.
49 lines (48 loc) • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AxisCameraStationEvents = void 0;
const DefaultClient_1 = require("../node/DefaultClient");
const utils_1 = require("../internal/utils");
class AxisCameraStationEvents {
sourceKey;
client;
constructor(sourceKey, opt = {}) {
this.sourceKey = sourceKey;
if ((0, utils_1.isClient)(opt)) {
this.client = opt;
}
else {
this.client = new DefaultClient_1.DefaultClient(opt);
}
}
async sendEvent(data, eventType) {
const dateString = this.getDate();
const event = {
addExternalDataRequest: {
occurrenceTime: dateString,
source: this.sourceKey,
externalDataType: eventType,
data: data,
},
};
const eventData = JSON.stringify(event);
const res = await this.client.post('/Acs/Api/ExternalDataFacade/AddExternalData', eventData, undefined, {
'Content-Type': 'application/json',
'Content-Length': eventData.length.toString(),
});
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;