import { Room , Client , IRoomObject } from "../internal" ; export interface ILobbyRoomParams { watch : string [ ] ; } export class LobbyRoom extends Room { public watch ! : string [ ] ; public rooms : { [ name ] : IRoomObject [ ] ; } = { } ; public subscribers : Set < Client > = new Set ( ) ; public getRooms : ( ( names : string [ ] ) => Promise < IRoomObject [ ] > ) | null = null ; public onRoomUpdate ( roomId , data ) { this . subscribers . forEach ( ( client ) => client . send ( "room_update" , { roomId , data } ) ) ; } public onCreate ( params ) { this . watch = params . watch || [ ] ; } public async onJoin ( client ) { if ( this . getRooms ) { client . send ( "rooms" , await this . getRooms ( this . watch ) ) ; this . subscribers . add ( client ) ; } } public onLeave ( client ) { this . subscribers . delete ( client ) ; } }