Disable notifications on new 'reconnect' event for laptop resume

This commit is contained in:
Scott Nonnenberg 2018-07-03 14:56:30 -07:00
parent e83e10a7d1
commit a40a39314a
2 changed files with 14 additions and 0 deletions

View file

@ -368,6 +368,7 @@
messageReceiver.addEventListener('verified', onVerified);
messageReceiver.addEventListener('error', onError);
messageReceiver.addEventListener('empty', onEmpty);
messageReceiver.addEventListener('reconnect', onReconnect);
messageReceiver.addEventListener('progress', onProgress);
messageReceiver.addEventListener('configuration', onConfiguration);
@ -460,6 +461,13 @@
Whisper.Notifications.enable();
}
function onReconnect() {
// We disable notifications on first connect, but the same applies to reconnect. In
// scenarios where we're coming back from sleep, we can get offline/online events
// very fast, and it looks like a network blip. But we need to suppress
// notifications in these scenarios too. So we listen for 'reconnect' events.
Whisper.Notifications.disable();
}
function onProgress(ev) {
const { count } = ev;

View file

@ -39,6 +39,12 @@ MessageReceiver.prototype.extend({
return;
}
this.count = 0;
if (this.hasConnected) {
const ev = new Event('reconnect');
this.dispatchEvent(ev);
}
this.hasConnected = true;
if (this.socket && this.socket.readyState !== WebSocket.CLOSED) {