From b6a6b540f30985ebb2f5c3a7750eac9ab74fe807 Mon Sep 17 00:00:00 2001 From: lukasIO Date: Thu, 21 Nov 2024 12:14:24 +0100 Subject: [PATCH] Await pending publications with timeout --- src/room/participant/LocalParticipant.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/room/participant/LocalParticipant.ts b/src/room/participant/LocalParticipant.ts index a6916197fb..93049f5e7f 100644 --- a/src/room/participant/LocalParticipant.ts +++ b/src/room/participant/LocalParticipant.ts @@ -2016,11 +2016,18 @@ export default class LocalParticipant extends Participant { } private async waitForPendingPublicationOfSource(source: Track.Source) { - const publishPromiseEntry = Array.from(this.pendingPublishPromises.entries()).find( - ([pendingTrack]) => pendingTrack.source === source, - ); - if (publishPromiseEntry) { - return publishPromiseEntry[1]; + const waitForPendingTimeout = 10_000; + const startTime = Date.now(); + + while (Date.now() < startTime + waitForPendingTimeout) { + const publishPromiseEntry = Array.from(this.pendingPublishPromises.entries()).find( + ([pendingTrack]) => pendingTrack.source === source, + ); + if (publishPromiseEntry) { + return publishPromiseEntry[1]; + } + sleep(20); } + throw new Error('waiting for pending publication promise timed out'); } }