public override Task OnConnectedAsync() { lock (ParticipantsConnectionLock) { var connectionIndex = DisconnectedParticipants.FindIndex(x => x.Participant.Id == Context.ConnectionId); if (connectionIndex >= 0) { var participant = DisconnectedParticipants.ElementAt(connectionIndex); DisconnectedParticipants.Remove(participant); AllConnectedParticipants.Add(participant); Clients.All.SendAsync("friendsListChanged", AllConnectedParticipants); } return(base.OnConnectedAsync()); } }
public override Task OnConnectedAsync() { // string name = _currentUser.UserName; // // _connections.Add(name, Context.ConnectionId); lock (ParticipantsConnectionLock) { var connectionIndex = DisconnectedParticipants.FindIndex(x => x.Participant.Id == Context.ConnectionId); if (connectionIndex >= 0) { var participant = DisconnectedParticipants.ElementAt(connectionIndex); RemoveDisconnect(participant.Participant.Id); AddConnect(participant); Clients.All.SendAsync("friendsListChanged", AllConnectedParticipants); } return(base.OnConnectedAsync()); } }
public override Task OnDisconnectedAsync(Exception exception) { lock (ParticipantsConnectionLock) { var connectionIndex = AllConnectedParticipants.FindIndex(x => x.Participant.Id == Context.ConnectionId); if (connectionIndex >= 0) { var participant = AllConnectedParticipants.ElementAt(connectionIndex); var groupsParticipantIsIn = AllGroupParticipants.Where(x => x.ChattingTo.Any(u => u.Id == participant.Participant.Id)); AllConnectedParticipants.RemoveAll(x => groupsParticipantIsIn.Any(g => g.Id == x.Participant.Id)); AllGroupParticipants.RemoveAll(x => groupsParticipantIsIn.Any(g => g.Id == x.Id)); AllConnectedParticipants.Remove(participant); DisconnectedParticipants.Add(participant); Clients.All.SendAsync("friendsListChanged", AllConnectedParticipants); } return(base.OnDisconnectedAsync(exception)); } }