Skip to content

Commit

Permalink
Make event names and proxy names case insensitive.
Browse files Browse the repository at this point in the history
Fixes #508
  • Loading branch information
davidfowl committed Jul 4, 2012
1 parent 183a66b commit 5cabbcb
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 29 deletions.
28 changes: 20 additions & 8 deletions SignalR.Client.JS/jquery.signalR.hubs.js
Expand Up @@ -3,7 +3,7 @@

(function ($, window) {
"use strict";

// we use a global id for tracking callbacks so the server doesn't have to send extra info like hub name
var callbackId = 0,
callbacks = {};
Expand Down Expand Up @@ -49,6 +49,10 @@
/// <param name="eventName" type="String">The name of the hub event to register the callback for.</param>
/// <param name="callback" type="Function">The callback to be invoked.</param>
var self = this;

// Normalize the event name to lowercase
eventName = eventName.toLowerCase();

$(self).bind(eventName, function (e, data) {
callback.apply(self, data);
});
Expand All @@ -58,7 +62,7 @@
invoke: function (methodName) {
/// <summary>Invokes a server hub method with the given arguments.</summary>
/// <param name="methodName" type="String">The name of the server hub method.</param>

var self = this,
args = $.makeArray(arguments).slice(1),
userCallback = args[args.length - 1], // last argument
Expand Down Expand Up @@ -128,12 +132,12 @@

// Wire up the received handler
connection.received(function (data) {
var proxy, dataCallbackId, callback;
var proxy, dataCallbackId, callback, hubName, eventName;
if (!data) {
return;
}

if (typeof(data.Id) !== "undefined") {
if (typeof (data.Id) !== "undefined") {
// We received the return value from a server method invocation, look up callback by id and call it
dataCallbackId = data.Id.toString();
callback = callbacks[dataCallbackId];
Expand All @@ -146,11 +150,15 @@
callback.method.call(callback.scope, data);
}
} else {
// Normalize the names to lowercase
hubName = data.Hub.toLowerCase();
eventName = data.Method.toLowerCase();

// We received a client invocation request, i.e. broadcast from server hub
// Trigger the local invocation event
proxy = this.proxies[data.Hub];
proxy = this.proxies[hubName];
$.extend(proxy.state, data.State);
$(proxy).trigger(data.Method, [data.Args]);
$(proxy).trigger(eventName, [data.Args]);
}
});
};
Expand All @@ -163,16 +171,20 @@
/// <paramater name="hubName" type="String">
/// The name of the hub on the server to create the proxy for.
/// </parameter>

// Normalize the name to lowercase
hubName = hubName.toLowerCase();

var proxy = this.proxies[hubName];
if (!proxy) {
proxy = hubProxy(this, hubName);
this.proxies[hubName] = proxy;
}
return proxy;
};

hubConnection.fn.init.prototype = hubConnection.fn;

$.hubConnection = hubConnection;

}(window.jQuery, window));
} (window.jQuery, window));
Expand Up @@ -3,9 +3,9 @@

$(function () {
var hubConnection = $.hubConnection(),
hub = hubConnection.createProxy('MouseTracking');
hub = hubConnection.createProxy('mouseTracking');

hub.on('moveMouse', function (id, x, y) {
hub.on('MoveMouse', function (id, x, y) {
if (id == this.state.id) {
return;
}
Expand All @@ -27,7 +27,7 @@ $(function () {

hubConnection.start({ transport: activeTransport })
.done(function () {
return hub.invoke('Join');
return hub.invoke('join');
})
.done(function () {
$(document).mousemove(function (e) {
Expand Down
28 changes: 20 additions & 8 deletions samples/SignalR.Hosting.AspNet.Samples/Scripts/jquery.signalR.js
Expand Up @@ -1290,7 +1290,7 @@

(function ($, window) {
"use strict";

// we use a global id for tracking callbacks so the server doesn't have to send extra info like hub name
var callbackId = 0,
callbacks = {};
Expand Down Expand Up @@ -1336,6 +1336,10 @@
/// <param name="eventName" type="String">The name of the hub event to register the callback for.</param>
/// <param name="callback" type="Function">The callback to be invoked.</param>
var self = this;

// Normalize the event name to lowercase
eventName = eventName.toLowerCase();

$(self).bind(eventName, function (e, data) {
callback.apply(self, data);
});
Expand All @@ -1345,7 +1349,7 @@
invoke: function (methodName) {
/// <summary>Invokes a server hub method with the given arguments.</summary>
/// <param name="methodName" type="String">The name of the server hub method.</param>

var self = this,
args = $.makeArray(arguments).slice(1),
userCallback = args[args.length - 1], // last argument
Expand Down Expand Up @@ -1415,12 +1419,12 @@

// Wire up the received handler
connection.received(function (data) {
var proxy, dataCallbackId, callback;
var proxy, dataCallbackId, callback, hubName, eventName;
if (!data) {
return;
}

if (typeof(data.Id) !== "undefined") {
if (typeof (data.Id) !== "undefined") {
// We received the return value from a server method invocation, look up callback by id and call it
dataCallbackId = data.Id.toString();
callback = callbacks[dataCallbackId];
Expand All @@ -1433,11 +1437,15 @@
callback.method.call(callback.scope, data);
}
} else {
// Normalize the names to lowercase
hubName = data.Hub.toLowerCase();
eventName = data.Method.toLowerCase();

// We received a client invocation request, i.e. broadcast from server hub
// Trigger the local invocation event
proxy = this.proxies[data.Hub];
proxy = this.proxies[hubName];
$.extend(proxy.state, data.State);
$(proxy).trigger(data.Method, [data.Args]);
$(proxy).trigger(eventName, [data.Args]);
}
});
};
Expand All @@ -1450,16 +1458,20 @@
/// <paramater name="hubName" type="String">
/// The name of the hub on the server to create the proxy for.
/// </parameter>

// Normalize the name to lowercase
hubName = hubName.toLowerCase();

var proxy = this.proxies[hubName];
if (!proxy) {
proxy = hubProxy(this, hubName);
this.proxies[hubName] = proxy;
}
return proxy;
};

hubConnection.fn.init.prototype = hubConnection.fn;

$.hubConnection = hubConnection;

}(window.jQuery, window));
} (window.jQuery, window));

0 comments on commit 5cabbcb

Please sign in to comment.