I have a self-hosted application akin to a scenario wherein I have a method that continuously broadcasts to groups (whether somebody has "joined" or not). Something like:
var aTimer = new System.Timers.Timer(2000);
aTimer.Elapsed += (sender, e) =>
{
// broadcast to listeners whether they are listening or not
IHubConnectionContext _clients = GlobalHost.ConnectionManager.GetHubContext<ChatHub>().Clients;
_clients.Group("group1FixedName").showMessage("Some message for group 1 only");
_clients.Group("group2FixedName").showMessage("Some message for group 2 only");
// etc
};
aTimer.Start();
I had recently upgraded to version 1.1.0 from beta1. I started to observe that the "remove" method doesn't work as the "client" (web browser) is still receiving messages from the "other" group even if I initiated a "leave". Note that "leaving" the group doesn't mean closing the web browser. It's still in the same page (Single Page Application) and leaving/joining a group is triggered by a selection (combo box for example).
Code in hub:
public Task Leave(string groupName)
{
return Groups.Remove(Context.ConnectionId, groupName)
.ContinueWith(z => Clients.Caller.showCallerMessage("You are now leaving " + groupName));
}
Code in javascript client to "leave the group":
chat.server.leave("group1FixedName");
Code in javascript client to "join the group":
chat.server.join("group1FixedName");
Code in Hub for joining:
public Task Join(string groupName)
{
return Groups.Add(Context.ConnectionId, groupName)
.ContinueWith(z => Clients.Caller.showCallerMessage("You are now listening to " + groupName));
}
Is there something wrong with my implementation here?