I’ve started digging in SignalR 0.4 and got stuck on a problem. I’d like to have two different Hubs on the same page which to keep things simple are:
public class ChatHub : Hub
{
public void Send(string message)
{
Clients.addMessage(message);
}
}
public class Chat2Hub : Hub
{
public void Send2(string message)
{
Clients.addMessage2(message);
}
}
This is my client code:
function initChat() {
var chat = $.connection.chat;
chat.addMessage = function (message) {...};
$('.send-cmd').click(function () {...});
return $.connection.hub.start();
}
function initChat2() {
var chat2 = $.connection.chat2;
chat2.addMessage2 = function (message) {...};
$('.send2-cmd').click(function () {...});
return $.connection.hub.start();
}
$(function() {
initChat().done(function() {
initChat2();
});
});
Simple enough, but I cannot make them work together. In this example, “chat” works correctly and “chat2” fails (without errors).
If I reverse order of initialization of course the opposite happens.
What am I missing?
Why are you starting the hub connection twice. There’s one connection for all hubs so you only need to call $.connection.hub.start() once.