* 发送消息
(message: any)
| 146 | * 发送消息 |
| 147 | */ |
| 148 | send(message: any): void { |
| 149 | const data = typeof message === "string" ? message : JSON.stringify(message); |
| 150 | |
| 151 | if (this.state === WebSocketState.CONNECTED && this.ws) { |
| 152 | try { |
| 153 | this.ws.send(data); |
| 154 | } catch (error) { |
| 155 | console.error("[WebSocket] Send failed:", error); |
| 156 | // 发送失败,加入队列 |
| 157 | this.messageQueue.push(message); |
| 158 | } |
| 159 | } else { |
| 160 | // 未连接,加入队列 |
| 161 | this.messageQueue.push(message); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * 添加消息监听器 |
no outgoing calls
no test coverage detected