Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR - HubContext and Hub.Context

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 ?

like image 276
Tom Avatar asked Oct 03 '13 02:10

Tom


1 Answers

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.

like image 161
davidfowl Avatar answered Oct 16 '22 18:10

davidfowl