Skip to content

Commit

Permalink
Add reconnect when InvalidStateError happens
Browse files Browse the repository at this point in the history
  • Loading branch information
HermanBilous committed Mar 5, 2024
1 parent 8b828b6 commit 1c03c24
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/room/RTCEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -456,6 +462,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
...this.logContext,
RTCSdpType: sd.type,
});
tryHandleInvalidStateError(error, ReconnectReason.RR_PUBLISHER_FAILED);
}
};

Expand All @@ -471,6 +478,7 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
candidate,
target,
});
tryHandleInvalidStateError(error, ReconnectReason.RR_PUBLISHER_FAILED);
});
};

Expand All @@ -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);
}
};

Expand Down

0 comments on commit 1c03c24

Please sign in to comment.