Example #1
0
        public override Task OnDisconnected(bool stopCalled)
        {
            string connection = Context.ConnectionId;

            var rooms = Rooms.Where(r => r.User1.ConnectionId == connection || r.User2.ConnectionId == connection || r.User1.ConnectionId == connection || r.User2.ConnectionId == connection).ToList();

            for (int i = 0; i < rooms.Count; i++)
            {
                Clients.Clients(new List <string> {
                    rooms[i].User1.ConnectionId, rooms[i].User2.ConnectionId
                }).roomClosed();
                Rooms.Remove(rooms[i]);
            }

            Users.RemoveAll(u => u.ConnectionId == connection);
            LogUsers();
            return(base.OnDisconnected(stopCalled));
        }