Chat — Minimal P2P chat
What this example does
Minimal P2P chat: join a topic, see peer count, and send and receive text messages. Uses only raw connection writes and no Protomux or Data API.
Prerequisites
Install the BridgeSwarm extension and native host before opening this example.
How to run
From the repo root:
npm run examples
Then open http://127.0.0.1:4173/chat/ (use two tabs for P2P).
Do not open index.html via file:// — browsers treat each local file as a unique origin and the demo will fail.
Usage
- Click Join (default topic is
bridge-swarm-demo). - Open the same page in another tab or device and join the same topic.
- Type a message and click Send; it appears in the other tab’s log.
- Click Leave when done.
Files in this directory
- index.html — Page structure and elements (topic input, join/leave/send buttons, log area).
- style.css — Layout and theme (dark background, inputs, buttons, log).
- app.js — BridgeSwarm setup, join/leave/send logic, connection handling and message log.
APIs and concepts
BridgeSwarm.ready()— Wait for the injected API.new BridgeSwarm({ appName })— Create a swarm.swarm.join(topic)/swarm.leave(topic)— Topic discovery.swarm.on('connection', …)— Peer connections.conn.write(data)/conn.on('data', …)— Raw messages.