【问题标题】:Failed to construct 'RTCIceCandidate' cannot convert to dictionary无法构造“RTCIceCandidate”无法转换为字典
【发布时间】:2021-08-14 00:37:52
【问题描述】:

当被呼叫对等方尝试添加从呼叫对等方收到的 ICECandidate 时,我不断收到此消息。

Failed to construct 'RTCIceCandidate': cannot convert to dictionary

这是我包装 ICECandidate 的自定义事件对象。该事件对象是通过信令通道接收的。

这是我的代码,尝试将重构的 ICE Candidate 添加到本地 RTCConnection,这会在其正下方抛出错误。

async function onIceCandidateFromPeer(e) {
    console.log('onIceCandidateFromPeer', e);
    try {
        let candidate = new RTCIceCandidate(e.iceCandidate);
        console.log('Reconstruct ICECandidate from peer sucessful', candidate);
        await app.connection.addIceCandidate(candidate);
        console.log('Add ICE Candidate successful')
    } catch(err) {
        console.log('Add ICE Candidate failed', err)
    }
}
  • 我应该将整个 iceCandidate 对象传递给 RTCIceCandidate 构造函数吗?
  • 我应该只通过iceCandidate.candidate 行吗?
  • 候选描述符行有什么问题导致无法解析吗?

编辑 28/5/2021

我刚刚意识到这个错误只发生在调用者端(即生成“报价”的那个)。它不会发生在接收端(即生成“答案”的一端)。

两个对等点都使用相同的处理程序代码!

我使用 Google Chrome 90.x 作为用户代理。我为提供对等方打开一个常规窗口,并为回答对等方打开另一个隐身窗口。

【问题讨论】:

  • 您能否分享一下您是如何通过套接字发送候选人的,因为通过套接字发送的候选人可能有问题?
  • @KathanPatel,ICE 候选人的描述正常。请参阅上面的屏幕截图。如果这就是你的意思,我不使用普通的 WebSocket 或 socket.io。我使用 Pusher(JS 客户端确实使用 WebSocket)作为信号通道。

标签: webrtc


【解决方案1】:

原来,this 是我的问题。

引用 SO 的回答“这个问题几乎完全没有记录......你不能在不设置远程描述的情况下添加 ICE 候选人......”

致电addIceCandidate()不应发生之前致电setRemoteDescription()

我的解决方案是缓存来自对等方的所有传入 ICE 候选者,并且仅在 RTCPeerConnection.signalingState 变为 have-remote-offer 后添加它们,这应该在设置远程描述后发生。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-22
    • 2018-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    相关资源
    最近更新 更多