Disconnect from socket faster on loss of network access (#1512)
* Disconnect from socket faster on complete loss of network access Today we wait for a keepalive request to fail; this change forces disconnect in the case that the browser tells us that we're now offline. FREEBIE * MessageReceiver: don't react to errors after explicit close() FREEBIE
This commit is contained in:
parent
b0f9644c14
commit
6323f598b5
3 changed files with 41 additions and 8 deletions
|
@ -149,9 +149,9 @@
|
|||
Whisper.events.on('start-shutdown', function() {
|
||||
if (messageReceiver) {
|
||||
messageReceiver.close().then(function() {
|
||||
messageReceiver = null;
|
||||
Whisper.events.trigger('shutdown-complete');
|
||||
});
|
||||
messageReceiver = null;
|
||||
} else {
|
||||
Whisper.events.trigger('shutdown-complete');
|
||||
}
|
||||
|
@ -159,11 +159,15 @@
|
|||
|
||||
function connect(firstRun) {
|
||||
window.removeEventListener('online', connect);
|
||||
window.addEventListener('offline', disconnect);
|
||||
|
||||
if (!Whisper.Registration.everDone()) { return; }
|
||||
if (Whisper.Import.isIncomplete()) { return; }
|
||||
|
||||
if (messageReceiver) { messageReceiver.close(); }
|
||||
if (messageReceiver) {
|
||||
messageReceiver.close();
|
||||
messageReceiver = null;
|
||||
}
|
||||
|
||||
var USERNAME = storage.get('number_id');
|
||||
var PASSWORD = storage.get('password');
|
||||
|
@ -439,6 +443,17 @@
|
|||
return message;
|
||||
}
|
||||
|
||||
function disconnect() {
|
||||
window.removeEventListener('offline', disconnect);
|
||||
window.addEventListener('online', connect);
|
||||
|
||||
console.log('offline');
|
||||
if (messageReceiver) {
|
||||
messageReceiver.close();
|
||||
messageReceiver = null;
|
||||
}
|
||||
}
|
||||
|
||||
function onError(ev) {
|
||||
var error = ev.error;
|
||||
console.log(error);
|
||||
|
@ -457,10 +472,6 @@
|
|||
setTimeout(connect, 60000);
|
||||
|
||||
Whisper.events.trigger('reconnectTimer');
|
||||
} else {
|
||||
console.log('offline');
|
||||
if (messageReceiver) { messageReceiver.close(); }
|
||||
window.addEventListener('online', connect);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -38394,6 +38394,7 @@ MessageReceiver.prototype.extend({
|
|||
this.incoming = [this.pending];
|
||||
},
|
||||
close: function() {
|
||||
this.calledClose = true;
|
||||
this.socket.close(3000, 'called close');
|
||||
return this.drain();
|
||||
},
|
||||
|
@ -38407,7 +38408,17 @@ MessageReceiver.prototype.extend({
|
|||
return Promise.all(this.dispatchEvent(event));
|
||||
},
|
||||
onclose: function(ev) {
|
||||
console.log('websocket closed', ev.code, ev.reason || '');
|
||||
console.log(
|
||||
'websocket closed',
|
||||
ev.code,
|
||||
ev.reason || '',
|
||||
'calledClose:',
|
||||
this.calledClose
|
||||
);
|
||||
|
||||
if (this.calledClose) {
|
||||
return;
|
||||
}
|
||||
if (ev.code === 3000) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ MessageReceiver.prototype.extend({
|
|||
this.incoming = [this.pending];
|
||||
},
|
||||
close: function() {
|
||||
this.calledClose = true;
|
||||
this.socket.close(3000, 'called close');
|
||||
return this.drain();
|
||||
},
|
||||
|
@ -53,7 +54,17 @@ MessageReceiver.prototype.extend({
|
|||
return Promise.all(this.dispatchEvent(event));
|
||||
},
|
||||
onclose: function(ev) {
|
||||
console.log('websocket closed', ev.code, ev.reason || '');
|
||||
console.log(
|
||||
'websocket closed',
|
||||
ev.code,
|
||||
ev.reason || '',
|
||||
'calledClose:',
|
||||
this.calledClose
|
||||
);
|
||||
|
||||
if (this.calledClose) {
|
||||
return;
|
||||
}
|
||||
if (ev.code === 3000) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue