Hyperlinkv0.8.0-beta.28

Hyperlink

Hyperlink.protocolWebsocketconstsrc/Hyperlink.ts:4123
(
  target?: number | string,
  serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
): Layer.Layer<RpcClient.Protocol>

Build a WebSocket client Protocol (one multiplexed connection + ndjson) for one endpoint url (default "/rpc"). The url may be a same-origin path ("/rpc" — resolved against the page location, http→ws / https→wss), an http(s):// url (scheme swapped), or an absolute ws(s):// url; resolution is lazy, so this is safe at module scope in a file a Node server also imports. The browser transport — every stream rides one connection, past the ~6-connection cap that starves streams over protocolHttp.

transportsprotocolHttp
Source src/Hyperlink.ts:412315 lines
export const protocolWebsocket = (
  target: number | string = "/rpc",
  serialization: Layer.Layer<RpcSerialization.RpcSerialization> = defaultSerialization,
): Layer.Layer<RpcClient.Protocol> => {
  const build = (url: string): Layer.Layer<RpcClient.Protocol> =>
    RpcClient.layerProtocolSocket().pipe(
      Layer.provide(serialization),
      Layer.provide(Socket.layerWebSocket(Effect.sync(() => toWebSocketUrl(url)))),
      Layer.provide(Socket.layerWebSocketConstructorGlobal),
    );
  // A bare port defers to the `clientHost` Config (→ `ws://${host}:port/rpc`); a path / url stays sync.
  return typeof target === "number" || /^:\d+$/.test(target)
    ? Layer.unwrap(Effect.map(clientTargetUrl("ws", target), build))
    : build(target);
};
Referenced by 2 symbols