RoomManager.ts
829 Bytes
import { RoomDescription } from "../../common/dataType";
import { Room } from "./Room";
export class RoomManager {
private rooms: Map<string, Room>;
constructor() {
this.rooms = new Map<string, Room>();
}
public create(name: string, maxConnections: number): Room {
const room = new Room(name, maxConnections);
this.rooms.set(room.uuid, room);
return room;
}
public get(uuid: string): Room | undefined {
return this.rooms.get(uuid);
}
public delete(uuid: string): void {
const room = this.get(uuid);
if (room !== undefined) {
room.close();
this.rooms.delete(uuid);
}
}
public list(): RoomDescription[] {
var roomData: RoomDescription[] = [];
this.rooms.forEach((room) => {
roomData.push(room.getDescription());
});
return roomData;
}
}