dt-common-device
Version:
A secure and robust device management library for IoT applications
45 lines (44 loc) • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventHandler = void 0;
const dt_pub_sub_1 = require("dt-pub-sub");
const dt_audit_library_1 = require("dt-audit-library");
class EventHandler {
constructor() {
this.source = "dt-common-device";
}
async onStateChange(deviceId, state) {
await dt_pub_sub_1.eventDispatcher.publishEvent("device.state.set", { deviceId, state }, this.source);
const payload = {
eventType: "device.state.set",
properties: {
deviceId,
state,
},
};
await (0, dt_audit_library_1.publishAudit)(payload);
}
async onStatusChange(deviceId, status) {
await dt_pub_sub_1.eventDispatcher.publishEvent("device.status.set", { deviceId, status }, this.source);
const payload = {
eventType: "device.status.set",
properties: {
deviceId,
status,
},
};
await (0, dt_audit_library_1.publishAudit)(payload);
}
async onBatteryLevelChange(deviceId, batteryLevel) {
await dt_pub_sub_1.eventDispatcher.publishEvent("device.battery.set", { deviceId, batteryLevel }, this.source);
const payload = {
eventType: "device.battery.set",
properties: {
deviceId,
batteryLevel,
},
};
await (0, dt_audit_library_1.publishAudit)(payload);
}
}
exports.EventHandler = EventHandler;