VisualBean
2/22/2017 - 7:23 PM

ToastHub.cs

using Microsoft.AspNet.SignalR;
using System.Threading.Tasks;

namespace MyAwesomeProject.Web.Hubs
{
    public class ToastHub : Hub
    {
        public override Task OnConnected()
        {
           //Adds connecting user to it's very own group. 
           this.Groups.Add(this.Context.ConnectionId, Context.Request.User.Identity.Name);
           return (base.OnConnected());
        }

        public override Task OnDisconnected(bool stopCalled)
        {
           //removes current user from it's group.
           this.Groups.Remove(this.Context.ConnectionId, Context.Request.User.Identity.Name);
           return (base.OnDisconnected(stopCalled));
        }
    }
}