| 299 | type WebSocketCtor = new (url: string, protocol?: string | string[]) => WebSocketLike; |
| 300 | |
| 301 | function resolveWebSocketFactory( |
| 302 | factory: WebSocketFactory | undefined, |
| 303 | ): WebSocketFactory | undefined { |
| 304 | if (factory) return factory; |
| 305 | const ctor = (globalThis as { WebSocket?: WebSocketCtor }).WebSocket; |
| 306 | if (typeof ctor !== "function") return undefined; |
| 307 | return (url, protocol) => { |
| 308 | const normalizedProtocol = Array.isArray(protocol) ? Array.from(protocol) : protocol; |
| 309 | return new ctor(url, normalizedProtocol as string | string[] | undefined); |
| 310 | }; |
| 311 | } |
| 312 | |
| 313 | function toWebSocketPayload(event: unknown): unknown { |
| 314 | if (!event || typeof event !== "object") return event; |