Skip to content

Commit

Permalink
use normal promises
Browse files Browse the repository at this point in the history
  • Loading branch information
nbsp committed Sep 19, 2024
1 parent 66ec836 commit b66e488
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 1 addition & 2 deletions examples/publish-wav/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ while (written < dataSize) {
Math.trunc(frameSize / channels),
);
await source.captureFrame(frame);
await source.waitForPlayout();

written += frameSize;
}
await source.waitForPlayout();

await room.disconnect();
await dispose();
10 changes: 7 additions & 3 deletions packages/livekit-rtc/src/audio_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class AudioSource {
currentQueueSize: number;
/** @internal */
release = () => {};
waitForPlayout = this.newPromise();
promise = this.newPromise();
/** @internal */
timeout?: ReturnType<typeof setTimeout> = undefined;

Expand Down Expand Up @@ -89,10 +89,14 @@ export class AudioSource {
async newPromise() {
return new Promise<void>((resolve) => {
this.release = resolve;
}).then(() => {
});
}

async waitForPlayout() {
return this.promise.then(() => {
this.lastCapture = 0;
this.currentQueueSize = 0;
this.waitForPlayout = this.newPromise();
this.promise = this.newPromise();
});
}

Expand Down

0 comments on commit b66e488

Please sign in to comment.