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