Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset the webrtc State?

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...

like image 933
zeus Avatar asked Mar 31 '19 17:03

zeus


People also ask

How do I check WebRTC connection?

If you're using Chrome, you can navigate to chrome://webrtc-internals . This will show you the offer, answer, ICE states, and statistics about the connection (once it has been established). Save this answer.

What is ice restart?

Restarting ICE essentially resets ICE so that it creates all new candidates using new credentials. Existing media transmissions continue uninterrupted during this process. For details about how ICE restart works, see ICE restart in Lifetime of a WebRTC session and RFC 5245, section 9.1. 1.1: ICE specification.

How do I close RTCPeerConnection?

close() The RTCPeerConnection. close() method closes the current peer connection.

What is a WebRTC session?

WebRTC Session Controller enables real time communication between web browsers that support it, as well as SIP and public switched telephone network (PSTN) phones. WebRTC Session Controller uses WebRTC (Web Real Time Communication), an API being standardized by the World Wide Web Consortium (W3C).


1 Answers

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 comes 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.

like image 158
jib Avatar answered Oct 06 '22 05:10

jib