()
| 245 | |
| 246 | ws.addEventListener('message', (event: MessageEvent) => { |
| 247 | if (this.ws !== ws) return; |
| 248 | this.handleMessage(event.data as string); |
| 249 | }); |
| 250 | |
| 251 | ws.addEventListener('close', () => { |
| 252 | if (this.ws !== ws) return; |
| 253 | this.connected = false; |
| 254 | this.stopPing(); |
| 255 | this.clearHandshakeTimer(); |
| 256 | if (!this.destroyed) { |
| 257 | this.scheduleReconnect(); |
| 258 | } |
| 259 | }); |
| 260 | |
| 261 | ws.addEventListener('error', () => { |
| 262 | if (this.ws !== ws) return; |
| 263 | // error is always followed by close, so we only need to reject the |
| 264 | // connect promise here if we never opened. The browser does not expose |
| 265 | // the HTTP status of a failed upgrade, so reconnect and reserve auth |
| 266 | // recovery for the preceding connection-ticket HTTP request. |
| 267 | if (!this.connected) { |
| 268 | settleReject(new Error('WebSocket connection failed')); |
no test coverage detected