最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to reset the webrtc State? - Stack Overflow

programmeradmin3浏览0评论

I have a problem, sometime I need to reset the WebRTC state (for example I sometimes receive this error:

Failed to set remote offer sdp: Called in wrong state: kHaveLocalOffer

But is it possible to do so without dropping and creating a new RTCPeerConnection object? I do not want to stop the current local video capture...

I have a problem, sometime I need to reset the WebRTC state (for example I sometimes receive this error:

Failed to set remote offer sdp: Called in wrong state: kHaveLocalOffer

But is it possible to do so without dropping and creating a new RTCPeerConnection object? I do not want to stop the current local video capture...

Share Improve this question edited Apr 1, 2019 at 13:23 jib 42.6k17 gold badges108 silver badges165 bronze badges asked Mar 31, 2019 at 17:07 zeuszeus 13.1k18 gold badges87 silver badges239 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

But is it possible to do so without dropping and creating a new RTCPeerConnection object?

Yes, it's called "rollback":

(async () => {
  try {
    const pc1 = new RTCPeerConnection(), pc2 = new RTCPeerConnection();
    pc1.createDataChannel("dummy");
    const offer1 = await pc1.createOffer();

    // Say a remote offer es in we're not ready for (most observable difference)
    const offer2 = await pc2.createOffer({offerToReceiveAudio: true,
                                          offerToReceiveVideo: true});
    await pc1.setRemoteDescription(offer2);
    console.log(pc1.getTransceivers().length); // 2

    await pc1.setRemoteDescription({type: "rollback"}); // <---

    await pc1.setLocalDescription(offer1);
    console.log(pc1.getTransceivers().length); // 0
  } catch(e) {
    console.log(e);
  }
})();

Unfortunately, Chrome does not implement "rollback" yet, but it works in Firefox. Chrome says:

TypeError: Failed to execute 'setRemoteDescription' on 'RTCPeerConnection': The
provided value 'rollback' is not a valid enum value of type RTCSdpType.

Please ★ this bug to urge Chrome to fix it.

check your offer object's type:"offer"

发布评论

评论列表(0)

  1. 暂无评论