So I am using SignalR groups to handle my chat site and I want to make sure that there are only 2 users per room. So far I haven't found any information about limiting connections to SignalR group, neither have I found any information abut counting current connections. One of my ideas is to Add room Id to a database whenever someone joinsit (which means that it has one user), then when 2nd person connects I could restrict access to this certain room with simple if statement. And so when 1 of these user would leave the group would be available to join again.
Asked
Active
Viewed 761 times
1
-
Unless you already have a db, adding one just to store a roomID and count would be overkill. – Mathemats Mar 04 '16 at 03:06
-
I think you need to maintain the details of room and when someone joins or leaves in a database, it would not be signlaR part. So everytime you checck the DB entries and then proceed further – Rajshekar Reddy Mar 04 '16 at 03:07
-
@Mathemats I can guess if he is building a chat app, then he must save the chat history, creating new rooms, deleting rooms, adding users to system, And temp table to hold messages which were not transmitted successfully and whole lot stuff, So definitely he must have a db – Rajshekar Reddy Mar 04 '16 at 03:09
-
@Reddy Holy assumptions batman! – Mathemats Mar 04 '16 at 03:10
-
lol, I spilled my coffee. – Rajshekar Reddy Mar 04 '16 at 03:13
-
1Sorry to dissapoint You guys but right now im not thinking about having chat history etc. I just want something to limit group connections to 2 and using db was one of the ideas. Also I want this app to be on my portfolio rather than some huge product so showing that I know how to handle db would definately be a +. But still, I dont know how to count connections. – JanRad Mar 04 '16 at 03:27
-
Possible duplicate of [Iterate through groups in signalR hub class](http://stackoverflow.com/questions/11870698/iterate-through-groups-in-signalr-hub-class). Not quite the same end goal, but the same solution applies. See also http://stackoverflow.com/questions/13514259/get-number-of-listeners-clients-connected-to-signalr-hub – brichins Jan 09 '17 at 20:07