问题描述
我即将使用webRTC + socket.io + node.js建立一个视频会议系统,所以我已经读过这本书作为Simon Pietro Romano的与webRTC进行实时通信的起点,我已经读完了,我我将在100 Mbps本地网络上运行这个系统,所以我将使用网状网络拓扑,因为带宽在这里不是问题,我不想专注于此,我只是有一个关于与许多用户合作的简单问题,特别是在使用这些函数时:
I am about to build a videoconferencing system using webRTC+socket.io+node.js, so I have read this book as start point "Real Time communications with webRTC" by Simon Pietro Romano, I already finished reading it, I am gonna run this system over a 100 Mbps local network, so I am gonna use the mesh network topology since bandwidth is no an issue here, I don't wanna focus on this, I just have a simple question on working with many users, specifically on using these functions:
var pc // PeerConnection Object
pc.onaddstream = ...//for receiving stream from remote party
pc.setRemoteDescription()...//for setting .sdp file from remote party
我知道我必须在每个对等体上建立点对点连接,但我们假设我有3个用户:A,B和C.
I know I have to make a peer-to-peer connection on each peer, but Let's suppose that I have 3 users: A, B and C.
A将成为房间发起人,然后B加入房间,这里A向B发送报价并收到B的回答,A setRemoteDescription(answe rB)和B setRemoteDescription(offerA),但是当C加入房间时,A和B将成为它的发起者,所以它们都会向C发送报价,而C会向它们发送答案,这是我的困惑:
A is gonna be the room initiator, then B joins the room, here A sends an offer to B and receives an answer from B, A setRemoteDescription(answerB) and B setRemoteDescription(offerA), but when C joins the room, A and B will be its initiators, so both of them will be send offers to C, and C will send answers to them, here is my confusion:
当C首次收到来自A的报价时,这是C setRemoteDescription(offerA),但是当收到来自B的报价时,这是C setRemoteDescription(offerB),我正在设置一个新值在这里丢失之前的A报价,这个程序只是暂时的吗?,C不再需要A报价吗?我知道这个sdp文件只包含webbrowser媒体信息。我对onaddstream有同样的疑问,这个程序是否会自动从一个对等端然后从另一个对等端捕获流?第一个捕获B的流,第二个从C开始,当最后一个加入房间时?在捕获C时,A会丢失B的流吗? ?。
When C first receives offer from A, this is C setRemoteDescription(offerA), but when receiving offer from B, this is C setRemoteDescription(offerB), I am setting a new value here and losing the previous offer from A, is this procedure just temporary?, isn't C going to need the A offer anymore?, I know this sdp file just contains webbrowser media info. I have the same doubt with onaddstream, Does this procedure automatically catch stream from one peer and then from another peer?, A first catch B's stream and second from C when this last one joined the room?, Does A lose B's stream when catching C's?.
另一方面,addIceCandidate只是向每个对等体添加远程候选者,因此本地对等体具有远程对等体路由,它永远不会丢失远程对等体路由,I想想,我是对的吗?
On the other hand, addIceCandidate just adds remote candidates to each peer, so a local peer have the remote peers routes, it never loses the remote peers routes, I think, Am I right?
我找到了关于webRTC视频会议的源代码,我看到onaddstream和setRemoteDescription就像临时函数,一旦设置了对等体之间的连接,那些不再是必要的,我不知道,也许我错了。
I have found source code about webRTC videoconferencing and I have seen that onaddstream and setRemoteDescription are like temporary functions, once the connection between peers is set, those are not neccesary anymore, I don't know, maybe I am wrong.
提前致谢。
推荐答案
你需要有一个对等连接( pc
)在您的客户端,每个其他参与者,你将做类似的事情:
You will need to have a peer connection (pc
) in your client side per each other participant, you will do something similar to:
socket.on('offer', function(from, data) {
users[from].pc.setRemoteDescription(new RTCSessionDescription(data));
// create answer..
});
请注意,节点服务器正在发送商品以及发送商品的用户的ID。此外,用户
将包含每个房间参与者的条目,并引用其 pc
。您将为每个参与者添加远程描述到他们自己的 pc
。
Note that the Node server is sending the offer along with the id of the user who is sending it. Also, users
will contain an entry per room participant with a reference to its pc
. You will be adding the remote description for each participant to their own pc
.
互联网上有很多例子,我正在:)
There are plenty of examples in internet, mine is on http://github.com/jconde/euphony :)
这篇关于WebRTC视频会议(多对多)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!