(ws: WebSocket)
| 82 | const noopConnectionControl = (_token?: string) => undefined; |
| 83 | |
| 84 | function closeWebSocketSafely(ws: WebSocket) { |
| 85 | try { |
| 86 | // readyState: 0 = CONNECTING, 1 = OPEN, 2 = CLOSING, 3 = CLOSED |
| 87 | if (ws.readyState === 2 || ws.readyState === 3) return; |
| 88 | ws.close(); |
| 89 | } catch { |
| 90 | // Some browsers throw if close() is called while already closing/closed. |
| 91 | // Since our cleanup can be invoked from multiple code paths, treat close as idempotent. |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | function isRecord(value: unknown): value is Record<string, unknown> { |
| 96 | return typeof value === "object" && value !== null; |
no test coverage detected