Beispiel #1
0
        public override Task OnConnectedAsync()
        {
            try
            {
                var    userId = Convert.ToInt32(Context.GetHttpContext().Request.Query["userid"]);
                string token  = Context.GetHttpContext().Request.Query["token"];

                var user = userContext.GetProfile(userId).Result;
                if (user == null)
                {
                    user = userContext.CreateUser(token).Result;
                }

                connectionContext.AddUser(user, Context.ConnectionId);

                /*var rooms = hubContext.Groups.GetGroupsByUserId(user.UserId).Result;
                 * foreach (var item in rooms)
                 * {
                 *  Groups.AddToGroupAsync(Context.ConnectionId, item.GroupName).Wait();
                 * }*/

                OnUserChangeOnlineStatus(user.UserId, true);
            }
            catch (Exception ex)
            {
                SendError(Context.ConnectionId, ex.Message);
            }

            return(base.OnConnectedAsync());
        }