I was able to get your code logic to work. Here's what I built off your logic:
SERVER:
public class Status : Hub
{
public override Task OnConnected()
{
Groups.Add(Context.ConnectionId, "foo");
return base.OnConnected();
}
public void foo()
{
var context = GlobalHost.ConnectionManager.GetHubContext<Status>();
var subscribers = context.Clients;
var subscriber = subscribers.Group("foo");
subscriber.messageReceived("ello");
}
}
CLIENT:
var status = $.connection.status;
status.client.messageReceived = function (val) {
alert(val);
}
$.connection.hub.start().done(function() {
status.server.foo();
});
My only thoughts onto why your implementation is not working is:
- You are not adding the connection ID to the group that you're trying to broadcast to (see my OnConnected function on the server).
- In your .client method for messageReceived you are not allowing for a value to be passed as a paramter. Unless you're parsing the arguments object within the function you will not be able to get the message value.
- Your message.Source is incorrect
Hope this helps!