Hyperlinkv0.8.0-beta.28

Hyperlink

Hyperlink.wsconstsrc/Hyperlink.ts:4196
<Self>(
  node: NodeKey<Self> & {
    readonly url?: string
    readonly endpoints?: Endpoints
  },
  options?: {
    readonly url?: string
    readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>
  }
): Layer.Layer<Self, NodeUnreachable | UnaddressedNode>

Wire a Node's transport over a WebSocket — the browser counterpart to http. Every stream (each resource's status + metrics + logs) rides one multiplexed connection, so a dashboard never trips the browser's ~6-connection-per-origin HTTP/1.1 limit that starves streams over http (in a browser http now fails hard — see its note). The server must be a wsServer.

The url may be a same-origin path ("/rpc" — resolved against the page location, so the browser follows its own host + scheme, http→ws / https→wss), an http(s):// url (scheme swapped), or an absolute ws(s):// url. Resolution is lazy, so this is safe to call at module scope in a file a Node server also imports. Uses the browser's global WebSocket.

const EdgeLive = Hyperlink.ws(EdgeNode, { url: "/rpc" }); // same origin as the page
clientsNodehttpwsServer
Source src/Hyperlink.ts:419623 lines
const ws = <Self>(
  node: NodeKey<Self> & { readonly url?: string; readonly endpoints?: Endpoints },
  options?: {
    readonly url?: string;
    readonly serialization?: Layer.Layer<RpcSerialization.RpcSerialization>;
  },
): Layer.Layer<Self, NodeUnreachable | UnaddressedNode> => {
  // The client sibling of {@link Node.ws} = `connect` + {@link protocolWebsocket}. Prefers the node's
  // own WebSocket endpoint (multi-protocol — its primary `url` is the Http one on an `{ http, ws }`
  // node), then the primary `url`, then `"/rpc"`; `options.url` overrides.
  const url =
    options?.url ?? node.endpoints?.WebSocket?.url ?? node.url ?? "/rpc";
  const wired = connectLayer(
    node,
    protocolWebsocket(url, options?.serialization),
  );
  return Layer.unwrap(
    Effect.gen(function* () {
      yield* applyClientVerify(node as AnyNode, { url });
      return wired;
    }),
  ) as Layer.Layer<Self, NodeUnreachable | UnaddressedNode>;
};