Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Await pending publications with timeout #1324

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tame-news-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Await pending publications with timeout
17 changes: 12 additions & 5 deletions src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Loading