dt-common-device
Version:
A secure and robust device management library for IoT applications
34 lines (33 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MicroServiceFactory = void 0;
const constants_1 = require("../constants");
const interfaces_1 = require("../entities/device/cloud/interfaces");
class MicroServiceFactory {
constructor(deviceType) {
this.deviceType = deviceType;
}
getMicroService() {
switch (this.deviceType) {
case interfaces_1.DeviceType.HUB:
case interfaces_1.DeviceType.ELEVATOR_LOCK:
case interfaces_1.DeviceType.LOCK:
return constants_1.SERVICE_NAMES.ACCESS;
case interfaces_1.DeviceType.THERMOSTAT:
return constants_1.SERVICE_NAMES.ENERGY;
case interfaces_1.DeviceType.TV:
return constants_1.SERVICE_NAMES.ENTERTAINMENT;
default:
throw new Error(`Invalid device type: ${this.deviceType}`);
}
}
static getInstance(deviceType) {
// Use device type as key to allow multiple instances for different device types
if (!MicroServiceFactory.instances.has(deviceType)) {
MicroServiceFactory.instances.set(deviceType, new MicroServiceFactory(deviceType));
}
return MicroServiceFactory.instances.get(deviceType);
}
}
exports.MicroServiceFactory = MicroServiceFactory;
MicroServiceFactory.instances = new Map();