Skip to content

Commit

Permalink
Made some modifications to js client for SSE and longpolling transports.
Browse files Browse the repository at this point in the history
- Always attempt reconnecting to server when SSE connections closes. This
  behavior was inconsistent across FF and Chrome.
- Don't raise errors on the longpolling transport if we're reconnecting.
  • Loading branch information
davidfowl committed Jun 16, 2012
1 parent c7b1d74 commit 5d782dc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 60 deletions.
32 changes: 13 additions & 19 deletions SignalR/Scripts/jquery.signalR.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 70,7 @@
changeState = function (connection, state) {
if (state !== connection.state) {
// REVIEW: Should event fire before or after the state change actually occurs?
$(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state }]);
$(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state}]);
connection.state = state;
}
},
Expand Down Expand Up @@ -798,26 798,18 @@
connection.log("EventSource readyState: " connection.eventSource.readyState);

if (e.eventPhase === window.EventSource.CLOSED) {
// connection closed
if (connection.eventSource.readyState === window.EventSource.CONNECTING) {
// We don't use the EventSource's native reconnect function as it
// doesn't allow us to change the URL when reconnecting. We need
// to change the URL to not include the /connect suffix, and pass
// the last message id we received.
connection.log("EventSource reconnecting due to the server connection ending");
// We don't use the EventSource's native reconnect function as it
// doesn't allow us to change the URL when reconnecting. We need
// to change the URL to not include the /connect suffix, and pass
// the last message id we received.
connection.log("EventSource reconnecting due to the server connection ending");

changeState(connection, signalR.connectionState.reconnecting);
changeState(connection, signalR.connectionState.reconnecting);

if (isDisconnecting(connection) === false) {
that.reconnect(connection);
}
}
else {
// The EventSource has closed, either because its close() method was called,
// or the server sent down a "don't reconnect" frame.
connection.log("EventSource closed");
that.stop(connection);
if (isDisconnecting(connection) === false) {
that.reconnect(connection);
}

} else {
// connection error
connection.log("EventSource error");
Expand Down Expand Up @@ -1075,7 1067,9 @@
clearTimeout(reconnectTimeOut);
}

$(instance).trigger(events.onError, [data.responseText]);
if (reconnecting === false) {
$(instance).trigger(events.onError, [data.responseText]);
}

window.setTimeout(function () {
if (isDisconnecting(instance) === false) {
Expand Down
2 changes: 1 addition & 1 deletion SignalR/Scripts/jquery.signalR.min.js

Large diffs are not rendered by default.

32 changes: 13 additions & 19 deletions samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 70,7 @@
changeState = function (connection, state) {
if (state !== connection.state) {
// REVIEW: Should event fire before or after the state change actually occurs?
$(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state }]);
$(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state}]);
connection.state = state;
}
},
Expand Down Expand Up @@ -798,26 798,18 @@
connection.log("EventSource readyState: " connection.eventSource.readyState);

if (e.eventPhase === window.EventSource.CLOSED) {
// connection closed
if (connection.eventSource.readyState === window.EventSource.CONNECTING) {
// We don't use the EventSource's native reconnect function as it
// doesn't allow us to change the URL when reconnecting. We need
// to change the URL to not include the /connect suffix, and pass
// the last message id we received.
connection.log("EventSource reconnecting due to the server connection ending");
// We don't use the EventSource's native reconnect function as it
// doesn't allow us to change the URL when reconnecting. We need
// to change the URL to not include the /connect suffix, and pass
// the last message id we received.
connection.log("EventSource reconnecting due to the server connection ending");

changeState(connection, signalR.connectionState.reconnecting);
changeState(connection, signalR.connectionState.reconnecting);

if (isDisconnecting(connection) === false) {
that.reconnect(connection);
}
}
else {
// The EventSource has closed, either because its close() method was called,
// or the server sent down a "don't reconnect" frame.
connection.log("EventSource closed");
that.stop(connection);
if (isDisconnecting(connection) === false) {
that.reconnect(connection);
}

} else {
// connection error
connection.log("EventSource error");
Expand Down Expand Up @@ -1075,7 1067,9 @@
clearTimeout(reconnectTimeOut);
}

$(instance).trigger(events.onError, [data.responseText]);
if (reconnecting === false) {
$(instance).trigger(events.onError, [data.responseText]);
}

window.setTimeout(function () {
if (isDisconnecting(instance) === false) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 70,7 @@
changeState = function (connection, state) {
if (state !== connection.state) {
// REVIEW: Should event fire before or after the state change actually occurs?
$(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state }]);
$(connection).trigger(events.onStateChanged, [{ oldState: connection.state, newState: state}]);
connection.state = state;
}
},
Expand Down Expand Up @@ -798,26 798,18 @@
connection.log("EventSource readyState: " connection.eventSource.readyState);

if (e.eventPhase === window.EventSource.CLOSED) {
// connection closed
if (connection.eventSource.readyState === window.EventSource.CONNECTING) {
// We don't use the EventSource's native reconnect function as it
// doesn't allow us to change the URL when reconnecting. We need
// to change the URL to not include the /connect suffix, and pass
// the last message id we received.
connection.log("EventSource reconnecting due to the server connection ending");
// We don't use the EventSource's native reconnect function as it
// doesn't allow us to change the URL when reconnecting. We need
// to change the URL to not include the /connect suffix, and pass
// the last message id we received.
connection.log("EventSource reconnecting due to the server connection ending");

changeState(connection, signalR.connectionState.reconnecting);
changeState(connection, signalR.connectionState.reconnecting);

if (isDisconnecting(connection) === false) {
that.reconnect(connection);
}
}
else {
// The EventSource has closed, either because its close() method was called,
// or the server sent down a "don't reconnect" frame.
connection.log("EventSource closed");
that.stop(connection);
if (isDisconnecting(connection) === false) {
that.reconnect(connection);
}

} else {
// connection error
connection.log("EventSource error");
Expand Down Expand Up @@ -1075,7 1067,9 @@
clearTimeout(reconnectTimeOut);
}

$(instance).trigger(events.onError, [data.responseText]);
if (reconnecting === false) {
$(instance).trigger(events.onError, [data.responseText]);
}

window.setTimeout(function () {
if (isDisconnecting(instance) === false) {
Expand Down
Loading

0 comments on commit 5d782dc

Please sign in to comment.