Stop keepalive when socket closes
// FREEBIE
This commit is contained in:
@@ -92,11 +92,6 @@
|
||||
return new OutgoingWebSocketRequest(options, socket);
|
||||
};
|
||||
|
||||
this.close = function(code, reason) {
|
||||
if (!code) { code = 3000; }
|
||||
socket.close(code, reason);
|
||||
};
|
||||
|
||||
socket.onmessage = function(socketMessage) {
|
||||
var blob = socketMessage.data;
|
||||
var reader = new FileReader();
|
||||
@@ -134,14 +129,24 @@
|
||||
reader.readAsArrayBuffer(blob);
|
||||
};
|
||||
|
||||
var keepalive;
|
||||
if (opts.keepalive) {
|
||||
var keepalive = new KeepAlive(this, {
|
||||
keepalive = new KeepAlive(this, {
|
||||
path : opts.keepalive.path,
|
||||
disconnect : opts.keepalive.disconnect
|
||||
});
|
||||
|
||||
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) {
|
||||
@@ -164,6 +169,10 @@
|
||||
|
||||
KeepAlive.prototype = {
|
||||
constructor: KeepAlive,
|
||||
close: function() {
|
||||
clearTimeout(this.keepAliveTimer);
|
||||
clearTimeout(this.disconnectTimer);
|
||||
},
|
||||
reset: function() {
|
||||
clearTimeout(this.keepAliveTimer);
|
||||
clearTimeout(this.disconnectTimer);
|
||||
|
Reference in New Issue
Block a user