Is there a way to get number of connections in Signalr hub group?

Posted by pajo on Stack Overflow See other posts from Stack Overflow or by pajo
Published on 2012-04-02T15:49:56Z Indexed on 2012/04/09 5:28 UTC
Read the original article Hit count: 295

Filed under:

Here is my problem, I want to track if user is online or offline and notify other clients about it. I'm using hubs and implemented both IConnected and IDisconnect interfaces.

My idea was to send notification to all clients when hub detects connect or disconnect. By default when user refreshes page he will get new connection id and eventually previous connection will call disconnect notifying other clients user is offline even though he's actually online.

I tired to use my own ConnectionIdFactory returning username for connection id but with multiple tabs opened at some point it will detect user connectionid disconnected and after that client side hub will try to unsuccessfully connect to the hub in endless loop wasting memory and cpu making browser almost unusable. I needed to fix it fast so I removed my factory and now I add every new connection to the group using username, so I can easily notify single user on all connections, but then I have problem of detecting if user is online or offline as I don't know how many active connection user is having.

So I'm wondering is there a way to get number of connections in one group? Or if anybody has some better idea how to track when user goes offline?

I'm using Signalr 0.4

© Stack Overflow or respective owner

Related posts about signalr