【问题标题】:Should empty string icecandidate be added by addicecandidate?addicecandidate 是否应该添加空字符串 icecandidate?
【发布时间】:2020-08-17 10:41:57
【问题描述】:

我的问题是关于 webrtc 协商的。

很多在线教程和MDN中描述的内容存在矛盾。

在 MDN 中,它说 link

在每一代候选人结束时,候选人结束 通知以 RTCIceCandidate 其候选人的形式发送 属性是一个空字符串。该候选人仍应添加到 连接使用 addIceCandidate() 方法,像往常一样,为了 将该通知传递给远程对等方。

当在测试期间完全没有其他候选人时 当前的谈判交换,候选人结束通知是 通过传递候选属性为空的 RTCIceCandidate 发送。 此消息不需要发送到远程对等方。它是 可以通过以下方式检测到的状态的遗留通知 观看 iceGatheringState 更改完成,通过观看 用于 icegatheringstatechange 事件。

但是,在教程here中,他们介绍了以下代码

function handleICECandidateEvent(event) {
  if (event.candidate) {
    sendToServer({
      type: "new-ice-candidate",
      target: targetUsername,
      candidate: event.candidate
    });
  }
}

如果candidate是一个空字符串,它将被评估为falsy并且不会通过sendToServer发送。

更有趣的是,即使在同一篇文章中here

他们有以下示例代码

rtcPeerConnection.onicecandidate = (event) => {
  if (event.candidate) {
    sendCandidateToRemotePeer(event.candidate)
  }
}

但是在这个 sn-p 的正下方,他们说

当 ICE 谈判会议没有候选人可以提议时 一个给定的 RTCIceTransport,它已经完成了一代人的收集 的候选人。 icecandidate 表示已发生这种情况 事件其候选字符串为空 ("")

您应该像任何标准候选人一样将其交付给远程对等方,如上面共享新候选人中所述。这 确保为远程对等方提供候选结束 通知。

实际上,我阅读了许多在线教程,但我从未见过他们处理空字符串候选的任何地方。

【问题讨论】:

    标签: webrtc p2p nat-traversal rtcpeerconnection


    【解决方案1】:

    旧规范不要求发送空候选人,但新规范要求发送和 addIceCandidate() 为空候选人。 由于Chrome还是老规范,空candidate在addIceCandidate()的时候会报错,所以就不发了。

    【讨论】:

    猜你喜欢
    • 2022-01-25
    • 2014-06-16
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    相关资源
    最近更新 更多