Broadcasting to all clients in a group except the caller
Similar to what we just did in order to exclude specific connections from the set of all the connected clients, we can provide exceptions in the context of a specific group. We can broadcast to all the connections in a given group, excluding a list of specific ConnectionId
values that we want to omit.
Getting ready
Before writing the code of this recipe, we create a new empty web application, which we'll call Recipe12
.
How to do it…
Let's prepare our project by performing the following steps:
We add a Hub called
EchoHub
.Let's then add the usual OWIN Startup class named
Startup
, with aConfiguration()
method callingapp.MapSignalR()
.Let's edit Hub's content using the following code:
using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Hubs; namespace Recipe12 { [HubName("echo")] public class EchoHub : Hub { public void Subscribe(string groupName) { Groups.Add(Context.ConnectionId, groupName...