peerjs.com Open in urlscan Pro
76.76.21.21  Public Scan

Submitted URL: http://peerjs.com/
Effective URL: https://peerjs.com/
Submission Tags: tranco_l324
Submission: On November 28 via api from DE — Scanned from DE

Form analysis 0 forms found in the DOM

Text Content

PEER JS
Home Get Started API Reference Examples PeerServer Cloud Team



THE PEERJS LIBRARY

PeerJS simplifies WebRTC peer-to-peer data, video, and audio calls.

PeerJS wraps the browser's WebRTC implementation to provide a complete,
configurable, and easy-to-use peer-to-peer connection API. Equipped with nothing
but an ID, a peer can create a P2P data or media stream connection to a remote
peer.

DOWNLOADS

Stable ( 1.3.1)



SETUP

INCLUDE THE LIBRARY

<script src="https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js"></script>


CREATE A PEER

var peer = new Peer(); 



DATA CONNECTIONS

CONNECT

var conn = peer.connect('another-peers-id');
// on open will be launch when you successfully connect to PeerServer
conn.on('open', function(){
  // here you have conn.id
  conn.send('hi!');
});


RECEIVE

peer.on('connection', function(conn) {
  conn.on('data', function(data){
    // Will print 'hi!'
    console.log(data);
  });
});



MEDIA CALLS

CALL

var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
getUserMedia({video: true, audio: true}, function(stream) {
  var call = peer.call('another-peers-id', stream);
  call.on('stream', function(remoteStream) {
    // Show stream in some video/canvas element.
  });
}, function(err) {
  console.log('Failed to get local stream' ,err);
});


ANSWER

var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
peer.on('call', function(call) {
  getUserMedia({video: true, audio: true}, function(stream) {
    call.answer(stream); // Answer the call with an A/V stream.
    call.on('stream', function(remoteStream) {
      // Show stream in some video/canvas element.
    });
  }, function(err) {
    console.log('Failed to get local stream' ,err);
  });
});



PEERSERVER

To broker connections, PeerJS connects to a PeerServer. Note that no
peer-to-peer data goes through the server; The server acts only as a connection
broker.

PEERSERVER CLOUD

If you don't want to run your own PeerServer, we offer a free cloud-hosted
version of PeerServer. Official PeerServer!

RUN YOUR OWN

PeerServer is open source and is written in node.js. You can easily run your
own.


QUESTIONS?

Please report any bugs you find on the Github issues page.


Get started!





Cloud hosting powered by OVH.