Ejemplo n.º 1
0
        public override Task OnConnectedAsync()
        {
            string userId = Context.GetHttpContext().Request.Query["userId"].ToString();

            //add the connection to the group that corresponds to the user id
            Groups.AddToGroupAsync(Context.ConnectionId, userId);
            SignalRConnectionToGroupsMap.TryAddGroup(Context.ConnectionId, userId);
            return(base.OnConnectedAsync());
        }
Ejemplo n.º 2
0
        public Task Subscribe(String id)
        {
            List <String> groups;
            var           success = SignalRConnectionToGroupsMap.TryRemoveConnection(Context.ConnectionId, out groups);

            if (groups != null)
            {
                foreach (var group in groups)
                {
                    Groups.Remove(Context.ConnectionId, group);
                }
            }

            SignalRConnectionToGroupsMap.TryAddGroup(Context.ConnectionId, id);
            return(Groups.Add(Context.ConnectionId, id));
        }
Ejemplo n.º 3
0
        public override Task OnDisconnectedAsync(Exception exception)
        {
            List <string> groups = new List <string>();

            if (SignalRConnectionToGroupsMap.TryRemoveConnection(Context.ConnectionId, out groups))
            {
                //remove connection from all the groups
                if (groups != null && groups.Count > 0)
                {
                    foreach (var groupName in groups)
                    {
                        Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName);
                    }
                }
            }
            return(base.OnDisconnectedAsync(exception));
        }