mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 03:02:20 +00:00
Keep an active voice session through engine switches
The page creates the voice once; each engine attachment only gives it that scene's action runner, pointer canvas and annotation events. Calls made during a switch wait for the incoming engine and are refused with ENGINE_SWITCHING when none attaches in time; results name the engine that answered, and the session hears engine-changed after a switch. The analyst's follow-up memory and layer enable times outlive one engine's runner. scripts/qa-voice-engine-switch.mjs drives a fake microphone and Realtime transport through the switches.
This commit is contained in:
1 parent
35ed499ae4
commit
05578c61b9
13 files changed
+998
-139
No files matched your search
@@ -0,0 +1,117 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createSceneVoice } from './gevRealtime.js';
|
||||
import { createTestVoiceUi } from '../testSupport/voiceUi.mjs';
|
||||
|
||||
function fakeEngine(kind) {
|
||||
const canvas = new EventTarget();
|
||||
canvas.getBoundingClientRect = () => ({ left: 0, top: 0 });
|
||||
return {
|
||||
kind,
|
||||
host: { canvas, size: () => ({ width: 0, height: 0 }) },
|
||||
camera: { pose: () => ({}) },
|
||||
};
|
||||
}
|
||||
|
||||
function fixture() {
|
||||
const previous = globalThis.window;
|
||||
globalThis.window = {};
|
||||
const lifetime = new AbortController();
|
||||
const adapter = { starts: 0, stops: [], events: [] };
|
||||
let runAction;
|
||||
const built = [];
|
||||
const voice = createSceneVoice({
|
||||
signal: lifetime.signal,
|
||||
createControl: () => createTestVoiceUi(),
|
||||
createCard: () => null,
|
||||
createReticle: () => null,
|
||||
createRunner: (scene) => {
|
||||
built.push(scene);
|
||||
return async (name) => ({ ok: true, action: name });
|
||||
},
|
||||
createSession(hooks) {
|
||||
runAction = hooks.runAction;
|
||||
return {
|
||||
async start() {
|
||||
adapter.starts++;
|
||||
hooks.emit({ type: 'state', state: 'listening' });
|
||||
},
|
||||
stop(options) {
|
||||
adapter.stops.push(options);
|
||||
},
|
||||
sendText() {},
|
||||
sendMapEvent(event) {
|
||||
adapter.events.push(event);
|
||||
return true;
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
return {
|
||||
voice,
|
||||
adapter,
|
||||
built,
|
||||
lifetime,
|
||||
run: (...args) => runAction(...args),
|
||||
restore: () => {
|
||||
globalThis.window = previous;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test('an engine switch keeps the voice session and its transport', async () => {
|
||||
const f = fixture();
|
||||
try {
|
||||
const cesium = fakeEngine('cesium');
|
||||
f.voice.attachScene({ engine: cesium, viewer: {} });
|
||||
await f.voice.commands.start();
|
||||
assert.equal(f.adapter.starts, 1);
|
||||
assert.equal(f.voice.commands.pointer.element, cesium.host.canvas);
|
||||
assert.equal((await f.run('set_layer', {})).engine, 'cesium');
|
||||
|
||||
f.voice.detachScene();
|
||||
assert.deepEqual(f.adapter.stops, [], 'a detach never stops the adapter');
|
||||
assert.equal(f.voice.commands.isActive(), true);
|
||||
assert.equal(f.voice.commands.pointer.element, null);
|
||||
// A call made between the engines waits for the next one.
|
||||
const pending = f.run('set_layer', {});
|
||||
const navara = fakeEngine('navara');
|
||||
f.voice.attachScene({ engine: navara, viewer: null });
|
||||
assert.equal((await pending).engine, 'navara');
|
||||
assert.equal(f.voice.commands.pointer.element, navara.host.canvas);
|
||||
assert.deepEqual(f.adapter.events, [
|
||||
{ type: 'engine-changed', engine: 'navara' },
|
||||
]);
|
||||
assert.equal(f.adapter.starts, 1);
|
||||
assert.equal(f.built.length, 2);
|
||||
assert.equal(f.built[1].engine, navara);
|
||||
|
||||
f.lifetime.abort();
|
||||
assert.equal(f.adapter.stops.at(-1)?.removeUi, true);
|
||||
} finally {
|
||||
f.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('annotation outline events reach the session from the attached engine only', async () => {
|
||||
const f = fixture();
|
||||
try {
|
||||
const listeners = new Set();
|
||||
const annotations = {
|
||||
onOutlineEvent(listener) {
|
||||
listeners.add(listener);
|
||||
return () => listeners.delete(listener);
|
||||
},
|
||||
};
|
||||
f.voice.attachScene({ engine: fakeEngine('cesium'), annotations });
|
||||
await f.voice.commands.start();
|
||||
for (const listener of listeners) listener({ status: 'resolved' });
|
||||
assert.deepEqual(f.adapter.events, [
|
||||
{ type: 'map_annotation_outline', status: 'resolved' },
|
||||
]);
|
||||
f.voice.detachScene();
|
||||
assert.equal(listeners.size, 0);
|
||||
} finally {
|
||||
f.restore();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user