HEL-897: preserve visual author voice session race fixes

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
2026-10-27 02:52:08 +08:00
co-authored by multica-agent
parent f259bd34e1
commit 761a2331f5
6 changed files with 201 additions and 5 deletions
+15 -3
View File
@@ -124,13 +124,25 @@ export class VoiceController {
}
async start(): Promise<void> {
await this.end();
void this.settle();
// The generation is taken before anything is awaited, so a start that wakes up after a newer one never takes
// the call over; the call it replaces is released first, as end() would.
const prev = this.live;
const gen = ++this.gen, live: Live = { gen, abort: new AbortController(), agent: false, stated: false, hushed: false };
this.live = live;
this.view = { ...OFF, phase: 'opening' }; this.deps.onView(this.view);
const stale = () => gen !== this.gen;
const fail = async (notice: string) => { if (stale()) return; this.live = null; this.gen++; await this.teardown(live); this.view = { ...OFF, notice }; this.deps.onView(this.view); };
if (prev) { await this.teardown(prev); this.deps.onRecord(); }
if (stale()) return;
void this.settle();
// Everything a failure says is said while this call still owns the page; its cleanup goes on afterwards and,
// however late it answers, only releases this call's own microphone, room and server room.
const fail = (notice: string) => {
if (stale()) return Promise.resolve();
this.live = null; this.gen++;
const released = this.teardown(live);
this.view = { ...OFF, notice }; this.deps.onView(this.view);
return released;
};
const secure = (this.deps.secure ?? (() => window.isSecureContext && !!navigator.mediaDevices?.getUserMedia))();
if (!secure) return fail(WORDS.insecure);