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...
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.
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.
close() The RTCPeerConnection. close() method closes the current peer connection.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With