mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:30:44 +00:00
fix(voice-call): settle cleared tts queue
This commit is contained in:
@@ -103,7 +103,7 @@ describe("MediaStreamHandler TTS queue", () => {
|
||||
started.push("active");
|
||||
await waitForAbort(signal);
|
||||
});
|
||||
void handler.queueTts("stream-1", async () => {
|
||||
const queued = handler.queueTts("stream-1", async () => {
|
||||
queuedRan = true;
|
||||
});
|
||||
|
||||
@@ -112,10 +112,37 @@ describe("MediaStreamHandler TTS queue", () => {
|
||||
|
||||
handler.clearTtsQueue("stream-1");
|
||||
await active;
|
||||
await withTimeout(queued);
|
||||
await flush();
|
||||
|
||||
expect(queuedRan).toBe(false);
|
||||
});
|
||||
|
||||
it("resolves pending queued playback during stream teardown", async () => {
|
||||
const handler = new MediaStreamHandler({
|
||||
transcriptionProvider: createStubSttProvider(),
|
||||
providerConfig: {},
|
||||
});
|
||||
|
||||
let queuedRan = false;
|
||||
const active = handler.queueTts("stream-1", async (signal) => {
|
||||
await waitForAbort(signal);
|
||||
});
|
||||
const queued = handler.queueTts("stream-1", async () => {
|
||||
queuedRan = true;
|
||||
});
|
||||
|
||||
await flush();
|
||||
(
|
||||
handler as unknown as {
|
||||
clearTtsState(streamSid: string): void;
|
||||
}
|
||||
).clearTtsState("stream-1");
|
||||
|
||||
await withTimeout(active);
|
||||
await withTimeout(queued);
|
||||
expect(queuedRan).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("MediaStreamHandler security hardening", () => {
|
||||
|
||||
@@ -561,7 +561,7 @@ export class MediaStreamHandler {
|
||||
*/
|
||||
clearTtsQueue(streamSid: string, _reason = "unspecified"): void {
|
||||
const queue = this.getTtsQueue(streamSid);
|
||||
queue.length = 0;
|
||||
this.resolveQueuedTtsEntries(queue);
|
||||
this.ttsActiveControllers.get(streamSid)?.abort();
|
||||
this.clearAudio(streamSid);
|
||||
}
|
||||
@@ -634,13 +634,21 @@ export class MediaStreamHandler {
|
||||
private clearTtsState(streamSid: string): void {
|
||||
const queue = this.ttsQueues.get(streamSid);
|
||||
if (queue) {
|
||||
queue.length = 0;
|
||||
this.resolveQueuedTtsEntries(queue);
|
||||
}
|
||||
this.ttsActiveControllers.get(streamSid)?.abort();
|
||||
this.ttsActiveControllers.delete(streamSid);
|
||||
this.ttsPlaying.delete(streamSid);
|
||||
this.ttsQueues.delete(streamSid);
|
||||
}
|
||||
|
||||
private resolveQueuedTtsEntries(queue: TtsQueueEntry[]): void {
|
||||
const pending = queue.splice(0);
|
||||
for (const entry of pending) {
|
||||
entry.controller.abort();
|
||||
entry.resolve();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user