Hyperlinkv0.8.0-beta.28

Node

Node.connectSocketconstsrc/internal/node.ts:285
(url: string): <Self>(node: NodeKey<Self>) => Layer.Layer<Self>
<Self>(
  node: NodeKey<Self> & {
    readonly url?: string
    readonly endpoints?: Endpoints
  }
): Layer.Layer<Self>

Wire a node over a WebSocket — Effect's layerProtocolSocket transport (WS in the browser), connect pinned to kind: "WebSocket". Dual: MyNode.pipe(Hyperlink.connectSocket) uses the node's own url (or "/rpc"); MyNode.pipe(Hyperlink.connectSocket(url)) overrides it.

connectconnect
export const connectSocket: {
  // data-last first, node form last — see connectHttp.
  (url: string): <Self>(node: NodeKey<Self>) => Layer.Layer<Self>;
  <Self>(
    node: NodeKey<Self> & { readonly url?: string; readonly endpoints?: Endpoints },
  ): Layer.Layer<Self>;
} = Fn.dual(
  (args: IArguments) => typeof args[0] !== "string",
  (
    node: NodeKey<unknown> & { readonly url?: string; readonly endpoints?: Endpoints },
    url?: string,
    // Prefer the node's OWN WebSocket endpoint over the primary `url`: on a multi-protocol `{ http, ws }`
    // node the primary is the Http url, so `node.url` would dial ws against the http endpoint (footgun).
    // Fall back to `node.url` (scheme-swapped) for a single-transport / co-mounted node.
  ): Layer.Layer<unknown> =>
    connectLayer(
      node,
      Hyperlink.protocolWebsocket(url ?? node.endpoints?.WebSocket?.url ?? node.url ?? "/rpc"),
    ),
);