2021-09-08 08:27:37 +00:00
|
|
|
/**
|
|
|
|
* Main monitor list
|
|
|
|
*/
|
2021-09-08 06:16:30 +00:00
|
|
|
class UserMonitorList {
|
|
|
|
list = {};
|
|
|
|
|
2021-09-08 10:58:02 +00:00
|
|
|
/**
|
|
|
|
* Add or update
|
|
|
|
* @param userID
|
|
|
|
* @param monitor
|
|
|
|
*/
|
2021-09-08 06:16:30 +00:00
|
|
|
add(userID, monitor) {
|
|
|
|
if (! this.list[userID]) {
|
|
|
|
this.list[userID] = {};
|
|
|
|
}
|
2021-09-08 10:58:02 +00:00
|
|
|
|
|
|
|
// Stopped the old monitor if same id
|
|
|
|
this.stop(userID, monitor.id);
|
|
|
|
|
2021-09-08 06:16:30 +00:00
|
|
|
this.list[userID][monitor.id] = monitor;
|
|
|
|
}
|
|
|
|
|
2021-09-08 10:58:02 +00:00
|
|
|
stop(userID, monitorID) {
|
|
|
|
if (this.list[userID][monitorID]) {
|
|
|
|
let oldMonitor = this.list[userID][monitorID];
|
|
|
|
|
|
|
|
if (oldMonitor) {
|
|
|
|
oldMonitor.stop();
|
|
|
|
} else {
|
|
|
|
console.log("No old monitor: " + monitorID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-08 06:16:30 +00:00
|
|
|
delete(userID, monitorID) {
|
2021-09-08 10:58:02 +00:00
|
|
|
this.stop(userID, monitorID);
|
2021-09-08 06:16:30 +00:00
|
|
|
let monitorList = this.getMonitorList(userID);
|
|
|
|
delete monitorList[monitorID];
|
|
|
|
}
|
|
|
|
|
|
|
|
getMonitor(userID, monitorID) {
|
|
|
|
let monitorList = this.getMonitorList(userID);
|
|
|
|
|
|
|
|
if (monitorList[monitorID]) {
|
|
|
|
return monitorList[monitorID];
|
|
|
|
} else {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getMonitorList(userID) {
|
|
|
|
if (this.list[userID]) {
|
|
|
|
return this.list[userID];
|
|
|
|
} else {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getAllMonitorList() {
|
|
|
|
let list = {};
|
|
|
|
for (let userID in this.list) {
|
|
|
|
let monitorList = this.list[userID];
|
|
|
|
|
|
|
|
for (let monitorID in monitorList) {
|
|
|
|
list[monitorID] = monitorList[monitorID];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-09-08 08:27:37 +00:00
|
|
|
module.exports = {
|
|
|
|
userMonitorList: new UserMonitorList(),
|
|
|
|
};
|