public async Task HangUp() { var callingUser = RTCUser.Get(Context.ConnectionId); if (callingUser == null) { return; } if (callingUser.CurrentRoom != null) { callingUser.CurrentRoom.Users.Remove(callingUser); await SendUserListUpdate(Clients.Others, callingUser.CurrentRoom, false); } lock (RoomsThatAreActive) { if (RoomsThatAreActive.Count() > 0 && callingUser.CurrentRoom != null) { var toRemove = RoomsThatAreActive.Where(m => m.Name == callingUser.CurrentRoom.Name).Select(m => m.Users).FirstOrDefault(); if (toRemove != null) { toRemove.Remove(callingUser); } } lock (RoomsThatAreFull) { if (callingUser.CurrentRoom != null && callingUser.CurrentRoom.Users.Count() == 0) { RoomsThatAreFull.Remove(callingUser.CurrentRoom); RoomsThatAreActive.Remove(callingUser.CurrentRoom); Room.Remove(callingUser.CurrentRoom); } } } RTCUser.Remove(callingUser); }
public async Task UserDisconnected(string userName) { var user = RTCUser.Get(userName, Context.ConnectionId); await Clients.All.SendAsync("UserDisconnected", user.UserName); }