/** * WebSocket连接配置接口 */ export interface WebSocketConfig { uuid: string; /** WebSocket服务器URL */ url: string; /** WebSocket子协议 */ protocols?: string | string[]; /** 是否自动重连 */ reconnect?: boolean; /** 重连间隔(毫秒) */ reconnectInterval?: number; /** 最大重连次数 */ maxReconnectAttempts?: number; /** 初始消息 */ message?: any; /** 是否发送初始消息 */ isMessage?: boolean; /** 请求头 */ headers?: Record; /** 是否使用请求头 */ isHeaders?: boolean; /** 二进制数据类型 */ binaryType?: "blob" | "arraybuffer"; /** 连接超时时间(毫秒) */ timeout?: number; } /** * WebSocket事件回调接口 */ export interface WebSocketCallbacks { onOpen?: () => void; onClose?: () => void; onMessage?: (data: any) => void; onError?: (error: Event) => void; onReconnect?: () => void; } /** * WebSocket连接状态枚举 */ export declare enum WebSocketConnectionState { DISCONNECTED = "disconnected", CONNECTING = "connecting", CONNECTED = "connected", RECONNECTING = "reconnecting", ERROR = "error" } /** * WebSocket连接工具类 */ export declare class WebSocketClient { private client; private config; private callbacks; private connectionState; private reconnectAttempts; private reconnectTimer; private connectTimer; private isManualDisconnect; constructor(config: WebSocketConfig, callbacks?: WebSocketCallbacks); /** * 连接到WebSocket服务器 */ connect(): Promise; /** * 断开WebSocket连接 */ disconnect(): void; /** * 发送消息 */ send(data: any): void; /** * 检查是否已连接 */ isConnected(): boolean; /** * 获取连接状态 */ getConnectionState(): WebSocketConnectionState; /** * 处理重连 */ private handleReconnect; } /** * 创建WebSocket客户端实例的工厂函数 * 使用连接池确保相同配置只创建一次连接 */ export declare function createWebSocketClient(config: WebSocketConfig, callbacks?: WebSocketCallbacks): Promise; /** * 创建WebSocket客户端实例的同步工厂函数(不推荐,可能创建重复连接) * @deprecated 建议使用异步的 createWebSocketClient */ export declare function createWebSocketClientSync(config: WebSocketConfig, callbacks?: WebSocketCallbacks): WebSocketClient;