* Close the WebSocket connection
()
| 367 | * Close the WebSocket connection |
| 368 | */ |
| 369 | close(): void { |
| 370 | logForDebugging('[SessionsWebSocket] Closing connection') |
| 371 | this.state = 'closed' |
| 372 | this.stopPingInterval() |
| 373 | |
| 374 | if (this.reconnectTimer) { |
| 375 | clearTimeout(this.reconnectTimer) |
| 376 | this.reconnectTimer = null |
| 377 | } |
| 378 | |
| 379 | if (this.ws) { |
| 380 | // Null out event handlers to prevent race conditions during reconnect. |
| 381 | // Under Bun (native WebSocket), onX handlers are the clean way to detach. |
| 382 | // Under Node (ws package), the listeners were attached with .on() in connect(), |
| 383 | // but since we're about to close and null out this.ws, no cleanup is needed. |
| 384 | this.ws.close() |
| 385 | this.ws = null |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Force reconnect - closes existing connection and establishes a new one. |
no test coverage detected