import type WS from '@alipay/faas-server-sdk/lib/Websocket'; import { CloseOptions, FaasWebSocketIOConfig, SocketAliveResponse } from './types/Websocket'; import Chain from './base/Chain'; import FaasWebSocket from './Socket'; import WSSet from './base/WsSet'; import Room from './Room'; import Socket from './Socket'; type RoomSet = WSSet; type SocketSet = WSSet; export default class FaasWebSocketIO extends Chain { private _storage; private _rooms; private _broadcast; private namespace; private currentConnectionId; ws: WS.WebsocketSDK; Websocket: typeof FaasWebSocket; constructor(options: FaasWebSocketIOConfig); /** * init storage instance * @param options * @return */ private initStorage; /** * 获取房间列表 * get room list * @example console.log(await io.rooms); * @return */ get rooms(): Promise; /** * 获取房间内的所有连接 * get all connections in the room * @example console.log(await io.sockets); * @return {Promise} */ get sockets(): Promise; /** * 发送数据除了当前连接外广播给所有连接,如果没有设置 currentConnectionId 则广播给所有连接 * send data to all connections except the current connection, if currentConnectionId is not set, broadcast to all connections * @example await io.broadcast.emit('event', 'data'); */ get broadcast(): this; /** * 当前所有 sockets 加入指定的房间 * all current sockets join the specified room * @example await io.socketsJoin('roomId'); * @param roomId 房间 ID, 可以是数组 */ socketsJoin(roomId: string | Array): any; /** * 当前所有 sockets 离开指定的房间 * all current sockets leave the specified room * @example await io.socketsLeave('roomId'); * @param roomId 房间 ID, 可以是数组 */ socketsLeave(roomId: string | Array): any; /** * specify the namespace to filter * 筛选指定命名空间 * @example io.of('/namespace').to('roomId').emit('event', 'data'); * @param namespace * @return */ of(namespace: string): this; /** * specify the room to filter * 筛选指定房间 * @example await io.to('roomId').emit('event', 'data'); * @param roomId * @return */ to(roomId: string): this; /** * specify the room to filter * 筛选指定房间 * @example await io.in('roomId').emit('event', 'data'); * @param roomId * @return */ in(roomId: string): this; /** * exclude specified room * 排除指定房间 * @example await io.except('roomId').emit('event', 'data'); * @param roomId 房间 ID, 可以是数组 * @return */ except(roomId: string | Array): this; /** * on event 暂时不可用请不要调用 * @deprecated * @param event * @param handler */ /** * send data to all sockets in the room or all sockets in the namespace if no room is filtered * 发送数据 给房间内的所有 sockets 或者如果没有筛选房间则给命名空间内的所有 sockets * @example await io.emit('event', 'data'); * @param event 自定义事件 * @param data 数据 * @return */ emit(event: string, data: any): unknown; /** * send data to all sockets in the room or all sockets in the namespace if no room is filtered * 发送数据 给房间内的所有 sockets 或者如果没有筛选房间则给命名空间内的所有 sockets * @example await io.send('data'); * @param data */ send(data: any): unknown; private getCurrentSockets; /** * close sockets connection and delete storage data, if no room is filtered, close all connections, if there is a room filter, close all connections in the room * 主动关闭连接,同时删除 storage 中对应的数据,如果没有筛选房间则关闭所有连接, 如果有筛选房间则关闭房间内的所有连接 * @param options close options * @example await io.close(); * @return */ close(options?: CloseOptions): unknown; /** * only delete storage data, do not close the connection, if no room is filtered, delete all connections, if there is a room filter, delete all connections in the room * 仅删除 storage 中对应的数据,不会关闭连接,如果没有筛选房间则删除所有连接, 如果有筛选房间则删除房间内的所有连接 * @example await io.delete(); * @return */ delete(): unknown; /** * check if all sockets are alive * 检查所有 sockets 是否都存活 * @example await wsio.of('room1').socketsIsAlive(); * @return Array */ socketsIsAlive(): Promise>; protected afterChain(): Promise; toJSON(): {}; toString(): string; [Symbol.toPrimitive](hint: string): string | true; } export {};