MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / resolveWebSocketFactory

Function resolveWebSocketFactory

packages/core/src/widgets/hooks/data.ts:301–311  ·  view source on GitHub ↗
(
  factory: WebSocketFactory | undefined,
)

Source from the content-addressed store, hash-verified

299type WebSocketCtor = new (url: string, protocol?: string | string[]) => WebSocketLike;
300
301function 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
313function toWebSocketPayload(event: unknown): unknown {
314 if (!event || typeof event !== "object") return event;

Callers 1

useWebSocketFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected