I'm trying to set up some SignalR Hubs and some separate OnDisconnected events for them.
For the sake of the question, on some page I have two Hubs:
StatusHub: Handles the status of the user on the website. This hub's methods are called on every page of the website and hadle the logic of the user connection and disconnection to update the user status as he navigates through the WebSite.
ChatHub: Handles everything related to the website real time chat. This hub's methods are only called from a specific page of the website, when the user click on specific buttons.
The problem I'm experiencing is that even though both of the hub classes implement their own version of the OnConnected and OnDisconnected methods, only the StatusHub methods are fired, the ChatHub methods aren't being called.
I don't know if that is by design, or if I'm doing something wrong. So far I've read some articles and answers that states that the connection to the hub server is a single connection and that I don't connect to a specific hub, I connect to the Hub server as a whole so only one of the methods will ever be recognized and called.
Can anyone with more experience with SignalR tell me if there is a way to separate the connection and disconnection events of the two hubs or if that's really meant to be this way?
I'll put just a few some pieces of code below to better illustrate the scenario but if you need to see more code, just ask and I'll add it.
StatusHub.cs
public class StatusHub : Hub {
public override Task OnDisconnected()
{
//handles the disconnected event as needed
return base.OnDisconnected();
}
public override Task OnConnected()
{
//handles the connected event as needed
return base.OnConnected();
}
}
ChatHub.cs
public class ChatHub : Hub {
public override Task OnDisconnected()
{
//should handle the chat disconnected event but is never reached
return base.OnDisconnected();
}
public override Task OnConnected()
{
//should handle the chat connected event but is never reached
return base.OnConnected();
}
}
Code that starts the hub server connection (executed on every page):
$.connection.hub.start().done(function() {
//a lot of code here (irrelevant to the question I think)
});