Files
BridgeSwarm/examples/hrpc-demo

HRPC Demo — Unary RPC (ping/pong) over a connection

What this example does

HRPC on a connection: HRPC is auto-enabled when a peer connects. Either tab can use "Ping peer" to get a pong (unary RPC). No manual attach step in the UI after connect.

Prerequisites

Install the BridgeSwarm extension and native host before opening this example.

How to run

Open index.html in your browser (File → Open or drag the file in). For file:// URLs, ensure the extension has Allow access to file URLs enabled, or run a local server (e.g. npx serve . from the examples folder) and open http://localhost:3000/hrpc-demo/.

Usage

  1. Click Join topic (default bridge-swarm-hrpc-demo).
  2. Open the same page in another tab and join the same topic.
  3. When connected, HRPC is enabled automatically; use Ping peer (optionally enter a value). Use Retry HRPC on selected connection if the first enable is still pending.
  4. Click Leave and destroy when done.

Files in this directory

  • index.html — Page structure (topic, join/leave, connection selector, HRPC retry, ping input/button, log).
  • style.css — Layout and theme (sections, badges, log).
  • app.js — BridgeSwarm setup, auto attachHrpc on connection, hrpcInvoke(ping), connection selector and UI state.

APIs and concepts

  • Swarm/connection as in chat: BridgeSwarm.ready(), new BridgeSwarm(), swarm.join(), swarm.on('connection'), conn.connId, conn.on('end'), conn.on('error').
  • BridgeSwarm.request('attachHrpc', { connId }) — Enable HRPC on the connection (called automatically on each new connection).
  • BridgeSwarm.request('hrpcInvoke', { connId, method: 'ping', args }) — Invoke the unary ping RPC; host runs HRPC on the connection, browser only invokes ping.

See also