简体   繁体   English

Webrtc将冰候选者添加到远程同伴

[英]Webrtc adding ice candidate to remote peer

Below is the sample webrtc peer to peer connection code from google webrtc tutorilal. 以下是来自google webrtc tutorilal的示例webrtc点对点连接代码。 this link. 这个链接。 I couldn't understand properly ,how addIceCandidate() add its Ice candidate to its remote peer using onIceCandidate(). 我无法理解,addIceCandidate()如何使用onIceCandidate()将其Ice候选添加到其远程对等体。 what does event.candidate means here. event.candidate在这里意味着什么。 A clear explanation would be appreciated 明确的解释将不胜感激

function onIceCandidate(pc, event) {   //pc1.onicecandidate
  if (event.candidate) {
    getOtherPc(pc).addIceCandidate(
      new RTCIceCandidate(event.candidate)
    ).then(
      function() {
        onAddIceCandidateSuccess(pc);
      },
      function(err) {
        onAddIceCandidateError(pc, err);
      }
    );

When peer A has discovered an ICE candidate (a potential route which could be used to communicate), it needs to send this ICE candidate to peer B (and vice versa). 当对等体A发现了ICE候选者(可以用于通信的潜在路由)时,它需要将该ICE候选者发送给对等体B(反之亦然)。 Peer B then adds that ICE candidate to its connection. 然后,同伴B将ICE候选添加到其连接中。 Both peers exchange ICE candidates this way until they have found the optimal route that both are able to use to communicate with each other directly. 两个对等体都以这种方式交换ICE候选者,直到他们找到了两个能够用来直接相互通信的最佳路由。

In that simple sample, peer A and B seem to be in the same machine, so the (dummy) getOtherPc function can get a handle of "the other peer" and you can directly use its addIceCandidate method. 在该简单示例中,对等体A和B似乎在同一台机器中,因此(虚拟) getOtherPc函数可以获得“另一个对等体”的句柄,并且您可以直接使用其addIceCandidate方法。 In practice however you will have to send that ICE candidate using a signalling server ; 但实际上,您必须使用信令服务器发送ICE候选者; some other way in which the peer can exchange the information across a network. 对等方可以通过网络交换信息的其他方式。 Typically that signalling server will use a websocket connection via which information can be relayed in near-realtime. 通常,该信令服务器将使用websocket连接,通过该连接可以近乎实时地中继信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM