[FIX] web_editor: prevent visible traceback from non-blocking RTC error

__Current behavior before commit:__
Sometimes the following tracebacks are popping up when an RTC connection
is being established between two users trying to edit the same document.
```log
InvalidStateError: Failed to execute 'setLocalDescription' on
'RTCPeerConnection': Called in wrong signalingState: stable
```

```log
InvalidStateError: Failed to execute 'setRemoteDescription' on
'RTCPeerConnection': Called in wrong signalingState: stable
```

__Description of the fix:__
These errors are not blocking and don't impact the successful ensuing
RTC connection. Thus, we can just catch the error and log it in the
console instead of showing it to the user.

__Steps to reproduce the issue (in 17):__
- Go to a knowledge article
- Open a new tab and open the same article
- On this new tab, quit the article and come back multiple times

Eventually a traceback will appear on one of the tab.
Note that this error seems to occur very randomly. It is similar to the
one dealt by [this commit][1] and it is probably due to a similar cause
i.e. a browser bug when the RTC connection is under stress.

It is however possible to trigger it in a more consistent way by calling
[_createClient][2] repeatedly.

opw-3778272

[1]: https://github.com/odoo/odoo/pull/158861/commits/0eca324
[2]: https://github.com/odoo/odoo/blob/a1afcc8/addons/web_editor/static/src/js/wysiwyg/PeerToPeer.js#L374

closes odoo/odoo#162709

X-original-commit: 034d45b6cde6d818755128778fdcf99dd9ff1254
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
Signed-off-by: Julien Launois (jula) <jula@odoo.com>
This commit is contained in:
Julien (jula)
2024-04-22 10:12:55 +00:00
parent f06da8b3c1
commit cf0743a679
@@ -131,7 +131,16 @@ const baseNotificationMethods = {
console.log(`%cisOfferRacing: ${isOfferRacing}`, 'background: red;');
console.log(`%c SETREMOTEDESCRIPTION`, 'background: navy; color:white;');
}
await pc.setRemoteDescription(description);
try {
await pc.setRemoteDescription(description);
} catch (e) {
if (e instanceof DOMException && e.name === 'InvalidStateError') {
console.error(e);
return;
} else {
throw e;
}
}
if (clientInfos.iceCandidateBuffer.length) {
for (const candidate of clientInfos.iceCandidateBuffer) {
await this._addIceCandidate(clientInfos, candidate);
@@ -140,7 +149,16 @@ const baseNotificationMethods = {
}
if (description.type === 'offer') {
const answerDescription = await pc.createAnswer();
await pc.setLocalDescription(answerDescription);
try {
await pc.setLocalDescription(answerDescription);
} catch (e) {
if (e instanceof DOMException && e.name === 'InvalidStateError') {
console.error(e);
return;
} else {
throw e;
}
}
this.notifyClient(
notification.fromClientId,
'rtc_signal_description',