Stop keepalive when socket closes

// FREEBIE
pull/749/head
lilia 10 years ago
parent 04c5f83485
commit b8536679b3

@ -38481,11 +38481,6 @@ TextSecureWebSocket = function (url, opts) {
return new OutgoingWebSocketRequest(options, socket); return new OutgoingWebSocketRequest(options, socket);
}; };
this.close = function(code, reason) {
if (!code) { code = 3000; }
socket.close(code, reason);
};
socket.onmessage = function(socketMessage) { socket.onmessage = function(socketMessage) {
var blob = socketMessage.data; var blob = socketMessage.data;
var reader = new FileReader(); var reader = new FileReader();
@ -38523,14 +38518,24 @@ TextSecureWebSocket = function (url, opts) {
reader.readAsArrayBuffer(blob); reader.readAsArrayBuffer(blob);
}; };
var keepalive;
if (opts.keepalive) { if (opts.keepalive) {
var keepalive = new KeepAlive(this, { keepalive = new KeepAlive(this, {
path : opts.keepalive.path, path : opts.keepalive.path,
disconnect : opts.keepalive.disconnect disconnect : opts.keepalive.disconnect
}); });
this.resetKeepAliveTimer = keepalive.reset.bind(keepalive); this.resetKeepAliveTimer = keepalive.reset.bind(keepalive);
} }
this.close = function(code, reason) {
if (!code) { code = 3000; }
socket.close(code, reason);
if (keepalive) {
keepalive.close();
}
};
}; };
function KeepAlive(websocketResource, opts) { function KeepAlive(websocketResource, opts) {
@ -38553,6 +38558,10 @@ TextSecureWebSocket = function (url, opts) {
KeepAlive.prototype = { KeepAlive.prototype = {
constructor: KeepAlive, constructor: KeepAlive,
close: function() {
clearTimeout(this.keepAliveTimer);
clearTimeout(this.disconnectTimer);
},
reset: function() { reset: function() {
clearTimeout(this.keepAliveTimer); clearTimeout(this.keepAliveTimer);
clearTimeout(this.disconnectTimer); clearTimeout(this.disconnectTimer);
@ -39414,7 +39423,7 @@ function generateKeys(count, progressCallback) {
}); });
}, },
close: function() { close: function() {
this.socket.close(); this.wsr.close();
delete this.listeners; delete this.listeners;
}, },
onopen: function() { onopen: function() {

@ -41,7 +41,7 @@
}); });
}, },
close: function() { close: function() {
this.socket.close(); this.wsr.close();
delete this.listeners; delete this.listeners;
}, },
onopen: function() { onopen: function() {

@ -92,11 +92,6 @@
return new OutgoingWebSocketRequest(options, socket); return new OutgoingWebSocketRequest(options, socket);
}; };
this.close = function(code, reason) {
if (!code) { code = 3000; }
socket.close(code, reason);
};
socket.onmessage = function(socketMessage) { socket.onmessage = function(socketMessage) {
var blob = socketMessage.data; var blob = socketMessage.data;
var reader = new FileReader(); var reader = new FileReader();
@ -134,14 +129,24 @@
reader.readAsArrayBuffer(blob); reader.readAsArrayBuffer(blob);
}; };
var keepalive;
if (opts.keepalive) { if (opts.keepalive) {
var keepalive = new KeepAlive(this, { keepalive = new KeepAlive(this, {
path : opts.keepalive.path, path : opts.keepalive.path,
disconnect : opts.keepalive.disconnect disconnect : opts.keepalive.disconnect
}); });
this.resetKeepAliveTimer = keepalive.reset.bind(keepalive); this.resetKeepAliveTimer = keepalive.reset.bind(keepalive);
} }
this.close = function(code, reason) {
if (!code) { code = 3000; }
socket.close(code, reason);
if (keepalive) {
keepalive.close();
}
};
}; };
function KeepAlive(websocketResource, opts) { function KeepAlive(websocketResource, opts) {
@ -164,6 +169,10 @@
KeepAlive.prototype = { KeepAlive.prototype = {
constructor: KeepAlive, constructor: KeepAlive,
close: function() {
clearTimeout(this.keepAliveTimer);
clearTimeout(this.disconnectTimer);
},
reset: function() { reset: function() {
clearTimeout(this.keepAliveTimer); clearTimeout(this.keepAliveTimer);
clearTimeout(this.disconnectTimer); clearTimeout(this.disconnectTimer);

Loading…
Cancel
Save