import Socket from './models/Socket'; import RoomDTO from './models/Room'; import BaseDO from './base/BaseDO'; import WsSet from './base/WsSet'; import SocketDO from './Socket'; import { SocketAliveResponse } from './types/Websocket'; export default class Room extends BaseDO { private gotSockets; private socketDos; private ws; constructor(options: { roomId: string; namespace: string; }); /** * get socketIds * 获取房间内的 socketIds * @example console.log(room.socketIds); * @return * @readonly */ get socketIds(): string[]; /** * set property * 设置属性 * @example await room.setProperty('key', 'value'); * @example await room.setProperty('key1', 'value', 'key2', ['key', 'value']); // set multiple properties * @param key * @param value * @return */ setProperty(...args: Array): this; /** * get property * 获取属性 * @example await room.getProperty('key'); * @example await room.getProperty('key1', 'key2'); // get multiple properties * @param key * @return */ getProperty(...args: Array): unknown; private _join; /** * socket join room * 加入房间 * @example await room.join(ws); * @param ws * @return */ join(ws: Socket): this; private _leave; /** * socket leave room * 离开房间 * @example await room.leave(ws); * @param ws * @return */ leave(ws: Socket): this; /** * get sockets in the room * 获取房间内的 sockets * @example await room.getSockets(); * @return */ getSockets(): Promise>; /** * get sockets in the room * 获取房间内的 sockets * @example await room.sockets(); * @return */ get sockets(): this; /** * get sockets in the room * 获取房间内的 sockets * @example await room.members(); * @return */ get members(): this; /** * broadcast data to all sockets in the room * 广播数据给房间内的所有 sockets * @example await room.broadcast('data'); * @param data * @return */ broadcast(data: any): this; /** * check if all sockets in the room are alive * 检查房间内的所有 sockets 是否都存活 * @example await room.socketsIsAlive(); * @return Array */ socketsIsAlive(): Promise>; /** * get room by id * 根据 roomId 获取房间 * @example await Room.get('roomId'); * @param roomId * @param namespace * @return room */ static get(roomId: string, namespace?: string): Promise; /** * find rooms by namespace * 根据 namespace 获取房间列表 * @example await Room.find('namespace'); * @param namespace * @return rooms */ static find(namespace?: string): Promise>; /** * init room from dto * 从 DTO 初始化房间 * @example Room.init(room); * @param room * @return room */ static init(room: RoomDTO): Room; protected afterChain(): Promise; toJSON(): { id: string; namespace: string; socketIds: string[]; }; toString(): string; [Symbol.toPrimitive](hint: string): string | true; }