Improve reconnect logic

Always test connectivity with an http request after a websocket closes,
regardless of what code/error it closed with. If that request succeeds,
automatically reconnect the socket.

// FREEBIE
This commit is contained in:
lilia 2015-09-09 01:24:36 -07:00
parent 756875f235
commit 16de5aa3d3
2 changed files with 12 additions and 16 deletions

View file

@ -39398,14 +39398,12 @@ function generateKeys(count, progressCallback) {
// initialize the socket and start listening for messages
this.socket = TextSecureServer.getMessageWebsocket(url);
this.socket.onclose = function(e) {
if (e.code === 1006) {
// possible 403. Make an request to confirm
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) {
var ev = new Event('textsecure:error');
ev.error = e;
eventTarget.dispatchEvent(ev);
});
}
// possible 403. Make a request to confirm
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) {
var ev = new Event('textsecure:error');
ev.error = e;
eventTarget.dispatchEvent(ev);
}).then(this.connect.bind(this)); // No HTTP error? Reconnect.
};
this.wsr = new WebSocketResource(this.socket, {

View file

@ -22,14 +22,12 @@
// initialize the socket and start listening for messages
this.socket = TextSecureServer.getMessageWebsocket(url);
this.socket.onclose = function(e) {
if (e.code === 1006) {
// possible 403. Make an request to confirm
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) {
var ev = new Event('textsecure:error');
ev.error = e;
eventTarget.dispatchEvent(ev);
});
}
// possible 403. Make a request to confirm
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) {
var ev = new Event('textsecure:error');
ev.error = e;
eventTarget.dispatchEvent(ev);
}).then(this.connect.bind(this)); // No HTTP error? Reconnect.
};
this.wsr = new WebSocketResource(this.socket, {