Skip to content

Commit

Permalink
Added connection data (hub subscriptions) to every request.
Browse files Browse the repository at this point in the history
- This also involved moving the starting event above the negotiation logic instead of inside, this way connection data is built before the negotiate request.

#2145
  • Loading branch information
NTaylorMullen committed Jul 21, 2013
1 parent 2e97a31 commit 1e58e5c
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,10 @@
connection.stop();
};

$(connection).triggerHandler(events.onStarting);

url = signalR.transports._logic.addQs(url, connection.qs);
url = signalR.transports._logic.addConnectionData(connection, url);

// Add the client version to the negotiate request. We utilize the same addQs method here
// so that it can append the clientVersion appropriately to the URL
Expand Down Expand Up @@ -608,8 +611,6 @@
return;
}

$(connection).triggerHandler(events.onStarting);

var transports = [],
supportedTransports = [];

Expand Down Expand Up @@ -646,7 +647,7 @@

starting: function (callback) {
/// <summary>Adds a callback that will be invoked before anything is sent over the connection</summary>
/// <param name="callback" type="Function">A callback function to execute before each time data is sent on the connection</param>
/// <param name="callback" type="Function">A callback function to execute before the connection is fully instantiated.</param>
/// <returns type="signalR" />
var connection = this;
$(connection).bind(events.onStarting, function (e, data) {
Expand Down Expand Up @@ -921,7 +922,8 @@
deferral.reject("SignalR: Error pinging server: " + errorMessage);
};

url = this.addQs(url, connection.qs);
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

$.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
Expand Down Expand Up @@ -990,10 +992,6 @@
url = baseUrl + connection.appRelativeUrl,
qs = "transport=" + transport + "&connectionToken=" + window.encodeURIComponent(connection.token);

if (connection.data) {
qs += "&connectionData=" + window.encodeURIComponent(connection.data);
}

if (connection.groupsToken) {
qs += "&groupsToken=" + window.encodeURIComponent(connection.groupsToken);
}
Expand All @@ -1014,10 +1012,21 @@
}
url += "?" + qs;
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);
url += "&tid=" + Math.floor(Math.random() * 11);
return url;
},

addConnectionData: function (connection, currentUrl) {
var appender = currentUrl.indexOf("?") !== -1 ? "&" : "?";

if (connection.data) {
currentUrl += appender + "connectionData=" + window.encodeURIComponent(connection.data);
}

return currentUrl;
},

maximizePersistentResponse: function (minPersistentResponse) {
return {
MessageId: minPersistentResponse.C,
Expand Down Expand Up @@ -1050,8 +1059,9 @@
$(connection).triggerHandler(events.onError, [error, data]);
};

url = this.addQs(url, connection.qs);

url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

return $.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
xhrFields: { withCredentials: connection.withCredentials },
Expand Down Expand Up @@ -1101,7 +1111,9 @@
async = typeof async === "undefined" ? true : async;

var url = connection.url + "/abort" + "?transport=" + connection.transport.name + "&connectionToken=" + window.encodeURIComponent(connection.token);
url = this.addQs(url, connection.qs);
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

$.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
xhrFields: { withCredentials: connection.withCredentials },
Expand Down
34 changes: 23 additions & 11 deletions samples/Microsoft.AspNet.SignalR.Samples/Scripts/jquery.signalR.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,10 @@
connection.stop();
};

$(connection).triggerHandler(events.onStarting);

url = signalR.transports._logic.addQs(url, connection.qs);
url = signalR.transports._logic.addConnectionData(connection, url);

// Add the client version to the negotiate request. We utilize the same addQs method here
// so that it can append the clientVersion appropriately to the URL
Expand Down Expand Up @@ -608,8 +611,6 @@
return;
}

$(connection).triggerHandler(events.onStarting);

var transports = [],
supportedTransports = [];

Expand Down Expand Up @@ -646,7 +647,7 @@

starting: function (callback) {
/// <summary>Adds a callback that will be invoked before anything is sent over the connection</summary>
/// <param name="callback" type="Function">A callback function to execute before each time data is sent on the connection</param>
/// <param name="callback" type="Function">A callback function to execute before the connection is fully instantiated.</param>
/// <returns type="signalR" />
var connection = this;
$(connection).bind(events.onStarting, function (e, data) {
Expand Down Expand Up @@ -921,7 +922,8 @@
deferral.reject("SignalR: Error pinging server: " + errorMessage);
};

url = this.addQs(url, connection.qs);
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

$.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
Expand Down Expand Up @@ -990,10 +992,6 @@
url = baseUrl + connection.appRelativeUrl,
qs = "transport=" + transport + "&connectionToken=" + window.encodeURIComponent(connection.token);

if (connection.data) {
qs += "&connectionData=" + window.encodeURIComponent(connection.data);
}

if (connection.groupsToken) {
qs += "&groupsToken=" + window.encodeURIComponent(connection.groupsToken);
}
Expand All @@ -1014,10 +1012,21 @@
}
url += "?" + qs;
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);
url += "&tid=" + Math.floor(Math.random() * 11);
return url;
},

addConnectionData: function (connection, currentUrl) {
var appender = currentUrl.indexOf("?") !== -1 ? "&" : "?";

if (connection.data) {
currentUrl += appender + "connectionData=" + window.encodeURIComponent(connection.data);
}

return currentUrl;
},

maximizePersistentResponse: function (minPersistentResponse) {
return {
MessageId: minPersistentResponse.C,
Expand Down Expand Up @@ -1050,8 +1059,9 @@
$(connection).triggerHandler(events.onError, [error, data]);
};

url = this.addQs(url, connection.qs);

url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

return $.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
xhrFields: { withCredentials: connection.withCredentials },
Expand Down Expand Up @@ -1101,7 +1111,9 @@
async = typeof async === "undefined" ? true : async;

var url = connection.url + "/abort" + "?transport=" + connection.transport.name + "&connectionToken=" + window.encodeURIComponent(connection.token);
url = this.addQs(url, connection.qs);
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

$.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
xhrFields: { withCredentials: connection.withCredentials },
Expand Down

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/Microsoft.AspNet.SignalR.Client.JS/jquery.signalR.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,10 @@
connection.stop();
};

$(connection).triggerHandler(events.onStarting);

url = signalR.transports._logic.addQs(url, connection.qs);
url = signalR.transports._logic.addConnectionData(connection, url);

// Add the client version to the negotiate request. We utilize the same addQs method here
// so that it can append the clientVersion appropriately to the URL
Expand Down Expand Up @@ -607,8 +610,6 @@
return;
}

$(connection).triggerHandler(events.onStarting);

var transports = [],
supportedTransports = [];

Expand Down Expand Up @@ -645,7 +646,7 @@

starting: function (callback) {
/// <summary>Adds a callback that will be invoked before anything is sent over the connection</summary>
/// <param name="callback" type="Function">A callback function to execute before each time data is sent on the connection</param>
/// <param name="callback" type="Function">A callback function to execute before the connection is fully instantiated.</param>
/// <returns type="signalR" />
var connection = this;
$(connection).bind(events.onStarting, function (e, data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
deferral.reject("SignalR: Error pinging server: " + errorMessage);
};

url = this.addQs(url, connection.qs);
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

$.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
Expand Down Expand Up @@ -141,10 +142,6 @@
url = baseUrl + connection.appRelativeUrl,
qs = "transport=" + transport + "&connectionToken=" + window.encodeURIComponent(connection.token);

if (connection.data) {
qs += "&connectionData=" + window.encodeURIComponent(connection.data);
}

if (connection.groupsToken) {
qs += "&groupsToken=" + window.encodeURIComponent(connection.groupsToken);
}
Expand All @@ -165,10 +162,21 @@
}
url += "?" + qs;
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);
url += "&tid=" + Math.floor(Math.random() * 11);
return url;
},

addConnectionData: function (connection, currentUrl) {
var appender = currentUrl.indexOf("?") !== -1 ? "&" : "?";

if (connection.data) {
currentUrl += appender + "connectionData=" + window.encodeURIComponent(connection.data);
}

return currentUrl;
},

maximizePersistentResponse: function (minPersistentResponse) {
return {
MessageId: minPersistentResponse.C,
Expand Down Expand Up @@ -201,8 +209,9 @@
$(connection).triggerHandler(events.onError, [error, data]);
};

url = this.addQs(url, connection.qs);

url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

return $.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
xhrFields: { withCredentials: connection.withCredentials },
Expand Down Expand Up @@ -252,7 +261,9 @@
async = typeof async === "undefined" ? true : async;

var url = connection.url + "/abort" + "?transport=" + connection.transport.name + "&connectionToken=" + window.encodeURIComponent(connection.token);
url = this.addQs(url, connection.qs);
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

$.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
xhrFields: { withCredentials: connection.withCredentials },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,10 @@
connection.stop();
};

$(connection).triggerHandler(events.onStarting);

url = signalR.transports._logic.addQs(url, connection.qs);
url = signalR.transports._logic.addConnectionData(connection, url);

// Add the client version to the negotiate request. We utilize the same addQs method here
// so that it can append the clientVersion appropriately to the URL
Expand Down Expand Up @@ -608,8 +611,6 @@
return;
}

$(connection).triggerHandler(events.onStarting);

var transports = [],
supportedTransports = [];

Expand Down Expand Up @@ -646,7 +647,7 @@

starting: function (callback) {
/// <summary>Adds a callback that will be invoked before anything is sent over the connection</summary>
/// <param name="callback" type="Function">A callback function to execute before each time data is sent on the connection</param>
/// <param name="callback" type="Function">A callback function to execute before the connection is fully instantiated.</param>
/// <returns type="signalR" />
var connection = this;
$(connection).bind(events.onStarting, function (e, data) {
Expand Down Expand Up @@ -921,7 +922,8 @@
deferral.reject("SignalR: Error pinging server: " + errorMessage);
};

url = this.addQs(url, connection.qs);
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

$.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
Expand Down Expand Up @@ -990,10 +992,6 @@
url = baseUrl + connection.appRelativeUrl,
qs = "transport=" + transport + "&connectionToken=" + window.encodeURIComponent(connection.token);

if (connection.data) {
qs += "&connectionData=" + window.encodeURIComponent(connection.data);
}

if (connection.groupsToken) {
qs += "&groupsToken=" + window.encodeURIComponent(connection.groupsToken);
}
Expand All @@ -1014,10 +1012,21 @@
}
url += "?" + qs;
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);
url += "&tid=" + Math.floor(Math.random() * 11);
return url;
},

addConnectionData: function (connection, currentUrl) {
var appender = currentUrl.indexOf("?") !== -1 ? "&" : "?";

if (connection.data) {
currentUrl += appender + "connectionData=" + window.encodeURIComponent(connection.data);
}

return currentUrl;
},

maximizePersistentResponse: function (minPersistentResponse) {
return {
MessageId: minPersistentResponse.C,
Expand Down Expand Up @@ -1050,8 +1059,9 @@
$(connection).triggerHandler(events.onError, [error, data]);
};

url = this.addQs(url, connection.qs);

url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

return $.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
xhrFields: { withCredentials: connection.withCredentials },
Expand Down Expand Up @@ -1101,7 +1111,9 @@
async = typeof async === "undefined" ? true : async;

var url = connection.url + "/abort" + "?transport=" + connection.transport.name + "&connectionToken=" + window.encodeURIComponent(connection.token);
url = this.addQs(url, connection.qs);
url = transportLogic.addQs(url, connection.qs);
url = transportLogic.addConnectionData(connection, url);

$.ajax(
$.extend({}, $.signalR.ajaxDefaults, {
xhrFields: { withCredentials: connection.withCredentials },
Expand Down

0 comments on commit 1e58e5c

Please sign in to comment.