private void RemoveClientFromCache() { var userId = Context.ConnectionId; if (!string.IsNullOrWhiteSpace(userId)) { var username = UsernameConnectionIdCache.FirstOrDefault(pair => pair.Value == userId).Key; if (username != null) { Remove(username); VoteHub.ActiveCappuVote?.UserAnswerCache.Remove(username); } } Clients.All.OnOnlineUsersChanged(GetOnlineUsers()); Console.WriteLine($"User with userId {userId} removed from usernames. ConnectionId: {Context.ConnectionId}"); }
public override Task OnReconnected() { string userId = Context.Headers.Get("userId"); if (string.IsNullOrWhiteSpace(userId)) { return(base.OnReconnected()); } var username = UsernameConnectionIdCache.FirstOrDefault(pair => pair.Value == userId).Key; if (username == null) { return(base.OnReconnected()); } Add(username); Clients.Caller.OnHeaderChanged(Context.ConnectionId); return(base.OnReconnected()); }