2017-11-28 00:50:46 +02:00
|
|
|
class AlarmServiceDriverNode {
|
|
|
|
|
2017-11-28 02:22:38 +02:00
|
|
|
constructor() {
|
|
|
|
this.notifications_ = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
hasPersistentNotifications() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
notificationIsSet(id) {
|
|
|
|
return id in this.notifications_;
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:50:46 +02:00
|
|
|
async clearNotification(id) {
|
2017-11-28 02:22:38 +02:00
|
|
|
if (!this.notificationIsSet(id)) return;
|
|
|
|
clearTimeout(this.notifications_[id].timeoutId);
|
|
|
|
delete this.notifications_[id];
|
2017-11-28 00:50:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async scheduleNotification(notification) {
|
2017-11-28 02:22:38 +02:00
|
|
|
const now = Date.now();
|
|
|
|
const interval = notification.date.getTime() - now;
|
|
|
|
if (interval < 0) return;
|
2017-11-28 00:50:46 +02:00
|
|
|
|
2017-11-28 02:22:38 +02:00
|
|
|
const timeoutId = setTimeout(() => {
|
|
|
|
console.info('NOTIFICATION: ', notification);
|
|
|
|
this.clearNotification(notification.id);
|
|
|
|
}, interval);
|
2017-11-28 00:50:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = AlarmServiceDriverNode;
|