web socket wait interval

This commit is contained in:
Yuri Kuznetsov
2024-02-11 16:46:19 +02:00
parent 47735aaa0b
commit e5e29101fd
+36 -3
View File
@@ -34,6 +34,7 @@ class NotificationBadgeView extends View {
notificationsCheckInterval = 10
groupedCheckInterval = 15
waitInterval = 2
/** @private */
useWebSocket = false
@@ -249,9 +250,7 @@ class NotificationBadgeView extends View {
this.checkUpdates(isFirstCheck);
if (this.useWebSocket) {
this.getHelper().webSocketManager.subscribe('newNotification', () => {
this.checkUpdates();
});
this.initWebSocketCheckUpdates();
return;
}
@@ -262,6 +261,40 @@ class NotificationBadgeView extends View {
);
}
/**
* @private
*/
initWebSocketCheckUpdates() {
let isBlocked = false;
let hasBeenBlocked = false;
const onWebSocketNewNotification = () => {
if (isBlocked) {
hasBeenBlocked = true;
return;
}
this.checkUpdates();
isBlocked = true;
setTimeout(() => {
const reRun = hasBeenBlocked;
isBlocked = false;
hasBeenBlocked = false;
if (reRun) {
onWebSocketNewNotification();
}
}, this.waitInterval * 1000);
};
this.getHelper().webSocketManager.subscribe('newNotification', () => onWebSocketNewNotification());
}
/**
* @private
* @return {boolean}