构建失败 'RTCIceCandidate' 无法转换为字典

Failed to construct 'RTCIceCandidate' cannot convert to dictionary

当被叫对等方尝试添加从主叫对等方收到的 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)
    }
}

编辑 28/5/2021

我刚刚意识到这个错误只发生在调用端(即生成 'offer' 的那个)。它不会发生在接收端(即生成 'answer' 的端)。

两个对等方使用完全相同的处理程序代码!

我正在使用 Google Chrome 90.x 作为用户代理。我打开一个常规 window 作为 Offering peer,另一个 incognito window 作为 Answering peer。

原来,是我的问题。

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

调用 addIceCandidate() 不应该 发生 调用 setRemoteDescription()

之前

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