From 1c03c249b028a5d2e474e14ec765816f070fbdf9 Mon Sep 17 00:00:00 2001 From: Herman Bilous Date: Tue, 5 Mar 2024 19:05:18 +0200 Subject: [PATCH] Add reconnect when InvalidStateError happens --- src/room/RTCEngine.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/room/RTCEngine.ts b/src/room/RTCEngine.ts index 6c54ff4d90..3368e00b3b 100644 --- a/src/room/RTCEngine.ts +++ b/src/room/RTCEngine.ts @@ -441,6 +441,12 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit } private setupSignalClientCallbacks() { + const tryHandleInvalidStateError = (error: unknown, disconnectReason: ReconnectReason) => { + if (error instanceof DOMException && error.name === 'InvalidStateError') { + this.fullReconnectOnNext = true; + this.handleDisconnect('peerconnection failed', disconnectReason); + } + } // configure signaling client this.client.onAnswer = async (sd) => { if (!this.pcManager) { @@ -456,6 +462,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit ...this.logContext, RTCSdpType: sd.type, }); + tryHandleInvalidStateError(error, ReconnectReason.RR_PUBLISHER_FAILED); } }; @@ -471,6 +478,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit candidate, target, }); + tryHandleInvalidStateError(error, ReconnectReason.RR_PUBLISHER_FAILED); }); }; @@ -488,6 +496,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit log.error(`failed to createSubscriberAnswerFromOffer: ${errorMessage}`, { ...this.logContext, }); + tryHandleInvalidStateError(error, ReconnectReason.RR_PUBLISHER_FAILED); } };