Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

signalr

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 tried 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

like image 617
pajo Avatar asked Apr 02 '12 15:04

pajo


1 Answers

There's not way to do this other than counting on your own.

like image 58
davidfowl Avatar answered Oct 06 '22 00:10

davidfowl