Computer >> Computer tutorials >  >> Programming >> Javascript

How can I make a browser to browser (peer to peer) connection in HTML?


For the browser to browser connection, follow the below-given steps −

All the following library −

<script src = "https://cdn.peerjs.com/0.3/peer.js"></script>

Create a peer −

For creating a peer, you need to get a free API key.

var peer = new Peer('pick-an-id', {key: 'myapikey'});

Connect −

var conn = peer.connect('another-peers-id');
conn.on('open', function(){
   conn.send('Welcome!');
});