Skip to content

Commit

Permalink
Await pending publications with timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO committed Nov 21, 2024
1 parent 2e497b6 commit b6a6b54
Showing 1 changed file with 12 additions and 5 deletions.
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 b6a6b54

Please sign in to comment.