Set up WebRTC connections between peers using nothing but an id.
- Simple way to set up peer-to-peer connections using WebRTC by giving peers an id.
- Provides a broker server for you, so you don't need to set up a server. You can run your own broker server too if you want.
- Open system. Like with the internet, each peer can connect to each other peer, and it's up to the peer to accept or deny connections. This is unlike most messaging platforms where you get an application key and peers can only talk to other peers within the same application (closed system).
- Works in browsers and node.js.
WebRTC relies on STUN and TURN servers for setting up connections between peers (via the ICE protocol). A STUN server is used to get an external network address, this is cheap and there are many STUN servers freely available. TURN servers are used to relay traffic if direct (peer to peer) connection fails. Since a TURN server passes all data the peers via the server, it requires a lot of bandwidth. Therefore TURN servers are not free.
linkup is configured to use the free STUN/TURN service from Viagénie, which is great for development and will get you going without having to set something up. For production use you will have to use (and pay for) your own STUN/TURN server or service.
Install the library via npm:
$ npm install linkup
Here a simple example on how to use the library in the browser. More examples are available in the examples folder.
<!-- load the linkup client library -->
Before the library can be used in node.js the
wrtc library has to be installed:
$ npm install wrtc
linkup can be loaded like:
var linkup = ;// create a peer with some idvar peer = linkup;// listen for messages from other peerspeer;// we want to know when something goes wrongpeer;// send a message to a peerpeer;
First install the dependencies once:
$ npm install
To build & run the broker server in development mode with debugging:
$ npm start
Then open the following url in your browser:
Note that the server must be restarted by hand on changes in the code.
The following environment variables can be provided:
|PORT||Port number for the server.|
|REDISCLOUD_URL||Optional redis database url, used for pub/sub messaging between multiple broker servers in a cluster.|
$ PORT=5001 npm start
The build script generates a bundled file for both peer libraries and for running the broker server.
$ npm install$ npm run build
To run the generated the generated code for the broker server:
$ node dist/broker/server
To deploy to heroku, first set a git remote to your heroku application:
$ heroku git:remote -a my-heroku-app
Then force Heroku to install all devDependencies, as it has to built the server application on startup:
$ heroku config:set NPM_CONFIG_PRODUCTION=false
In order to make the broker server scalable, multiple broker servers can be be set up in a cluster. The servers communicate via pub/sub messaging powered by Redis. This is optional.
To add a (free) Redis database to the Heroku setup:
$ heroku addons:create rediscloud
$ npm run deploy
To publish a new version of
linkup on npm:
- Update the version number in package.json.
- Update the CHANGELOG.md
npm run build
- Create a git tag for the new version:
git tag v1.2.3; git push --tags
- Support for Android and iOS.
- Support for letting peers authenticate each other for example with a Google or Facebook id.
- Support authentication against the broker server, allowing to set up a private broker server.