Skip to content

Commit 0384a6e

Browse files
authored
fix(rtc): error on closed source on captureFrame (#435)
1 parent ad5da0c commit 0384a6e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

.changeset/tender-eggs-explode.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@livekit/rtc-node": patch
3+
---
4+
5+
error on closed source on captureFrame

packages/livekit-rtc/src/audio_source.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export class AudioSource {
3232
promise = this.newPromise();
3333
/** @internal */
3434
timeout?: ReturnType<typeof setTimeout> = undefined;
35+
/** @internal */
36+
closed = false;
3537

3638
sampleRate: number;
3739
numChannels: number;
@@ -101,6 +103,9 @@ export class AudioSource {
101103
}
102104

103105
async captureFrame(frame: AudioFrame) {
106+
if (this.closed) {
107+
throw new Error('AudioSource is closed');
108+
}
104109
const now = Number(process.hrtime.bigint() / BigInt(1000000));
105110
const elapsed = this.lastCapture === 0 ? 0 : now - this.lastCapture;
106111
const frameDurationMs = (frame.samplesPerChannel / frame.sampleRate) * 1000;
@@ -136,5 +141,6 @@ export class AudioSource {
136141

137142
async close() {
138143
this.ffiHandle.dispose();
144+
this.closed = true;
139145
}
140146
}

0 commit comments

Comments
 (0)