1.3 KiB
1.3 KiB
Auto-replicate — Hypercore sync on new connections
What this example does
Turns on swarm.setAutoReplicate({ enabled: true }) so every new Hyperswarm connection is taken over by the host for Hypercore replication. Append blocks in one tab and watch core.length grow in the other.
Those sockets are not usable for page chat or in-page Protomux while auto-replicate is on.
Prerequisites
Install the BridgeSwarm extension and native host.
How to run
Recommended: Extension Settings → enable Examples server.
npm run examples
Open http://127.0.0.1:4173/sync-demo/ in two tabs. Do not use file://.
Usage
- Join the same topic in both tabs.
- Enable auto-replicate.
- Append text in one tab.
- Click Core info in the other — length should increase after the cores replicate.
Files in this directory
- index.html — Topic, auto-replicate toggles, append, log.
- style.css — Layout.
- app.js — Swarm session,
setAutoReplicate,coreAppend/coreInfo.
APIs and concepts
swarm.setAutoReplicate({ enabled, coreKeyHex?, resourceId? })attachReplication(what auto-replicate runs per connection)- Default Hypercore name
'default'
See Data API.