4

I am brand new into PeerJs and WebRTC. I have got a 1:1 NodeJS/PeerJS application working in my remote server and that works great. However now I want to explore extending this to a 1:N model where a host ID can have multiple peers connecting to them and each of the peers can receive every other connected peer's audio/video. I am ok with about 4-5 parties in a call for now so a mesh architecture is fine. In the future I would progress into a Media server based architecture to get more participants in the same session.

Currently in my code if I have more than 2 parties in the call, the last one to join is kicking out the previous party.

Can you please let me know if PeerJS library can support multi-party video chatting (4-5 users is fine) ? If not can you please guide me to how I can enhance my 1:1 app to a 1:N model? I am unable to find any clear direction on the web.

Many thanks in advance ... :-)

John G
  • 55
  • 1
  • 7

2 Answers2

3

Showing some of your code would be helpful in solving your problem. By using clean WebRTC you can achieve conference call, so I think you can also do this in peerJs.

At the beginning of your call you need to call getUserMedia once and get your local stream.

var myStream;
navigator.getUserMedia({video: true, audio: true}, function(stream) {
    myStream = stream;
}, function(err) {
    console.log('Failed to get local stream' ,err);
});

So when you make offer to them, you can write

var call = peer.call('another-peers-id', myStream);
call.on('stream', function(remoteStream) {
    // Show stream in some <video> element.
});

And when peer receives call, it answers with

peer.on('call', function(call) {
    call.answer(myStream); // Answer the call with an A/V stream.
    call.on('stream', function(remoteStream) {
      // Show stream in some <video> element.
    });
});

I hope this helps you to solve your problem.

Velexior
  • 169
  • 2
  • 8
  • peer.on('call', function (call) { var acceptsCall = confirm("Videocall incoming, accept it ?"); if(acceptsCall){ call.answer(window.localStream); call.on('stream', function (stream) { window.peer_stream = stream; onReceiveStream(stream, 'peer-camera'); }); call.on('close', function(){ alert("The videocall has finished"); }); }else{ console.log("Call denied !"); } }); – John G Mar 11 '18 at 05:09
  • function requestLocalVideo(callbacks) { navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; navigator.getUserMedia({ audio: true, video: true }, callbacks.success , callbacks.error); } – John G Mar 11 '18 at 05:11
  • function onReceiveStream(stream, element_id) { var video = document.getElementById(element_id); video.src = window.URL.createObjectURL(stream); window.peer_stream = stream; } – John G Mar 11 '18 at 05:12
  • Thanks @Xarthisius. It seems that I am not able to get more than 2 parties in the call using the core code above. – John G Mar 11 '18 at 05:14
  • 1
    When you receive remote stream you are always using 'peer-camera' as ID and your existing video's src will be replaced by new remote stream and it will only show stream from the last user. Anyway, code I posted in the answer works. Here is link to an example: https://github.com/mluketin/peerjs-helloworld-conference – Velexior Mar 11 '18 at 11:36
  • Thanks a million @Xarthisius. Your code gave me the right guidance and snippets to solve the problem that I was having. I have finally been able to implement multi-party conferencing - Phew! Much appreciate your help and patience. :-) – John G Mar 11 '18 at 22:49
0

am working on peerjs, for one to one, I want to extend it, so I have plan to achive by creating multiple peerjs instance and reseve one instance for each peer in a group call