最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Webrtc adding ice candidate to remote peer - Stack Overflow

programmeradmin9浏览0评论

Below is the sample webrtc peer to peer connection code from google webrtc tutorilal. this link. I couldn't understand properly ,how addIceCandidate() add its Ice candidate to its remote peer using onIceCandidate(). what does event.candidate means here. 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);
      }
    );

Below is the sample webrtc peer to peer connection code from google webrtc tutorilal. this link. I couldn't understand properly ,how addIceCandidate() add its Ice candidate to its remote peer using onIceCandidate(). what does event.candidate means here. 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);
      }
    );
Share Improve this question asked May 24, 2018 at 7:29 ambach 66ambach 66 1133 silver badges11 bronze badges 1
  • 1 html5rocks./en/tutorials/webrtc/infrastructure explains what an ice candidate is (along with many other concepts needed to understand things) – Philipp Hancke Commented May 24, 2018 at 7:41
Add a ment  | 

1 Answer 1

Reset to default 7

When peer A has discovered an ICE candidate (a potential route which could be used to municate), it needs to send this ICE candidate to peer B (and vice versa). Peer B then adds that ICE candidate to its connection. Both peers exchange ICE candidates this way until they have found the optimal route that both are able to use to municate with each other directly.

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. In practice however you will have to send that ICE candidate using a signalling server; 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.

发布评论

评论列表(0)

  1. 暂无评论