King Friday
King Friday

Reputation: 26076

How to broadcast selectively within a Hub when using SignalR

I'm trying to solve a problem where I'll have subscribers to a single Hub but they will be coming from different cities and my page will detect the cities in which they come from. I have a single Hub that everyone will listen to and from this Hub I want to selectively broadcast messages to particular cities.

Please advise if the approach is wrong or advise how I can selectively send messages through a Hub. I may need to go to the lower PersistentConnection API approach.

Thanks in advance.


Im coming back to this question to comment on the result. What I found out that I really needed to do was to have dynamic rooms that were existing solely based off of friend relationships or group relationships and related by cities which has too many possibilities as each "group" is unique to the person's perspective. This was too hard for me to figure out using SignalR so I just coded it in JavaScript using hashes and arrays for node.js and socket.io since I'm most comfortable with JavaScript. Node.js isn't faster since its not compiled and c# already is allowing for the async stuff which node toutes as its selling point so don't take this as a knock to SignalR. Just sharing. Here is the link to it on github if you are curious: https://github.com/sebringj/zipstory-node

Upvotes: 1

Views: 2193

Answers (1)

redsquare
redsquare

Reputation: 78667

You can add users into groups and then broadcast a message to all clients in that group. Check out the source code for the JabbR chatroom project, they use addToGroup to add a user into a specific chat room, see this class file.

Also see docs here

Upvotes: 3

Related Questions