/// <summary> /// Hub overriden methood while connecting /// </summary> /// <returns></returns> public override System.Threading.Tasks.Task OnConnected() { if (Context.User.Identity.IsAuthenticated) { ///check if already connected with the same ConnectionID then ignore database update if (!MyConnectionID.Equals(Context.ConnectionId)) { try { CurrentUser.StatusID = 1; _hub.UpdateUserStatus(CurrentUser.UserID, Context.ConnectionId, Enums.BroadCastType.Web, Enums.UserStatus.ONL); IList <string> connectionIDs = new BusinessLogic.UserAccess() .GetFollowerListByConnectID(CurrentUser.UserID, Enums.PageType.Profile, Enums.FriendshipStatus.FA) .Where(x => x.ConnectedBy == (byte)Enums.BroadCastType.Web).Select(x => x.ConnectionID).ToList(); Clients.Clients(connectionIDs).updateUserList(GetMyChatInfo(1)); MyConnectionID = Context.ConnectionId; } catch (Exception ex) { Logs.Error("Error updating user status", ex); } } } return(base.OnConnected()); }
/// <summary> /// Hub overriden methood while disconnecting /// </summary> /// <returns></returns> public System.Threading.Tasks.Task OnDisconnected() { try { CurrentUser.StatusID = 2; _hub.UpdateUserStatus(CurrentUser.UserID, Context.ConnectionId, Enums.BroadCastType.Web, Enums.UserStatus.OFL); IList <string> connectionIDs = new BusinessLogic.UserAccess() .GetFollowerListByConnectID(CurrentUser.UserID, Enums.PageType.Profile, Enums.FriendshipStatus.FA) .Where(x => x.ConnectedBy == (byte)Enums.BroadCastType.Web).Select(x => x.ConnectionID).ToList(); Clients.Clients(connectionIDs).updateUserList(GetMyChatInfo(1)); } catch (Exception ex) { Logs.Error("Error updating user status", ex); } return(base.OnDisconnected(false)); }