Ensure transport manager is reset before attempting legacy fallback path (#1893)

Co-authored-by: cnderrauber <zengjiestc@gmail.com>
This commit is contained in:
lukasIO
2026-04-17 10:10:08 +02:00
committed by GitHub
parent d85c28fb0c
commit 0752be3c50
5 changed files with 30 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"livekit-client": patch
---
Ensure transport manager is reset before attempting legacy fallback path

View File

@@ -310,7 +310,7 @@
class="btn btn-outline-secondary btn-sm"
type="button"
onclick="appActions.cancelChatReceive()"
style="display: none;"
style="display: none"
>
Cancel current receive
</button>

View File

@@ -220,6 +220,8 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
private shouldFailNext: boolean = false;
private shouldFailOnV1Path: boolean = false;
private regionUrlProvider?: RegionUrlProvider;
private log = log;
@@ -321,9 +323,16 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
offerProto = toProtoSessionDescription(offer.offer, offer.offerId);
}
}
if (abortSignal?.aborted) {
throw ConnectionError.cancelled('Connection aborted');
}
if (!useV0Path && this.shouldFailOnV1Path) {
this.shouldFailOnV1Path = false;
throw ConnectionError.serviceNotFound('Simulated v1 path failure', 'v0-rtc');
}
log.warn('joining signal with ', url);
const joinResponse = await this.client.join(
url,
token,
@@ -383,6 +392,10 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
}
} else if (e.reason === ConnectionErrorReason.ServiceNotFound) {
this.log.warn(`Initial connection failed: ${e.message} Retrying`);
if (this.pcManager) {
this.pcManager.onStateChange = undefined;
await this.cleanupPeerConnections();
}
return this.join(url, token, opts, abortSignal, true);
}
}
@@ -1860,6 +1873,12 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
this.shouldFailNext = true;
}
/* @internal */
failNextV1Path() {
// debugging method to fail the next connection attempt for /rtc/v1 to trigger the fallback version
this.shouldFailOnV1Path = true;
}
private dataChannelsInfo(): DataChannelInfo[] {
const infos: DataChannelInfo[] = [];
const getInfo = (dc: RTCDataChannel | undefined, target: SignalTarget) => {

View File

@@ -1137,6 +1137,9 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
// @ts-expect-error function is private
await this.engine.client.handleOnClose('simulate disconnect');
break;
case 'fail-on-v1-path':
this.engine.failNextV1Path();
break;
case 'speaker':
req = new SimulateScenario({
scenario: {

View File

@@ -92,7 +92,8 @@ export type SimulationScenario =
| 'disconnect-signal-on-resume'
| 'disconnect-signal-on-resume-no-messages'
// instructs the server to send a full reconnect reconnect action to the client
| 'leave-full-reconnect';
| 'leave-full-reconnect'
| 'fail-on-v1-path';
export type LoggerOptions = {
loggerName?: string;