@@ -8,7 +8,11 @@ These are the main APIs your page uses. For host request types and event payload
|
||||
`await BridgeSwarm.ready()` or `BridgeSwarm.ready().then(swarm => { ... })`.
|
||||
**Default ready timeout:** If the extension option “Default ready timeout (ms)” is set to a value > 0, `ready()` will reject after that many milliseconds with a message like `"BridgeSwarm not available within N ms"` when the API has not appeared (e.g. extension not installed or injection failed). Use 0 in options to wait indefinitely (default).
|
||||
|
||||
- **`new BridgeSwarm(options)`** — Constructor options are passed to Hyperswarm on the host. Supported: **`appName`** (string), **`maxPeers`** (number, cap on peer connections per swarm). If the page omits `appName` or `maxPeers`, the extension **defaults** from the options page are used (default app name, default max peers). Default max peers 0 means no limit. Firewall is **not** a JS function in options — use `swarm.setFirewall(...)` after construct.
|
||||
- **`new BridgeSwarm(options)`** — Constructor options are passed to Hyperswarm on the host. Supported: **`appName`** (string), **`maxPeers`** (number, cap on peer connections per swarm), **`swarmId`** (string — reuse an existing host swarm after reload), **`seedHex`** (64-char hex — stable Noise keypair across destroy/recreate). If the page omits `appName` or `maxPeers`, the extension **defaults** from the options page are used (default app name, default max peers). Default max peers 0 means no limit. Firewall is **not** a JS function in options — use `swarm.setFirewall(...)` after construct.
|
||||
|
||||
- **`swarm.getPublicKey()`** — Resolves after host init; safe to call before `join` so handshakes can include identity immediately.
|
||||
|
||||
- **`swarm.resumeConnections()`** — After reload with the same `swarmId`, re-attaches live host sockets and emits `connection` for each peer that is not already wrapped.
|
||||
|
||||
- **`swarm.setFirewall({ mode, keys })`** — `mode`: `off` | `allowlist` | `denylist`; `keys` are public-key hex strings.
|
||||
|
||||
@@ -54,10 +58,11 @@ Used by the BridgeSwarm class. All payloads include `swarmId` (chosen by the cli
|
||||
|
||||
| Type | Payload | Response |
|
||||
|------|---------|----------|
|
||||
| `init` | `{ swarmId, options? }` — options passed to Hyperswarm (`appName`, `maxPeers`; firewall is host-managed via `setFirewall`) | `{ ok }` |
|
||||
| `init` | `{ swarmId, options? }` — options: `maxPeers`, `seedHex`/`seed` (64 hex → stable keypair); `appName` stripped (dashboard metadata). Re-init with same `swarmId` resumes host swarm | `{ ok, resumed? }` |
|
||||
| `join` | `{ swarmId, topic }` — topic as 32-byte hex string; optional `opts` | `{ ok }` or `{ ok: false, error }` |
|
||||
| `leave` | `{ swarmId, topic }` — topic as 32-byte hex string | `{ ok }` |
|
||||
| `swarmKey` | `{ swarmId }` | `{ ok, publicKey }` (hex) — used by `swarm.getPublicKey()` |
|
||||
| `listConnections` | `{ swarmId }` | `{ ok, connections: [{ connId, peerInfo }] }` — used by `swarm.resumeConnections()` |
|
||||
| `setFirewall` | `{ swarmId, mode, keys }` — `mode`: `off` \| `allowlist` \| `denylist` | `{ ok, mode, keys }` |
|
||||
| `banPeer` | `{ swarmId, publicKeyHex, banned? }` | `{ ok, banned, publicKeyHex }` |
|
||||
| `setAutoReplicate` | `{ swarmId, enabled, coreKeyHex?, resourceId? }` | `{ ok, enabled }` |
|
||||
|
||||
Reference in New Issue
Block a user