【问题标题】:WebRTC, how to gather a full set of candidates without ice trickle?WebRTC,如何在没有冰涓涓涓的情况下收集全套候选人?
【发布时间】:2019-05-10 22:56:52
【问题描述】:

我正在尝试在两台电脑之间进行视频通话,但我不想使用 icetrickle,有时我可以进行视频通话,其他时候(我不知道为什么)我无法收集所有的冰候选,iceGatheringState 保持在聚集状态,永远不会完成。

我已经尝试使用事件 onicecandidate 并等待空候选人。 现在我正在使用 onIceGatheringStateChange。

pc=new RTCPeerConnection(iceServers);
pc.onicegatheringstatechange=function(){
  if(pc.iceGatheringState=='complete'){
    send_to_target(pc.localDescription);
  }
}   
localStream.getTracks().forEach(track=>pc.addTrack(track,localStream));
pc.createOffer().then(function(sessionDescription){
  pc.setLocalDescription(sessionDescription);
})

我正在两台带有 chrome 的笔记本电脑上对此进行测试,我希望 iceGatheringState 进入完成状态或知道另一种方式/条件来收集候选冰,以便在不使用冰涓流的情况下将 sessionDescription 发送到目标。

谢谢。

【问题讨论】:

  • 使用小写:pc.onicegatheringstatechange.
  • 抱歉,打错了,问题是一样的,我想知道在发送会话描述之前收集候选冰的方法。我现在的想法是获得“每种预期类型的​​候选人之一”,正如我在 issue 7844 中看到的那样
  • 我放弃了,现在我正在使用 Ice Trickle 并且工作正常,但我仍然不明白为什么没有 Ice Trickle 无法获得 pc.iceGatheringState=='complete'。
  • 这是一个有趣的问题,如果在报价中传输了候选人结束。你在什么浏览器上试过这个?
  • 我只尝试了 Chrome,在一台笔记本电脑上一切都很好,在另一台笔记本电脑上 setLocalDescription 之后,iceGatheringState 是“正在收集”并且不会更改为“完成”,而且我也没有收到候选人 null ,现在有了冰涓涓细流,我收到了空候选人,并且收集状态变为“完成”,我可以指出的唯一区别是一台笔记本电脑有 Windows 7,而另一台笔记本电脑有 Windows 10

标签: javascript webrtc


【解决方案1】:

据我所知,有两种方法可以确定“ICE 候选人聚集”/“ICE Trickle”何时完成。

  1. 您可以通过观察 icegatheringstatechange 事件并检查 iceGatheringState 的值是否等于“完成”来确定 ICE 候选收集已完成。

Code example from MDN

let pc = new RTCPeerConnection();
pc.onicegatheringstatechange = ev => {
  let connection = ev.target;

  switch(connection.iceGatheringState) {
    case "gathering":
      /* collection of candidates has begun */
      break;
    case "complete":
      /* collection of candidates is finished */
      break;
  }
}
  1. 您还可以让 icecandidate 事件的处理程序查看其候选属性是否等于“null”。

Code example from MDN

let pc = new RTCPeerConnection();
pc.onicecandidate = function(event) {
  if (event.candidate) {
    /* Code for each candidate */
    /* Send the candidate to the remote peer */
  } else {
    /* All ICE candidates have been sent */
  }
}

WebRTC 的有用链接:

【讨论】:

    猜你喜欢
    • 2020-06-13
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 2014-07-17
    • 2020-12-08
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    相关资源
    最近更新 更多