[FIX] web_editor: prevent InvalidStateError with stressed webrtc

This prevents a traceback* which happens when the webrtc connection is
under signaling stress and a local rollback is triggered when the state
has been set back to stable.

This seems to be caused by browser bugs (both in
[Firefox](<https://bugzilla.mozilla.org/show_bug.cgi?id=1628139>) and in
[Chromium](<https://issues.chromium.org/issues/40132342>) due to an
[error](<https://github.com/w3c/webrtc-pc/issues/2508>) in the webrtc
spec) that occur under stress. To prevent this sort of issue, a solution
was provided in the form of an [implicit
rollback](<https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/setRemoteDescription#browser_compatibility>)
on the remote description setter. This solution has recently become
available everywhere (since Safari adopted it in
[2022](<https://caniuse.com/mdn-api_rtcpeerconnection_setremotedescription_implicit_rollback>)
for desktop and iOS).

This allows us to simply rely on the remote description setter to handle
the rollback if needed.

* Traceback: InvalidStateError: Cannot rollback local description in
  stable.

task-3823100

closes odoo/odoo#158861

Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
Antoine Guenet
2024-03-25 13:08:01 +00:00
parent 0aae1ae147
commit c1fa1e2391
@@ -127,20 +127,11 @@ const baseNotificationMethods = {
);
return;
}
if (debugShowLog) console.log(`%cisOfferRacing: ${isOfferRacing}`, 'background: red;');
if (isOfferRacing) {
if (debugShowLog)
console.log(`%c SETREMOTEDESCRIPTION 1`, 'background: navy; color:white;');
await Promise.all([
pc.setLocalDescription({ type: 'rollback' }),
pc.setRemoteDescription(description),
]);
} else {
if (debugShowLog)
console.log(`%c SETREMOTEDESCRIPTION 2`, 'background: navy; color:white;');
await pc.setRemoteDescription(description);
if (debugShowLog) {
console.log(`%cisOfferRacing: ${isOfferRacing}`, 'background: red;');
console.log(`%c SETREMOTEDESCRIPTION`, 'background: navy; color:white;');
}
await pc.setRemoteDescription(description);
if (clientInfos.iceCandidateBuffer.length) {
for (const candidate of clientInfos.iceCandidateBuffer) {
await this._addIceCandidate(clientInfos, candidate);