I am new to signalR and reading the API and playing around with it. a bit confused about the Hub and its Context.
That is, Hub.Context
is not HubContext
.
HubContext
I can get from GlobalHost.ConnectionManager.GetHubContext<THub>()
and Hub.Context
gives me a HubCallerContext
which I am not sure how to use.
What are their relationship? How can I get HubContext from Hub
or Hub from HubContext
?
A result of poor naming. Hub.Context
is the HTTP context from the caller (more like a request context). The HubContext
has the GroupManager
and Clients
which map to Hub.Groups
and Hub.Clients
.
You can add to groups and talk to the client from outside the hub. Inside the hub you can get the connection ID of the caller and get the HTTP request context associated with the hub invocation. Outside of the hub, you can't do Context.Clients.Caller
or Context.Clients.Others
because there's no caller when you're outside of the hub.
Hope that clears things up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With