Multiple party peer.js application

一曲冷凌霜 提交于 2021-02-09 11:01:27

问题


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 ... :-)


回答1:


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.



来源:https://stackoverflow.com/questions/49213850/multiple-party-peer-js-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!