Skip to content

Commit

Permalink
Fixed issue with configured DisconnectTimeout in JS client
Browse files Browse the repository at this point in the history
- Use the correct connection reference (this) in reconnecting event event
  • Loading branch information
DamianEdwards committed Dec 6, 2012
1 parent 010c4f6 commit f3ae1e6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,21 @@
},

configureStopReconnectingTimeout = function (connection) {
var stopReconnectingTimeout = null;
var stopReconnectingTimeout,
onReconnectTimeout = function (connection) {
connection.log("Couldn't reconnect within the configured timeout (" + connection.disconnectTimeout + "ms), disconnecting.");
connection.stop(/* async */ false, /* notifyServer */ false);
};

connection.reconnecting(function () {
if (stopReconnectingTimeout === null) {
stopReconnectingTimeout = window.setTimeout(function () {
connection.log(connection.disconnectTimeout + "ms have passed without successfully reconnecting. Disconnecting.");
connection.stop(/* async */ false, /* notifyServer */ false);
stopReconnectingTimeout = null;
}, connection.disconnectTimeout);
}
stopReconnectingTimeout = window.setTimeout(function () { onReconnectTimeout(this); }, this.disconnectTimeout);
});

connection.reconnected(function () {
window.clearTimeout(stopReconnectingTimeout);
stopReconnectingTimeout = null;
connection.stateChanged(function (data) {
if (data.oldState === signalR.connectionState.reconnecting) {
// Clear the pending reconnect timeout check
window.clearTimeout(stopReconnectingTimeout);
}
});
};

Expand Down Expand Up @@ -371,9 +371,8 @@

// Once the server has labeled the PersistentConnection as Disconnected, we should stop attempting to reconnect
// after res.DisconnectTimeout seconds.
if (!isNaN(res.DisconnectTimeout)) {
connection.disconnectTimeout = res.DisconnectTimeout * 1000; // in ms
}
connection.disconnectTimeout = res.DisconnectTimeout * 1000; // in ms


// If we have a keep alive
if (res.KeepAlive) {
Expand Down
Loading

0 comments on commit f3ae1e6

Please sign in to comment.