PeerJS provides a complete, configurable, and easy-to-use peer-to-peer data API built on top of WebRTC.
Each peer simply provides a identifier with which other peers using the same API key can connect.
Include the library
<script src="http://cdn.peerjs.com/0/peer.js"></script>
Peer
<script>
var peer = new Peer('someid', {key: 'apikey'});
peer.on('connection', function(conn) {
conn.on('data', function(data){
// Will print 'hi!'
console.log(data);
});
});
</script>
Connecting peer
<script>
var peer = new Peer('anotherid', {key: 'apikey'});
var conn = peer.connect('someid');
conn.on('open', function(){
conn.send('hi!');
});
</script>
- Tests
- Firefox support
- Stream API
- Video/audio support