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 = "http://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!');
});

Updated on: 24-Jun-2020

324 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements