Reputation: 79
I am wondering...
The following code declares a reference to a hub proxy.
var chat = $.connection.chatHub;
And the following code also:
var connection=$.hubConnection();
var hub=connection.createHubProxy("chatHub");
Upvotes: 1
Views: 1238
Reputation: 8276
So what is the difference between the two tpyes of declaration?
The difference is that one code is using the SignalR generated proxy, the other one doesn't.
Your generated proxy code is by default at http://yourapplicationURL/signalr/hubs. You can read the generated proxy code there.
You can read more about it here: http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-javascript-client#establishconnection
The example on the site: Using the generated proxy:
var contosoChatHubProxy = $.connection.contosoChatHub;
Witout the generated proxy:
var connection = $.hubConnection();
var contosoChatHubProxy = connection.createHubProxy('contosoChatHub');
(This code is actually contained in the generated proxy, to make a shortcut for referencing a hub)
Which one to be used and when?
You can chose not to have generated proxy code. In that case only the second option would work. In other case they are executing the same code, and the first option is more elegant. Depends on your choice.
Upvotes: 4