Fix reconnect bugs from previous commit
Forgot to bind the socket event handler, and the then() handler should come before the catch() handler or else it will execute every time the catch handler executes. // FREEBIE
This commit is contained in:
parent
16de5aa3d3
commit
6b483195cb
2 changed files with 24 additions and 18 deletions
|
@ -39383,28 +39383,31 @@ function generateKeys(count, progressCallback) {
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
|
|
||||||
function MessageReceiver(url, eventTarget) {
|
function MessageReceiver(url, eventTarget) {
|
||||||
|
this.url = url;
|
||||||
if (eventTarget instanceof EventTarget) {
|
if (eventTarget instanceof EventTarget) {
|
||||||
this.target = eventTarget;
|
this.target = eventTarget;
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError('MessageReceiver expected an EventTarget');
|
throw new TypeError('MessageReceiver expected an EventTarget');
|
||||||
}
|
}
|
||||||
this.connect(url);
|
this.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageReceiver.prototype = {
|
MessageReceiver.prototype = {
|
||||||
constructor: MessageReceiver,
|
constructor: MessageReceiver,
|
||||||
connect: function(url) {
|
connect: function() {
|
||||||
var eventTarget = this.target;
|
var eventTarget = this.target;
|
||||||
// initialize the socket and start listening for messages
|
// initialize the socket and start listening for messages
|
||||||
this.socket = TextSecureServer.getMessageWebsocket(url);
|
this.socket = TextSecureServer.getMessageWebsocket(this.url);
|
||||||
this.socket.onclose = function(e) {
|
this.socket.onclose = function(e) {
|
||||||
// possible 403. Make a request to confirm
|
// possible 403. Make a request to confirm
|
||||||
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) {
|
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).
|
||||||
|
then(this.connect.bind(this)).
|
||||||
|
catch(function(e) {
|
||||||
var ev = new Event('textsecure:error');
|
var ev = new Event('textsecure:error');
|
||||||
ev.error = e;
|
ev.error = e;
|
||||||
eventTarget.dispatchEvent(ev);
|
eventTarget.dispatchEvent(ev);
|
||||||
}).then(this.connect.bind(this)); // No HTTP error? Reconnect.
|
});
|
||||||
};
|
}.bind(this);
|
||||||
|
|
||||||
this.wsr = new WebSocketResource(this.socket, {
|
this.wsr = new WebSocketResource(this.socket, {
|
||||||
handleRequest: this.handleRequest.bind(this),
|
handleRequest: this.handleRequest.bind(this),
|
||||||
|
|
|
@ -7,28 +7,31 @@
|
||||||
window.textsecure = window.textsecure || {};
|
window.textsecure = window.textsecure || {};
|
||||||
|
|
||||||
function MessageReceiver(url, eventTarget) {
|
function MessageReceiver(url, eventTarget) {
|
||||||
|
this.url = url;
|
||||||
if (eventTarget instanceof EventTarget) {
|
if (eventTarget instanceof EventTarget) {
|
||||||
this.target = eventTarget;
|
this.target = eventTarget;
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError('MessageReceiver expected an EventTarget');
|
throw new TypeError('MessageReceiver expected an EventTarget');
|
||||||
}
|
}
|
||||||
this.connect(url);
|
this.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageReceiver.prototype = {
|
MessageReceiver.prototype = {
|
||||||
constructor: MessageReceiver,
|
constructor: MessageReceiver,
|
||||||
connect: function(url) {
|
connect: function() {
|
||||||
var eventTarget = this.target;
|
var eventTarget = this.target;
|
||||||
// initialize the socket and start listening for messages
|
// initialize the socket and start listening for messages
|
||||||
this.socket = TextSecureServer.getMessageWebsocket(url);
|
this.socket = TextSecureServer.getMessageWebsocket(this.url);
|
||||||
this.socket.onclose = function(e) {
|
this.socket.onclose = function(e) {
|
||||||
// possible 403. Make a request to confirm
|
// possible 403. Make a request to confirm
|
||||||
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) {
|
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).
|
||||||
|
then(this.connect.bind(this)).
|
||||||
|
catch(function(e) {
|
||||||
var ev = new Event('textsecure:error');
|
var ev = new Event('textsecure:error');
|
||||||
ev.error = e;
|
ev.error = e;
|
||||||
eventTarget.dispatchEvent(ev);
|
eventTarget.dispatchEvent(ev);
|
||||||
}).then(this.connect.bind(this)); // No HTTP error? Reconnect.
|
});
|
||||||
};
|
}.bind(this);
|
||||||
|
|
||||||
this.wsr = new WebSocketResource(this.socket, {
|
this.wsr = new WebSocketResource(this.socket, {
|
||||||
handleRequest: this.handleRequest.bind(this),
|
handleRequest: this.handleRequest.bind(this),
|
||||||
|
|
Loading…
Reference in a new issue