fix(voice): mark stream as ended (#10455)

* fix: mark stream as ended

refactor: prefer destroying the stream

* refactor: callback for nextTick

test: wait duration ms to check end

chore: eslint

test: end before timeout

---------

Co-authored-by: Almeida <github@almeidx.dev>
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
pat
2025-01-01 07:45:24 +11:00
committed by GitHub
parent a6685a319e
commit bc3a0c8389
2 changed files with 39 additions and 17 deletions

View File

@@ -1,4 +1,5 @@
import type { Buffer } from 'node:buffer';
import { nextTick } from 'node:process';
import { Readable, type ReadableOptions } from 'node:stream';
import { SILENCE_FRAME } from '../audio/AudioPlayer';
@@ -74,6 +75,11 @@ export class AudioReceiveStream extends Readable {
this.renewEndTimeout(this.end);
}
if (buffer === null) {
// null marks EOF for stream
nextTick(() => this.destroy());
}
return super.push(buffer);
}