Skip to content

Commit 0752be3

Browse files
lukasIOcnderrauber
andauthored
Ensure transport manager is reset before attempting legacy fallback path (#1893)
Co-authored-by: cnderrauber <zengjiestc@gmail.com>
1 parent d85c28f commit 0752be3

5 files changed

Lines changed: 30 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"livekit-client": patch
3+
---
4+
5+
Ensure transport manager is reset before attempting legacy fallback path

examples/demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ <h3>Chat</h3>
310310
class="btn btn-outline-secondary btn-sm"
311311
type="button"
312312
onclick="appActions.cancelChatReceive()"
313-
style="display: none;"
313+
style="display: none"
314314
>
315315
Cancel current receive
316316
</button>

src/room/RTCEngine.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
220220

221221
private shouldFailNext: boolean = false;
222222

223+
private shouldFailOnV1Path: boolean = false;
224+
223225
private regionUrlProvider?: RegionUrlProvider;
224226

225227
private log = log;
@@ -321,9 +323,16 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
321323
offerProto = toProtoSessionDescription(offer.offer, offer.offerId);
322324
}
323325
}
326+
324327
if (abortSignal?.aborted) {
325328
throw ConnectionError.cancelled('Connection aborted');
326329
}
330+
331+
if (!useV0Path && this.shouldFailOnV1Path) {
332+
this.shouldFailOnV1Path = false;
333+
throw ConnectionError.serviceNotFound('Simulated v1 path failure', 'v0-rtc');
334+
}
335+
log.warn('joining signal with ', url);
327336
const joinResponse = await this.client.join(
328337
url,
329338
token,
@@ -383,6 +392,10 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
383392
}
384393
} else if (e.reason === ConnectionErrorReason.ServiceNotFound) {
385394
this.log.warn(`Initial connection failed: ${e.message} – Retrying`);
395+
if (this.pcManager) {
396+
this.pcManager.onStateChange = undefined;
397+
await this.cleanupPeerConnections();
398+
}
386399
return this.join(url, token, opts, abortSignal, true);
387400
}
388401
}
@@ -1860,6 +1873,12 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit
18601873
this.shouldFailNext = true;
18611874
}
18621875

1876+
/* @internal */
1877+
failNextV1Path() {
1878+
// debugging method to fail the next connection attempt for /rtc/v1 to trigger the fallback version
1879+
this.shouldFailOnV1Path = true;
1880+
}
1881+
18631882
private dataChannelsInfo(): DataChannelInfo[] {
18641883
const infos: DataChannelInfo[] = [];
18651884
const getInfo = (dc: RTCDataChannel | undefined, target: SignalTarget) => {

src/room/Room.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,9 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
11371137
// @ts-expect-error function is private
11381138
await this.engine.client.handleOnClose('simulate disconnect');
11391139
break;
1140+
case 'fail-on-v1-path':
1141+
this.engine.failNextV1Path();
1142+
break;
11401143
case 'speaker':
11411144
req = new SimulateScenario({
11421145
scenario: {

src/room/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ export type SimulationScenario =
9292
| 'disconnect-signal-on-resume'
9393
| 'disconnect-signal-on-resume-no-messages'
9494
// instructs the server to send a full reconnect reconnect action to the client
95-
| 'leave-full-reconnect';
95+
| 'leave-full-reconnect'
96+
| 'fail-on-v1-path';
9697

9798
export type LoggerOptions = {
9899
loggerName?: string;

0 commit comments

Comments
 (0)