将 RTCPeerConnection 的 change connectionState 从 disconnect 改为 new

Change RTCPeerConnection's change connectionState from disconnect to new

我想手动更改连接状态。 考虑以下情况:

第 1 步:P1 创建报价并发送给 P2 - RTCPeerConnection 状态为新

第 2 步: P2 生成应答并发送回 P1 - 建立连接且 RTCPeerConnection 状态稳定

步骤 3: P2 注销。 P1 中的 RTCPeerConnection 状态已断开

第 4 步: P3 现在尝试连接到 P1。 P3 使用相同的报价生成答案(第 1 步,我将其存储在某处)

现在这第 4 步总是失败。我知道我可以创建一个新的连接并创建一个新的报价来连接 P4。但我不想那样做。有什么方法可以将现有的 RTCPeerConnection 置于初始状态?

示例代码:

myconnection = new RTCPeerConnection(configuration);
dataChannel = myconnection.createDataChannel("channel");
dataChannel.onclose = ()=>{
        console.log("data channel is closed");
        console.log(myconnection); //connectionState:disconnected; iceConnectionState: "disconnected"
        console.log(dataChannel); //readyState: "closed"
        
        //I Want to change the connectionState of myconnection here
      }

没有,因为您不应该与多个对等点一起使用对等连接。销毁当前连接并建立新连接。

可能有效的方法是使用 {iceRestart: true} 调用 createOffer,这会向堆栈发出信号以重置某些状态。不过,您可能 运行 遇到错误。

有关将 RTCPeerConnection 从一个点更改为另一个点的一些模式,请参阅 https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/webrtc/protocol/handover.html;l=3?q=handover&sq=&ss=chromium

TL;DR:有点用,但您必须生成新报价,不能重复使用已存储的报价。