多方 peer.js 应用程序 [英] Multiple party peer.js application

查看:22
本文介绍了多方 peer.js 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 PeerJs 和 WebRTC 的新手.我有一个 1:1 NodeJS/PeerJS 应用程序在我的远程服务器上运行,效果很好.但是,现在我想探索将其扩展到 1:N 模型,其中主机 ID 可以有多个对等点连接到它们,并且每个对等点都可以接收其他所有连接的对等点的音频/视频.我现在可以接受大约 4-5 方的通话,因此网状架构很好.将来,我将进入基于媒体服务器的架构,以便在同一会话中吸引更多参与者.

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.

目前在我的代码中,如果我有超过 2 个通话方,最后一个加入是踢出前一个方.

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.

能否请您告诉我 PeerJS 库是否可以支持多方视频聊天(4-5 个用户可以)?如果不能,请指导我如何将我的 1:1 应用程序增强为 1:N 模型?我在网上找不到任何明确的方向.

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

推荐答案

显示您的一些代码将有助于解决您的问题.通过使用干净的 WebRTC,你可以实现电话会议,所以我认为你也可以在 peerJs 中做到这一点.

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.

在通话开始时,您需要调用 getUserMedia 一次并获取本地流.

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

当peer收到电话时,它会回复

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.

这篇关于多方 peer.js 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆