Let keepalive listen to socket events
Wait until the socket connects before starting the keepalive timer. Automatically stop the keepalive when the socket is closed. // FREEBIE
This commit is contained in:
@@ -38456,22 +38456,19 @@ axolotlInternal.RecipientRecord = function() {
|
||||
reader.readAsArrayBuffer(blob);
|
||||
};
|
||||
|
||||
var keepalive;
|
||||
if (opts.keepalive) {
|
||||
keepalive = new KeepAlive(this, {
|
||||
var keepalive = new KeepAlive(this, {
|
||||
path : opts.keepalive.path,
|
||||
disconnect : opts.keepalive.disconnect
|
||||
});
|
||||
|
||||
this.resetKeepAliveTimer = keepalive.reset.bind(keepalive);
|
||||
socket.addEventListener('connect', this.resetKeepAliveTimer);
|
||||
socket.addEventListener('close', keepalive.stop.bind(keepalive));
|
||||
}
|
||||
|
||||
this.close = function(code, reason) {
|
||||
if (!code) { code = 3000; }
|
||||
socket.close(code, reason);
|
||||
if (keepalive) {
|
||||
keepalive.close();
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
@@ -38488,7 +38485,6 @@ axolotlInternal.RecipientRecord = function() {
|
||||
this.disconnect = true;
|
||||
}
|
||||
this.wsr = websocketResource;
|
||||
this.reset();
|
||||
} else {
|
||||
throw new TypeError('KeepAlive expected a WebSocketResource');
|
||||
}
|
||||
@@ -38496,7 +38492,7 @@ axolotlInternal.RecipientRecord = function() {
|
||||
|
||||
KeepAlive.prototype = {
|
||||
constructor: KeepAlive,
|
||||
close: function() {
|
||||
stop: function() {
|
||||
clearTimeout(this.keepAliveTimer);
|
||||
clearTimeout(this.disconnectTimer);
|
||||
},
|
||||
|
Reference in New Issue
Block a user