Signal R with .NET

public class NotificationSend : Hub
{
private static IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<NotificationSend>();

public override Task OnConnected()
{
string name = Context.User.Identity.Name;
Groups.Add(Context.ConnectionId, name);

return base.OnConnected();
}

public void SendToUser(string messageText,string userName)
{
hubContext.Clients.Group(userName).Notification(messageText);
}

public void StopLoader(string messageText, string userName)
{
hubContext.Clients.Group(userName).Stoploader(messageText);
}
}

$(function () {
var notification = $.connection.notificationSend;
console.log(notification);
notification.client.Notification = function (Count) {
$(‘#liveupdate’).empty();
$(‘#liveupdate’).show();
$(‘#liveupdate’).append(Count);
};
notification.client.Stoploader = function (Count) {
$(“#message”).hide();
$(‘#messagepath’).hide();
$(‘#messagetype’).hide();
$(‘#error1’).hide();
$(‘#error2’).hide();
$(‘#error3’).hide();
$(‘#messageDiv’).empty();
$(‘#messageDiv’).show();
$(‘#messageDiv’).append(Count);
};
$.connection.hub.start().done(function () {
var connectionId = $.connection.hub.id;
console.log(“Connected Successfully”);
}).fail(function (response) {
console.log(“not connected” + response);
});
});

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s