Skip to content

Commit

Permalink
Made JS hubConnection API consistent with .NET but in JS style.
Browse files Browse the repository at this point in the history
Updated MouseTracking sample to use new hubConnection API.
  • Loading branch information
DamianEdwards committed Aug 22, 2012
1 parent 7089b32 commit 93c2dd2
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 30 deletions.
32 changes: 24 additions & 8 deletions SignalR.Client.JS/jquery.signalR.hubs.js
Expand Up @@ -104,22 +104,38 @@




// hubConnection // hubConnection
function hubConnection(url) { function hubConnection(url, options) {
/// <summary>Creates a new hub connection.</summary> /// <summary>Creates a new hub connection.</summary>
/// <param name="url" type="String">[Optional] The hub route url, defaults to "/signalr"</param> /// <param name="url" type="String">[Optional] The hub route url, defaults to "/signalr".</param>
if (!url) { /// <param name="options" type="Object">[Optional] Settings to use when creating the hubConnection.</param>
url = "/signalr"; var settings = {
qs: null,
logging: false,
useDefaultPath : true
};

$.extend(settings, options);

if (!url || settings.useDefaultPath) {
url = (url || "") + "/signalr";
} }
return new hubConnection.fn.init(url); return new hubConnection.fn.init(url, settings);
} }


hubConnection.fn = hubConnection.prototype = $.connection(); hubConnection.fn = hubConnection.prototype = $.connection();


hubConnection.fn.init = function (url, qs, logging) { hubConnection.fn.init = function (url, options) {
var connection = this; var settings = {
qs: null,
logging: false,
useDefaultPath: true
},
connection = this;

$.extend(settings, options);


// Call the base constructor // Call the base constructor
$.signalR.fn.init.call(connection, url, qs, logging); $.signalR.fn.init.call(connection, url, settings.qs, settings.logging);


// Object to store hub proxies for this connection // Object to store hub proxies for this connection
connection.proxies = {}; connection.proxies = {};
Expand Down
Expand Up @@ -2,7 +2,7 @@
/// <reference path="../../Scripts/jquery.signalR.js" /> /// <reference path="../../Scripts/jquery.signalR.js" />


$(function () { $(function () {
var hubConnection = $.hubConnection(), var hubConnection = $.hubConnection('/signalr', { qs : 'test=1', logging: false, useDefaultPath: false }),
hub = hubConnection.createProxy('mouseTracking'); hub = hubConnection.createProxy('mouseTracking');


hub.on('MoveMouse', function (id, x, y) { hub.on('MoveMouse', function (id, x, y) {
Expand Down
32 changes: 24 additions & 8 deletions samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.js
Expand Up @@ -1407,22 +1407,38 @@




// hubConnection // hubConnection
function hubConnection(url) { function hubConnection(url, options) {
/// <summary>Creates a new hub connection.</summary> /// <summary>Creates a new hub connection.</summary>
/// <param name="url" type="String">[Optional] The hub route url, defaults to "/signalr"</param> /// <param name="url" type="String">[Optional] The hub route url, defaults to "/signalr".</param>
if (!url) { /// <param name="options" type="Object">[Optional] Settings to use when creating the hubConnection.</param>
url = "/signalr"; var settings = {
qs: null,
logging: false,
useDefaultPath : true
};

$.extend(settings, options);

if (!url || settings.useDefaultPath) {
url = (url || "") + "/signalr";
} }
return new hubConnection.fn.init(url); return new hubConnection.fn.init(url, settings);
} }


hubConnection.fn = hubConnection.prototype = $.connection(); hubConnection.fn = hubConnection.prototype = $.connection();


hubConnection.fn.init = function (url, qs, logging) { hubConnection.fn.init = function (url, options) {
var connection = this; var settings = {
qs: null,
logging: false,
useDefaultPath: true
},
connection = this;

$.extend(settings, options);


// Call the base constructor // Call the base constructor
$.signalR.fn.init.call(connection, url, qs, logging); $.signalR.fn.init.call(connection, url, settings.qs, settings.logging);


// Object to store hub proxies for this connection // Object to store hub proxies for this connection
connection.proxies = {}; connection.proxies = {};
Expand Down

0 comments on commit 93c2dd2

Please sign in to comment.