Files
BridgeSwarm/examples/sdk-demo
Raven Scott 8c95a97662
CI / Build & Test (push) Successful in 3m0s
fixes
2026-07-26 22:19:31 -04:00
..
2026-02-21 02:52:00 -05:00
2026-07-26 22:19:31 -04:00
2026-07-26 22:19:31 -04:00

SDK Demo — Swarm, connections, raw messages, and Protomux

What this example does

Demonstrates all core BridgeSwarm SDK features in one page: swarm lifecycle, connection events and peerInfo, raw byte messages, and Protomux (channel with string and binary messages).

Prerequisites

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

How to run

npm run examples

Open http://127.0.0.1:4173/sdk-demo/ (two tabs for P2P). Do not use file://.

Usage

  1. Click Join topic (default bridge-swarm-sdk-demo).
  2. Open the same page in another tab and join the same topic.
  3. Use Send raw to send text as raw bytes; use Send Protomux to send via the Protomux channel. The log shows which path each message used.
  4. Click Leave and destroy when done.

Files in this directory

  • index.html — Page structure (topic, join/leave, raw/protomux inputs and buttons, log).
  • style.css — Layout and theme (sections, badges, log).
  • app.js — BridgeSwarm and Protomux setup, connection handling, raw and Protomux send/receive.

APIs and concepts

  • Swarm/connection as in chat: BridgeSwarm.ready(), new BridgeSwarm(), swarm.join(), swarm.on('connection'), conn.on('data'), conn.write().
  • swarm.createProtomux(conn) — Create a Protomux instance on the connection.
  • mux.createChannel with protocol 'sdk-demo/v1' — Create a channel.
  • channel.addMessage with encoding c.string or c.binary — Add string or binary message handlers; uses window.BridgeSwarmProtomux.c and b4a.
  • channel.open(), message.send() — Open channel and send.
  • Raw path: conn.write(data) and conn.on('data') for unencoded bytes.

See also