Joining Hyperswarms via WebSocket gateways
MIT License
Use a WebSocket gateway to bridge Hyperswarm connections via hyperswarm-proxy
to the browser.
npm install hyperswarm-ws
Join a Hyperswarm via a WebSocket gateway. For more, look up the Hyperswarm documentation.
const crypto = require('crypto')
const { ClientSwarm } = require('hyperswarm-ws')
// look for peers listed under this topic
const topic = crypto
.createHash('sha256')
.update('my-hyperswarm-topic')
.digest()
const swarm = new ClientSwarm('ws://localhost:4200')
swarm.join(topic)
swarm = new ClientSwarm(gateway, [opts])
Create a new client instance that connects to a WebSocket gateway given the a gateway URL. gateway
may alternatively be a websocket connection stream (created using websocket-stream
).
The class extends HyperswarmProxyClient
of hyperswarm-proxy
, so it will
opts
, with
opts.pingInterval
being the interval used for pinging clients (default: 3500 ms),reconnect
, join
, leave
, destroy
.swarm = async createClientSwarm(gatewayUrls)
Given an array of gateway URLs, try all gateways for working connections until the first one is found. Will pass that URL as websocket stream to a new ClientSwarm
instance.
If none of the gateways works, an error with err.code = 'EBADGATEWAYS'
is thrown.
For running a gateway, use hyperswarm-ws-gateway [-p <port>]
. Will run a WebSocket gateway on the given port that bridges all incoming WebSocket streams into the Hyperswarm network.