hyperswarm-web
Implementation of the hyperswarm API for use in web browsers
Using in an application
npm i -s hyperswarm-web
// Based on example in hyperswarm repo// Try running the regular hyperswarm demo with nodeconst hyperswarm = const crypto = const swarm = // look for peers listed under this topicconst topic = crypto swarm swarm
Build it with Browserify to get it running on the web.
You could also compile an existing codebase relying on hyperswarm to run on the web by adding a browser
field set to {"hyperswarm": "hyperswarm-web"}
to have Browserify alias it when compiling dependencies.
Setting up a proxy server
HyperswarmServer
provides two services:
- HyperswarmProxyWS: to proxy hyperswarm connections over websockets. Path:
ws://yourserver/proxy
- SignalServer: for P2P WebRTC signaling connections. Path:
ws://yourserver/signal
Running a HyperswarmServer
will allows you to use both services in one single process.
npm i -g hyperswarm-web
# Run it! Default port is 4977 (HYPR on a phone pad)
hyperswarm-web
# Run it with a custom port
hyperswarm-web --port 42069
Running as a Linux service with SystemD
sudo cat << EOF > /etc/systemd/system/hyperswarm-web.service[Unit]Description=Hyperswarm proxy server which webpages can connect to. [Service]Type=simple# Check that hyperswarm-web is present at this location # If it's not, replace the path with its location # You can get the location with 'whereis hyperswarm-web' # Optionally add a --port parameter if you don't want 4977 ExecStart=/usr/local/bin/hyperswarm-webRestart=always [Install]WantedBy=multi-user.targetEOF sudo chmod 644 /etc/systemd/system/hyperswarm-web.service sudo systemctl daemon-reloadsudo systemctl enable hyperswarm-websudo systemctl start hyperswarm-web sudo systemctl status hyperswarm-web