Reputation: 65
I want to call a client side method from my SignalR hub class only once, when the client first loads up the webpage. How would I go about doing this?
Upvotes: 2
Views: 552
Reputation: 6450
In your BlahBlahHub
class, you have access to all of the connection methods that you do on the Client. Hint: Look at the base Hub
class.
With that being said, here's what the code would look like:
[HubName("messageHub")]
public class MessageHub : Hub
{
public override Task OnConnected()
{
Clients.Caller.alertUser(88);
return base.OnConnected();
}
}
var sender = $.connection.messageHub;
$.connection.hub.start().done(function () {
}).fail(function (reason) {
console.log("SignalR connection failed: " + reason);
});
sender.client.alertUser = function (test) {
alert(test);
};
Upvotes: 3