Abdul Jabbar
Abdul Jabbar

Reputation: 124

I want to implement peer to peer video call in nodejs using webrtc

i want to call a route and then that route will open in browse and starts transmitting video stream . i used getUserMedia api .

Upvotes: 0

Views: 2405

Answers (2)

user10097670
user10097670

Reputation:

include this in your library

<script src="https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.9/peer.min.js"></script>

make a peer

var peer = new Peer(); 

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);
  });
});

so now for calls you should be fine with

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);
});

and for 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);
  });
});

I hope this helps you, btw you can use Kurento Media Server https://github.com/ESTOS/kurento-media-server

Upvotes: 1

Abdul Jabbar
Abdul Jabbar

Reputation: 414

You can use Kurento Media Server. That's the best opensource media server available. I've worked with it and implemented live peer to peer call.

It provide wide variety of pre-built tutorials. e.g.

  • One-to-One Call
  • One-to-Many Call
  • Adding filters while video chat

Further, it provides different flavours in Java, Javascript and NodeJS.

You can see the detailed documentation here

Upvotes: 1

Related Questions