web socket wait interval
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user