Spaces:
Sleeping
Sleeping
| import WebSocket from 'ws'; | |
| class RoomServices { | |
| map; | |
| //instead of WebSocket[] use Map<string, WebSocket> mapped to username to its websocket, so you cna make him leave whenever needed! | |
| constructor() { | |
| this.map = new Map(); | |
| } | |
| hasRoom(roomId) { | |
| return this.map.has(roomId); | |
| } | |
| getRoom(roomId) { | |
| return this.map.get(roomId); | |
| } | |
| leaveRoom(roomId, username) { | |
| return this.getRoom(roomId)?.delete(username) === true; | |
| } | |
| putRoom(roomId, username, ws) { | |
| if (!this.hasRoom(roomId)) | |
| this.map.set(roomId, new Map()); | |
| this.map.get(roomId)?.set(username, ws); | |
| } | |
| getConnection(room_id, username) { | |
| return this.map.get(room_id)?.get(username); | |
| } | |
| } | |
| export default RoomServices; | |
| //# sourceMappingURL=RoomServices.js.map |