Clear and reset all relevant timers on packet

Not clear to me that receiving a pong would actually clear the old
heartbeat timer.
This commit is contained in:
Graham Hughes
2015-06-10 12:37:04 -07:00
parent e959647864
commit cca5edd40e

View File

@@ -79,24 +79,30 @@ _.extend(DDPCommon.Heartbeat.prototype, {
self._onTimeout();
},
pingReceived: function () {
// Restart all timers, as we got a message from the counterparty.
_restartTimers: function () {
var self = this;
// We know the connection is alive if we receive a ping, so we
// don't need to send a ping ourselves. Reset the interval timer.
if (self._heartbeatTimeoutHandle) {
self._clearHeartbeatTimeoutTimer();
}
if (self._heartbeatIntervalHandle) {
self._clearHeartbeatIntervalTimer();
self._startHeartbeatIntervalTimer();
}
},
pingReceived: function () {
var self = this;
// We know the connection is alive if we receive a ping, so we
// don't need to send a ping ourselves. Reset the interval timer.
self._restartTimers();
},
pongReceived: function () {
var self = this;
// Receiving a pong means we won't timeout, so clear the timeout
// timer and start the interval again.
if (self._heartbeatTimeoutHandle) {
self._clearHeartbeatTimeoutTimer();
self._startHeartbeatIntervalTimer();
}
self._restartTimers();
}
});