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); } };