Decentralized signalling for simple-peer using the Ethereum Whisper protocol.
Still an open research project, but it works! If you have a local node, try the demo!
- All signalling data is sent over Whisper. Only STUN servers are used.
- Video, voice, data and all the features of WebRTC work as normal.
- Adapts almost all client features from
simple-signal
.
With Browserify:
npm install shh-signal --save
Without Browserify:
<script src="dist/shh-signal-client.js"></script>
You also need access to the global Web3
object. shh-signal
is currently only tested with the version in dist/web3.min.js
.
You will also need a local Ethereum node with Websockets JSON-RPC and Whisper enabled.
A common signaling scheme is to connect two clients by having one client "call" the ID of another.
Client:
const web3 = new Web3(new Web3.providers.WebsocketProvider('ws://localhost:8546')) // setup web3
const signalClient = new ShhSignalClient(web3) // setup shh-signal
const allIDs = []
signalClient.on('discover', async (newID) => {
allIDs.push(newID)
const id = await promptUserForID(allIDs) // Have the user choose an ID to connect to (you define this)
const { peer } = await signalClient.connect(id) // connect to target client
peer // this is a fully-signaled simple-peer object (initiator side)
})
signalClient.on('request', async (request) => {
const { peer } = await request.accept() // Accept the incoming request
peer // this is a fully-signaled simple-peer object (non-initiator side)
})
See example.js
for a more comprehensive example.
Create a new signalling client.
Required web3
is a web3 instance with a provider that supports both Whisper and subscriptions (such as a WebsocketProvider
connected to a local geth
node started with the --shh
option).
Options:
connectionTimeout: number = 10000
: Defines the time to wait to establish a connection.roomPassword": string = ""
: A secret passphrase used to encrypt connection messages.
The identifying string for this client's socket. null
until discovery completes. Consists of 2 public keys pubKey
and sig
, used for encryption and signing respectively.
Initiate discovery.
discoveryData
is any discovery data to be sent to all peers with the room password.
Request to connect to another client. Returns a Promise.
id
is the signalClient.id
of the other client.
Optional metadata
is any serializable object to be passed along with the request.
Optional peerOptions
are the options to be passed to the SimplePeer
constructor.
Fired when the client has discovered a remote peer with the room password, or that peer has restarted discovery.
remoteID
is the remote ID of the new peer.
discoveryData
is any additional data that has been passed by the remote peer.
Fired on receiving a request to connect from another client.
The id of the remote client's socket.
Any additional metadata passed by the requesting client.
Accept the request to connect. Not calling this method will ignore the request. Returns a Promise.
metadata
is any serializable object to be passed along with the answer.
peerOptions
are the options to be passed to the SimplePeer
constructor.
Promise will reject if the other side calls reject()
.
Rejects the request to connect. Not calling this method will ignore the request.
metadata
is any serializable object to be passed along with the rejection.
List all currently connecting/connected peers. Returns an array of SimplePeer
objects.
- Download Grid: https://grid.ethereum.org/#downloads
- Install and launch Grid.
- Go to
Geth > Settings
and enableUse custom flags
. - Add these flags to enable Websockets and Whisper:
--ws --wsorigins=* --shh
- Start Geth and wait for the node to sync.
- Done! You can now use this library to connect to everyone else on the Ethereum Whisper network!
Support this project by becoming a sponsor. Your logo will appear here with a link to your website. [Become a sponsor]