Skip to content

Commit

Permalink
Await pending publications with timeout (#1324)
Browse files Browse the repository at this point in the history
* Await pending publications with timeout

* Create tame-news-study.md
  • Loading branch information
lukasIO authored Nov 28, 2024
1 parent e511197 commit cc14de4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
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');
}
}

0 comments on commit cc14de4

Please sign in to comment.