diff --git a/.changeset/tame-news-study.md b/.changeset/tame-news-study.md new file mode 100644 index 0000000000..ef3fabf0b9 --- /dev/null +++ b/.changeset/tame-news-study.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Await pending publications with timeout 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'); } }