import { SocketCloseOptions } from "../SocketCloseOptions"; import { SocketSendOptions } from "../SocketSendOptions"; import { SocketCloseEvent } from "../SocketCloseEvent"; import { SocketErrorEvent } from "../SocketErrorEvent"; import { SocketMessageEvent } from "../SocketMessageEvent"; import { SocketOpenEvent } from "../SocketOpenEvent"; declare const readyStates: { readonly CONNECTING: 0; readonly OPEN: 1; readonly CLOSING: 2; readonly CLOSED: 3; }; declare type ReadyState = typeof readyStates[keyof typeof readyStates]; declare type SocketEventType = 'open' | 'message' | 'error' | 'close'; export declare const socketTaskSet: Set; export declare const globalSocketEventCallbacks: Partial any>>>; /** * @internal */ export declare const createCallbackHandler: (taskId: number, type: SocketEventType) => (...params: any[]) => void; /** * WebSocket 任务,可通过 ks.connectSocket() 接口创建返回。 */ export interface SocketTask { readyState: ReadyState; /** * 关闭 WebSocket 连接。 * @param options * @returns */ close(options?: SocketCloseOptions): Promise; /** * 通过 WebSocket 连接发送数据。 * @param options * @returns */ send(options: SocketSendOptions): Promise; /** * 监听 WebSocket 连接关闭事件。 * @param callback WebSocket 连接关闭事件的回调函数 */ onClose(callback: (event: SocketCloseEvent) => void): void; /** * 监听错误事件。 * @param callback 错误事件的回调函数 */ onError(callback: (event: SocketErrorEvent) => void): void; /** * 监听 WebSocket 接受到服务器的消息事件。 * @param callback WebSocket 接受到服务器的消息事件的回调函数 */ onMessage(callback: (event: SocketMessageEvent) => void): void; /** * 监听 WebSocket 连接打开事件。 * @param callback WebSocket 连接打开事件的回调函数 */ onOpen(callback: (event: SocketOpenEvent) => void): void; } export {};