diff --git a/examples/publish-wav/index.ts b/examples/publish-wav/index.ts index 3db75df4..56722969 100644 --- a/examples/publish-wav/index.ts +++ b/examples/publish-wav/index.ts @@ -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(); diff --git a/packages/livekit-rtc/src/audio_source.ts b/packages/livekit-rtc/src/audio_source.ts index 33224f22..9df75d7a 100644 --- a/packages/livekit-rtc/src/audio_source.ts +++ b/packages/livekit-rtc/src/audio_source.ts @@ -29,7 +29,8 @@ export class AudioSource { /** @internal */ currentQueueSize: number; /** @internal */ - releaseQueue = new Queue(); + release = () => {}; + promise = this.newPromise(); /** @internal */ timeout?: ReturnType = undefined; @@ -82,13 +83,21 @@ export class AudioSource { }, }); - this.releaseQueue.put(); + this.release(); + } + + /** @internal */ + async newPromise() { + return new Promise((resolve) => { + this.release = resolve; + }); } async waitForPlayout() { - await this.releaseQueue.get().then(() => { + return this.promise.then(() => { this.lastCapture = 0; this.currentQueueSize = 0; + this.promise = this.newPromise(); }); } @@ -105,7 +114,7 @@ export class AudioSource { // remove 50ms to account for processing time // (e.g. using wait_for_playout for very small chunks) - this.timeout = setTimeout(this.releaseQueue.put, this.currentQueueSize - 50); + this.timeout = setTimeout(this.release, this.currentQueueSize - 50); const req = new CaptureAudioFrameRequest({ sourceHandle: this.ffiHandle.handle, diff --git a/packages/livekit-rtc/src/index.ts b/packages/livekit-rtc/src/index.ts index 45e23bd1..efffac47 100644 --- a/packages/livekit-rtc/src/index.ts +++ b/packages/livekit-rtc/src/index.ts @@ -40,4 +40,5 @@ export { export { EncryptionType, EncryptionState } from './proto/e2ee_pb.js'; export { StreamState, TrackKind, TrackSource } from './proto/track_pb.js'; export { VideoBufferType, VideoRotation } from './proto/video_frame_pb.js'; +export { ParticipantKind } from './proto/participant_pb.js'; export { dispose } from './ffi_client.js'; diff --git a/packages/livekit-rtc/src/participant.ts b/packages/livekit-rtc/src/participant.ts index 73bbee54..63e24266 100644 --- a/packages/livekit-rtc/src/participant.ts +++ b/packages/livekit-rtc/src/participant.ts @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: Apache-2.0 import { FfiClient, FfiHandle } from './ffi_client.js'; -import type { OwnedParticipant, ParticipantInfo } from './proto/participant_pb.js'; +import type { OwnedParticipant, ParticipantInfo, ParticipantKind } from './proto/participant_pb.js'; import type { PublishDataCallback, PublishDataResponse, @@ -71,6 +71,10 @@ export abstract class Participant { get attributes(): Record { return this.info.attributes; } + + get kind(): ParticipantKind { + return this.info.kind; + } } export type DataPublishOptions = {