RoomManager.ts
972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Room } from "./Room";
import { RoomDescription } from "./types";
export class RoomManager {
private static _instance: RoomManager;
private rooms: Map<string, Room>;
constructor() {
RoomManager._instance = this;
this.rooms = new Map<string, Room>();
}
public static instance(): RoomManager {
return RoomManager._instance;
}
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;
}
}