mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Fix Stories navigation, sharing, and voice entry
This commit is contained in:
1 parent
5418438339
commit
9e9ce1db22
43 files changed
+744
-137
No files matched your search
+21
-2
@@ -21,6 +21,7 @@ import { createLibraryBrowser } from '../ui/libraryBrowser.js';
|
||||
import { useDataLibraryStore } from '../ui/stores/dataLibrary.js';
|
||||
import { localGeoJsonServices } from './localGeojsonServices.js';
|
||||
import { initGevVoiceCommands } from '../voice/gevRealtime.js';
|
||||
import { isStoriesOpen } from '../voice/realtimeInputPolicy.js';
|
||||
import { installViews, isEmbeddedInline } from './embed.js';
|
||||
import {
|
||||
installScopeMask,
|
||||
@@ -81,12 +82,23 @@ export function createApplicationTools({
|
||||
onSceneDirector?.(sceneDirector);
|
||||
// Stories: GEV scenes on this globe, from a Stories button. Its screens,
|
||||
// styles, story data and controller load on first use.
|
||||
const storiesStore = useStoriesStore(applicationPinia());
|
||||
let voiceCommands;
|
||||
const stories = bootStories({
|
||||
// Inline in a host page, the URL and history are the host's.
|
||||
available: !isEmbeddedInline(),
|
||||
viewer,
|
||||
director: sceneDirector,
|
||||
store: useStoriesStore(applicationPinia()),
|
||||
store: storiesStore,
|
||||
onEnter: () => {
|
||||
const session = voiceCommands?.session;
|
||||
// A typed command can finish its reply without keeping a microphone on.
|
||||
if (!session || session.adapter.getStartOptions?.().textOnly) return;
|
||||
const wasActive = session.isActive();
|
||||
session.stop();
|
||||
if (wasActive)
|
||||
storiesStore.flashToast(t('Voice is disabled in Stories.'), 4000);
|
||||
},
|
||||
onLoadFailed: () =>
|
||||
styleManager._showToast?.(
|
||||
t('Stories could not load. Check the connection and try again.'),
|
||||
@@ -299,8 +311,15 @@ export function createApplicationTools({
|
||||
defer(() => {
|
||||
if (window.__godsEyeView === debug) delete window.__godsEyeView;
|
||||
});
|
||||
const voiceCommands = initGevVoiceCommands({
|
||||
voiceCommands = initGevVoiceCommands({
|
||||
...voice,
|
||||
canStartVoice: () => !isStoriesOpen(),
|
||||
openStories: storiesStore.available
|
||||
? ({ isCurrent }) =>
|
||||
storiesStore.mode === 'closed'
|
||||
? stories.open({ isCurrent })
|
||||
: 'already-open'
|
||||
: null,
|
||||
floorServices: operations.surface.groundFloor,
|
||||
annotationResolver: operations.annotationResolver,
|
||||
searchNavigation: operations.searchAndFlyTo,
|
||||
|
||||
@@ -991,6 +991,7 @@ test('the voice TOOL SCHEMA matches the pinned contract — the mission mapping
|
||||
'find_imagery',
|
||||
'osm_query',
|
||||
'show_street_level',
|
||||
'open_stories',
|
||||
].includes(tool.name),
|
||||
);
|
||||
const hudLayout = legacyTools.find((tool) => tool.name === 'set_hud')
|
||||
|
||||
@@ -205,6 +205,7 @@
|
||||
"Hold Space to talk": "اضغط مطولًا على Space للتحدث",
|
||||
"Release Space to send": "حرّر Space للإرسال",
|
||||
"Ask or command": "اسأل أو أصدر أمرًا",
|
||||
"Voice is disabled in Stories.": "التحكم الصوتي معطّل في القصص.",
|
||||
"Voice off": "الصوت متوقف",
|
||||
"Running command": "جارٍ تنفيذ الأمر",
|
||||
"Radio did not start": "لم يبدأ الراديو",
|
||||
|
||||
@@ -784,6 +784,7 @@
|
||||
"Requesting microphone": "Mikrofonzugriff wird angefordert",
|
||||
"Ask or command": "Fragen oder Befehl geben",
|
||||
"Running command": "Befehl läuft",
|
||||
"Voice is disabled in Stories.": "Die Sprachsteuerung ist in Stories deaktiviert.",
|
||||
"Voice off": "Sprache aus",
|
||||
"WebRTC microphone support unavailable": "WebRTC-Mikrofonunterstützung nicht verfügbar",
|
||||
"VOICE UNAVAILABLE": "SPRACHE N. V.",
|
||||
|
||||
@@ -968,6 +968,7 @@
|
||||
"Hold Space to talk": "Mantén Space y habla",
|
||||
"Release Space to send": "Suelta Space para enviar",
|
||||
"Ask or command": "Pregunta o ordena",
|
||||
"Voice is disabled in Stories.": "El control por voz está desactivado en Historias.",
|
||||
"Voice off": "Voz desactivada",
|
||||
"Running command": "Ejecutando comando",
|
||||
"Radio did not start": "La radio no se inició",
|
||||
|
||||
@@ -2526,6 +2526,7 @@
|
||||
"Gemini voice is not connected": "La voix Gemini n'est pas connectée",
|
||||
"Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "La saisie interrompue de Gemini a dépassé sa limite de tampon ou d'attente. Relancez la voix.",
|
||||
"Gemini Live connection is expiring. Start voice again for a new conversation.": "La connexion à Gemini Live expire. Relancez la voix pour une nouvelle conversation.",
|
||||
"Voice is disabled in Stories.": "La commande vocale est désactivée dans les Stories.",
|
||||
"Voice off": "Voix désactivée",
|
||||
"Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "Les sessions vocales Gemini sont limitées dans le temps. Quand une session expire, relancez la voix pour une nouvelle conversation.",
|
||||
"Stopped by voice": "Arrêté par la voix",
|
||||
|
||||
@@ -2862,6 +2862,7 @@
|
||||
"Gemini voice is not connected": "הקול של Gemini אינו מחובר",
|
||||
"Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "הקלט שהופסק של Gemini חרג מהחוצץ או ממגבלת ההמתנה. הפעל את הקול שוב.",
|
||||
"Gemini Live connection is expiring. Start voice again for a new conversation.": "חיבור Gemini Live עומד לפוג. הפעל את הקול שוב לשיחה חדשה.",
|
||||
"Voice is disabled in Stories.": "השליטה הקולית מושבתת בסיפורים.",
|
||||
"Voice off": "הקול כבוי",
|
||||
"Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "הפעלות הקול של Gemini מוגבלות בזמן. כשההפעלה פגה, הפעל את הקול שוב לשיחה חדשה.",
|
||||
"Stopped by voice": "נעצר בקול",
|
||||
|
||||
@@ -2526,6 +2526,7 @@
|
||||
"Gemini voice is not connected": "La voce Gemini non è connessa",
|
||||
"Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "L'input interrotto di Gemini ha superato il limite di buffer o di attesa. Riavvia la voce.",
|
||||
"Gemini Live connection is expiring. Start voice again for a new conversation.": "La connessione a Gemini Live sta scadendo. Riavvia la voce per una nuova conversazione.",
|
||||
"Voice is disabled in Stories.": "Il controllo vocale è disattivato nelle Storie.",
|
||||
"Voice off": "Voce disattivata",
|
||||
"Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "Le sessioni vocali Gemini hanno un limite di tempo. Quando una sessione scade, riavvia la voce per una nuova conversazione.",
|
||||
"Stopped by voice": "Fermato dalla voce",
|
||||
|
||||
@@ -2426,6 +2426,7 @@
|
||||
"Gemini voice is not connected": "Gemini音声が接続されていません",
|
||||
"Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "Geminiの中断された入力がバッファーまたは待機の上限を超えました。音声をもう一度開始してください。",
|
||||
"Gemini Live connection is expiring. Start voice again for a new conversation.": "Gemini Liveの接続がまもなく期限切れです。新しい会話を始めるには、音声をもう一度開始してください。",
|
||||
"Voice is disabled in Stories.": "ストーリーでは音声操作が無効になります。",
|
||||
"Voice off": "音声 オフ",
|
||||
"Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "Gemini音声のセッションには時間制限があります。セッションが期限切れになったら、音声をもう一度開始して新しい会話を始めてください。",
|
||||
"Stopped by voice": "音声で停止しました",
|
||||
|
||||
@@ -2526,6 +2526,7 @@
|
||||
"Gemini voice is not connected": "A voz do Gemini não está conectada",
|
||||
"Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "A entrada interrompida do Gemini excedeu o limite de buffer ou de espera. Inicie a voz de novo.",
|
||||
"Gemini Live connection is expiring. Start voice again for a new conversation.": "A conexão com o Gemini Live vai expirar. Inicie a voz de novo para uma nova conversa.",
|
||||
"Voice is disabled in Stories.": "O controle por voz está desativado nas Histórias.",
|
||||
"Voice off": "Voz desligada",
|
||||
"Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "As sessões de voz do Gemini têm limite de tempo. Quando uma sessão expirar, inicie a voz de novo para uma nova conversa.",
|
||||
"Stopped by voice": "Parado por voz",
|
||||
|
||||
@@ -1024,6 +1024,7 @@
|
||||
"Ask or command": "Спросите или дайте команду",
|
||||
"WebRTC microphone support unavailable": "Поддержка микрофона WebRTC недоступна",
|
||||
"Requesting microphone": "Запрос доступа к микрофону",
|
||||
"Voice is disabled in Stories.": "Голосовое управление в историях отключено.",
|
||||
"Voice off": "Голос выключен",
|
||||
"VOICE UNAVAILABLE": "ГОЛОС НЕДОСТУПЕН",
|
||||
"VOICE ACTIVE": "ГОЛОС АКТИВЕН",
|
||||
|
||||
@@ -740,6 +740,7 @@
|
||||
"Requesting microphone": "Begär åtkomst till mikrofonen",
|
||||
"Ask or command": "Fråga eller ge ett kommando",
|
||||
"Running command": "Kör kommando",
|
||||
"Voice is disabled in Stories.": "Röststyrning är avstängd i Stories.",
|
||||
"Voice off": "Röst av",
|
||||
"WebRTC microphone support unavailable": "Mikrofonstöd för WebRTC saknas",
|
||||
"VOICE UNAVAILABLE": "RÖST OTILLGÄNGLIG",
|
||||
|
||||
@@ -2575,6 +2575,7 @@
|
||||
"Gemini voice is not connected": "Голосовий режим Gemini не підключено",
|
||||
"Gemini interrupted input exceeded its buffer or wait limit. Start voice again.": "Перерване введення Gemini перевищило ліміт буфера або очікування. Запустіть голосовий режим знову.",
|
||||
"Gemini Live connection is expiring. Start voice again for a new conversation.": "Термін дії зʼєднання з Gemini Live спливає. Запустіть голосовий режим знову для нової розмови.",
|
||||
"Voice is disabled in Stories.": "Голосове керування в історіях вимкнено.",
|
||||
"Voice off": "Голос вимкнено",
|
||||
"Gemini voice sessions have a time limit. When a session expires, start voice again for a new conversation.": "Тривалість голосових сеансів Gemini обмежена. Коли сеанс завершиться, запустіть голосовий режим знову для нової розмови.",
|
||||
"Stopped by voice": "Зупинено голосовою командою",
|
||||
|
||||
@@ -2332,6 +2332,7 @@
|
||||
"Release Space to send": "松开空格键发送",
|
||||
"Hold Space to talk": "按住空格键说话",
|
||||
"Ask or command": "提问或下达指令",
|
||||
"Voice is disabled in Stories.": "故事模式下语音控制已禁用。",
|
||||
"Voice off": "语音已关闭",
|
||||
"VOICE UNAVAILABLE": "语音不可用",
|
||||
"VOICE ACTIVE": "语音已启用",
|
||||
|
||||
@@ -2322,6 +2322,7 @@
|
||||
"Release Space to send": "鬆開空格鍵發送",
|
||||
"Hold Space to talk": "按住空格鍵說話",
|
||||
"Ask or command": "提問或下達指令",
|
||||
"Voice is disabled in Stories.": "故事模式下語音控制已停用。",
|
||||
"Voice off": "語音已關閉",
|
||||
"VOICE UNAVAILABLE": "語音不可用",
|
||||
"VOICE ACTIVE": "語音已啟用",
|
||||
|
||||
@@ -25,15 +25,16 @@ const css = readStylesheet(new URL('../style.css', import.meta.url));
|
||||
|
||||
function realtimeTools() { return GEV_REALTIME_TOOLS; }
|
||||
|
||||
test('Realtime schema exposes the authoritative 35-tool inventory', () => {
|
||||
test('Realtime schema exposes the authoritative 36-tool inventory', () => {
|
||||
const tools = realtimeTools();
|
||||
assert.equal(tools.length, 35);
|
||||
assert.equal(tools.length, 36);
|
||||
const names = tools.map((tool) => tool.name);
|
||||
assert.equal(new Set(names).size, 35, 'tool names are unique');
|
||||
assert.equal(new Set(names).size, 36, 'tool names are unique');
|
||||
assert.ok(names.includes('resolve_area'));
|
||||
assert.ok(names.includes('find_imagery'));
|
||||
assert.ok(names.includes('osm_query'));
|
||||
assert.ok(names.includes('show_street_level'));
|
||||
assert.ok(names.includes('open_stories'));
|
||||
assert.ok(names.includes('set_context_mode'));
|
||||
assert.ok(names.includes('control_cockpit'));
|
||||
assert.ok(names.includes('set_voice_inactivity_timeout'));
|
||||
@@ -209,6 +210,8 @@ test('no unchanged Realtime tool definition drifts silently', () => {
|
||||
'osm_query',
|
||||
// Street-level photos: a new composite tool, not an edit to a shipped one.
|
||||
'show_street_level',
|
||||
// Stories Explore: a new entry action.
|
||||
'open_stories',
|
||||
]);
|
||||
const unchanged = realtimeTools()
|
||||
.filter((tool) => !TOUCHED.has(tool.name))
|
||||
|
||||
@@ -756,6 +756,11 @@ export class ShareLinkManager {
|
||||
history.replaceState(history.state, '', url.href);
|
||||
}
|
||||
|
||||
/** Capture the live share hash without changing the current history entry. */
|
||||
snapshotHash() {
|
||||
return this._buildHashParams()?.toString() ?? null;
|
||||
}
|
||||
|
||||
/** Build a deterministic snapshot without mutating history. */
|
||||
_buildHashParams() {
|
||||
if (this._destroyed) return null;
|
||||
|
||||
@@ -167,6 +167,12 @@ test('holding writes first writes a view change still waiting for its debounce',
|
||||
manager.holdWrites(true);
|
||||
assert.equal(window.location.hash, '#v=2&lat=5', 'written before the hold');
|
||||
manager._buildHashParams = () => new URLSearchParams('v=2&lat=9');
|
||||
assert.equal(manager.snapshotHash(), 'v=2&lat=9');
|
||||
assert.equal(
|
||||
window.location.hash,
|
||||
'#v=2&lat=5',
|
||||
'snapshot leaves the URL alone',
|
||||
);
|
||||
manager._scheduleUpdate();
|
||||
assert.equal(timers.size, 0, 'nothing scheduled while held');
|
||||
manager.destroy();
|
||||
|
||||
@@ -14,6 +14,7 @@ const wantsStories = () => {
|
||||
* @param {{viewer: import('cesium').Viewer,
|
||||
* director: import('../scenes/director.js').SceneDirector,
|
||||
* store: ReturnType<typeof import('../ui/stores/stories.js').useStoriesStore>,
|
||||
* onEnter?: () => void,
|
||||
* onLoadFailed?: () => void,
|
||||
* loadModules?: () => Promise<[object, object]>}} options `onLoadFailed`
|
||||
* tells the person a click did nothing because Stories could not load;
|
||||
@@ -26,6 +27,7 @@ export function bootStories({
|
||||
viewer,
|
||||
director,
|
||||
store,
|
||||
onEnter,
|
||||
onLoadFailed,
|
||||
available = true,
|
||||
loadModules = () =>
|
||||
@@ -67,6 +69,7 @@ export function bootStories({
|
||||
viewer,
|
||||
director,
|
||||
store,
|
||||
onEnter,
|
||||
});
|
||||
store.connect(real, listStories());
|
||||
return real;
|
||||
|
||||
@@ -70,7 +70,14 @@ test('the shell loads the controller on first open, then steps aside', async ()
|
||||
setActivePinia(createPinia());
|
||||
history.replaceState(null, '', '/');
|
||||
const store = useStoriesStore();
|
||||
const shell = bootStories({ viewer, director, store });
|
||||
const entries = [];
|
||||
const shell = bootStories({
|
||||
viewer,
|
||||
director,
|
||||
store,
|
||||
onEnter: () =>
|
||||
entries.push(document.body.classList.contains('stories-mode')),
|
||||
});
|
||||
assert.equal(store.controller, shell);
|
||||
assert.equal(store.stories.length, 0, 'no catalog until Stories is used');
|
||||
const engineLoaded = () =>
|
||||
@@ -78,7 +85,14 @@ test('the shell loads the controller on first open, then steps aside', async ()
|
||||
/stories\/(controller|catalog|protoEngine)\.js$/.test(u),
|
||||
);
|
||||
assert.equal(engineLoaded(), false, 'GEV starts without the Stories chunk');
|
||||
await shell.open();
|
||||
let current = true;
|
||||
const staleOpen = shell.open({ isCurrent: () => current });
|
||||
current = false;
|
||||
assert.equal(await staleOpen, false);
|
||||
assert.equal(store.mode, 'closed');
|
||||
assert.deepEqual(entries, []);
|
||||
assert.equal(await shell.open(), true);
|
||||
assert.deepEqual(entries, [true]);
|
||||
assert.equal(engineLoaded(), true);
|
||||
assert.notEqual(store.controller, shell);
|
||||
assert.ok(store.stories.length > 0);
|
||||
@@ -115,10 +129,10 @@ test('a failed load is reported and the next open tries again', async () => {
|
||||
? Promise.reject(new Error('offline'))
|
||||
: Promise.all([import('./controller.js'), import('./catalog.js')]),
|
||||
});
|
||||
await shell.open();
|
||||
assert.equal(await shell.open(), undefined);
|
||||
assert.equal(failures, 1);
|
||||
assert.equal(store.mode, 'closed');
|
||||
await shell.open();
|
||||
assert.equal(await shell.open(), true);
|
||||
assert.equal(attempts, 2, 'the failure was not kept');
|
||||
assert.equal(store.mode, 'explore');
|
||||
shell.destroy();
|
||||
|
||||
+150
-35
@@ -19,6 +19,20 @@ import { registerNavigationAuthorityListener } from '../navigationPolicy.js';
|
||||
|
||||
const PARAM_STORIES = 'stories';
|
||||
const PARAM_STORY = 'story';
|
||||
const PARAM_STORY_TIME = 'storyTime';
|
||||
const PARAM_SELECTED_STORY = 'selectedStory';
|
||||
|
||||
function exploreSelection(params) {
|
||||
const id = params.get(PARAM_SELECTED_STORY);
|
||||
const story = id ? storyById(id) : null;
|
||||
return story && !story.mine ? story.id : null;
|
||||
}
|
||||
|
||||
function storyTime(params) {
|
||||
const value = params.get(PARAM_STORY_TIME);
|
||||
const ms = Number(value);
|
||||
return value && /^\d+$/.test(value) && Number.isSafeInteger(ms) ? ms : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stories: Explore (the story list over the person's own Cesium globe, with
|
||||
@@ -34,19 +48,28 @@ const PARAM_STORY = 'story';
|
||||
*
|
||||
* @param {{viewer: Cesium.Viewer,
|
||||
* director: import('../scenes/director.js').SceneDirector,
|
||||
* store: ReturnType<typeof import('../ui/stores/stories.js').useStoriesStore>}} options
|
||||
* store: ReturnType<typeof import('../ui/stores/stories.js').useStoriesStore>,
|
||||
* onEnter?: () => void}} options
|
||||
*/
|
||||
export function createStoriesController({ viewer, director, store }) {
|
||||
export function createStoriesController({ viewer, director, store, onEnter }) {
|
||||
let player = null;
|
||||
let saved = null;
|
||||
// The view a Close is about to restore, once a stopping scene has settled.
|
||||
let pendingView = null;
|
||||
// Reopening reuses the saved view, but supersedes the old close request.
|
||||
let closeGeneration = 0;
|
||||
let removeReadout = null;
|
||||
let destroyed = false;
|
||||
// Close steps back over Stories' own entries; the landing popstate is ours.
|
||||
let closingHistory = false;
|
||||
// A Back to Explore traversal is on its way.
|
||||
let steppingBack = false;
|
||||
let backTimer = 0;
|
||||
let readyTimer = 0;
|
||||
function cancelInitialLink() {
|
||||
clearTimeout(readyTimer);
|
||||
readyTimer = 0;
|
||||
}
|
||||
// A call made while a traversal is landing runs from the entry it lands on,
|
||||
// so two traversals never stack (Close after Back to Explore would step
|
||||
// one entry too far).
|
||||
@@ -78,7 +101,7 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
// A draft's THUMBNAIL or tags.
|
||||
'story-details-changed',
|
||||
]);
|
||||
const unsubscribeScenes = director.subscribe?.((change) => {
|
||||
const unsubscribeScenes = director.subscribe?.(({ change }) => {
|
||||
if (!LIST_CHANGES.has(change?.type) || destroyed) return;
|
||||
store.stories = markRaw(listStories());
|
||||
if (removePins) {
|
||||
@@ -96,6 +119,8 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
const url = new URL(location.href);
|
||||
url.searchParams.delete(PARAM_STORIES);
|
||||
url.searchParams.delete(PARAM_STORY);
|
||||
url.searchParams.delete(PARAM_STORY_TIME);
|
||||
url.searchParams.delete(PARAM_SELECTED_STORY);
|
||||
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
|
||||
if (Object.keys(params).length) url.hash = '';
|
||||
return url.toString();
|
||||
@@ -168,6 +193,7 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
}
|
||||
const onPopState = () => {
|
||||
if (destroyed) return;
|
||||
cancelInitialLink();
|
||||
const queued = afterTraversal;
|
||||
afterTraversal = null;
|
||||
try {
|
||||
@@ -177,6 +203,8 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
}
|
||||
};
|
||||
function handlePopState() {
|
||||
clearTimeout(backTimer);
|
||||
backTimer = 0;
|
||||
steppingBack = false;
|
||||
if (closingHistory) {
|
||||
closingHistory = false;
|
||||
@@ -189,12 +217,24 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
}
|
||||
const params = new URLSearchParams(location.search);
|
||||
const id = params.get(PARAM_STORY);
|
||||
if (id && storyById(id)) controller.openStory(id, { fromHistory: true });
|
||||
if (id && storyById(id))
|
||||
controller.openStory(id, {
|
||||
fromHistory: true,
|
||||
atMs: storyTime(params),
|
||||
});
|
||||
else if (params.has(PARAM_STORIES))
|
||||
store.mode === 'closed'
|
||||
? controller.open({ fromHistory: true })
|
||||
: controller.backToExplore({ fromHistory: true });
|
||||
else if (store.mode !== 'closed') controller.close({ fromHistory: true });
|
||||
else if (pendingView) {
|
||||
// Another browser navigation landed while the scene was stopping.
|
||||
// The destination owns the globe now, so discard the earlier restore.
|
||||
pendingView = null;
|
||||
closeGeneration += 1;
|
||||
document.body.classList.remove('stories-mode');
|
||||
shareLink()?.holdWrites?.(false);
|
||||
}
|
||||
}
|
||||
addEventListener('popstate', onPopState);
|
||||
|
||||
@@ -209,9 +249,8 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
time: viewer.clock.currentTime.clone(),
|
||||
animate: viewer.clock.shouldAnimate,
|
||||
openedAt: Date.now(),
|
||||
// The share state (layers, style, camera) as it was, for after a GEV
|
||||
// scene has changed it.
|
||||
hash: location.hash,
|
||||
// Story history entries have no hash. Capture the live globe state.
|
||||
hash: shareLink()?.snapshotHash?.() ?? location.hash,
|
||||
ranScene: false,
|
||||
// Whether a scene played during this visit, which selects it in
|
||||
// AUTHORING (ranScene clears once Back to Explore has undone the look).
|
||||
@@ -585,7 +624,9 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
saved = pendingView;
|
||||
pendingView = null;
|
||||
} else saveView();
|
||||
closeGeneration += 1;
|
||||
document.body.classList.add('stories-mode');
|
||||
onEnter?.();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -678,34 +719,41 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
}
|
||||
|
||||
const controller = {
|
||||
open({ fromHistory = false } = {}) {
|
||||
open({ fromHistory = false, isCurrent } = {}) {
|
||||
if (destroyed || (isCurrent && !isCurrent())) return false;
|
||||
cancelInitialLink();
|
||||
if (!fromHistory && traversing()) {
|
||||
afterTraversal = () => controller.open();
|
||||
return;
|
||||
if (!isCurrent) afterTraversal = () => controller.open();
|
||||
return false;
|
||||
}
|
||||
if (store.mode !== 'closed') return;
|
||||
if (!enterStories()) return;
|
||||
store.picked = null;
|
||||
if (store.mode !== 'closed' || !enterStories()) return false;
|
||||
store.picked = fromHistory
|
||||
? exploreSelection(new URLSearchParams(location.search))
|
||||
: null;
|
||||
showExplore();
|
||||
if (!fromHistory) navigate({ [PARAM_STORIES]: 'explore' }, true);
|
||||
return true;
|
||||
},
|
||||
close({ fromHistory = false, keepCamera = false } = {}) {
|
||||
if (destroyed) return;
|
||||
cancelInitialLink();
|
||||
if (store.mode === 'closed') return;
|
||||
if (!fromHistory && traversing()) {
|
||||
afterTraversal = () => controller.close({ keepCamera });
|
||||
return;
|
||||
}
|
||||
const generation = ++closeGeneration;
|
||||
dropPlayer();
|
||||
stopPins();
|
||||
viewer.camera.cancelFlight();
|
||||
// GEV comes back on screen now; `stories-mode` (keyboard guard, voice
|
||||
// refusal) stays until the view is back, so nothing acts on GEV under
|
||||
// a scene that is still tearing down.
|
||||
// Close the Stories screens now and keep their input guard until the
|
||||
// scene and share view have finished restoring.
|
||||
document.body.classList.remove('stories-scene');
|
||||
store.mode = 'closed';
|
||||
store.storyId = null;
|
||||
store.picked = null;
|
||||
store.expanded = false;
|
||||
store.toast = '';
|
||||
const was = saved;
|
||||
saved = null;
|
||||
pendingView = was;
|
||||
@@ -727,9 +775,14 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
canvas.removeEventListener('pointerdown', onDrag);
|
||||
stopWatching();
|
||||
// Reopened meanwhile (the reopen took `was` over), or torn down.
|
||||
if (pendingView !== was || destroyed || viewer.isDestroyed?.()) return;
|
||||
if (
|
||||
generation !== closeGeneration ||
|
||||
pendingView !== was ||
|
||||
destroyed ||
|
||||
viewer.isDestroyed?.()
|
||||
)
|
||||
return;
|
||||
pendingView = null;
|
||||
document.body.classList.remove('stories-mode');
|
||||
if (!navigated) restoreView(was, { keepCamera });
|
||||
// AUTHORING shows what it showed before, unless the person opened
|
||||
// the story there.
|
||||
@@ -740,6 +793,7 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
// over the earlier entry instead.
|
||||
if (!keepCamera && !navigated) restoreShareState(was);
|
||||
shareLink()?.holdWrites?.(false);
|
||||
document.body.classList.remove('stories-mode');
|
||||
};
|
||||
if (fromHistory) afterLanding();
|
||||
else leaveHistory(afterLanding);
|
||||
@@ -759,6 +813,8 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
* @param {{autoplay?: boolean, fromHistory?: boolean, atMs?: number}} [opts]
|
||||
*/
|
||||
openStory(id, { autoplay = false, fromHistory = false, atMs = 0 } = {}) {
|
||||
if (destroyed) return;
|
||||
cancelInitialLink();
|
||||
const story = storyById(id);
|
||||
if (!story) return;
|
||||
if (!fromHistory && traversing()) {
|
||||
@@ -777,6 +833,9 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
store.sheet = 'peek';
|
||||
store.bigPlay = !autoplay;
|
||||
syncSceneShots(story);
|
||||
atMs = Number.isFinite(atMs)
|
||||
? Math.max(0, Math.min(story.durationMs, Math.round(atMs)))
|
||||
: 0;
|
||||
store.playback = {
|
||||
wallMs: atMs,
|
||||
worldMs: null,
|
||||
@@ -796,15 +855,26 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
// Opened paused, a scene frames its first shot (or the moment asked).
|
||||
if (atMs || !autoplay) player.seek(atMs);
|
||||
if (autoplay) player.play();
|
||||
if (!fromHistory) navigate({ [PARAM_STORY]: story.id }, true);
|
||||
if (!fromHistory)
|
||||
navigate(
|
||||
atMs
|
||||
? { [PARAM_STORY]: story.id, [PARAM_STORY_TIME]: atMs }
|
||||
: { [PARAM_STORY]: story.id },
|
||||
true,
|
||||
);
|
||||
if (!store.hintSeen) {
|
||||
store.hintSeen = true;
|
||||
store.flashHint(t('Drag the map to explore · Resume any time'), 4200);
|
||||
}
|
||||
},
|
||||
backToExplore({ fromHistory = false } = {}) {
|
||||
// A second press while the first is landing does nothing more.
|
||||
if (!fromHistory && traversing()) return;
|
||||
if (destroyed) return;
|
||||
cancelInitialLink();
|
||||
// A second Back keeps the traversal, but cancels a story queued since.
|
||||
if (!fromHistory && traversing()) {
|
||||
if (steppingBack) afterTraversal = null;
|
||||
return;
|
||||
}
|
||||
dropPlayer();
|
||||
store.expanded = false;
|
||||
if (!fromHistory) {
|
||||
@@ -816,7 +886,9 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
if (params.has(PARAM_STORY) && to != null && depth() > to) {
|
||||
steppingBack = true;
|
||||
// A step that never lands gives up, as Close's does.
|
||||
setTimeout(() => {
|
||||
clearTimeout(backTimer);
|
||||
backTimer = setTimeout(() => {
|
||||
backTimer = 0;
|
||||
if (!steppingBack) return;
|
||||
steppingBack = false;
|
||||
const queued = afterTraversal;
|
||||
@@ -827,6 +899,10 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
return;
|
||||
}
|
||||
navigate({ [PARAM_STORIES]: 'explore' }, true);
|
||||
} else {
|
||||
const params = new URLSearchParams(location.search);
|
||||
if (params.has(PARAM_SELECTED_STORY))
|
||||
store.picked = exploreSelection(params);
|
||||
}
|
||||
showExplore();
|
||||
},
|
||||
@@ -855,7 +931,10 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
player.pause();
|
||||
// After Close has settled: the scene's teardown restores GEV's look
|
||||
// and panels, which would fold the Scenes panel again.
|
||||
await controller.close({ keepCamera: true });
|
||||
const closing = controller.close({ keepCamera: true });
|
||||
const generation = closeGeneration;
|
||||
await closing;
|
||||
if (destroyed || generation !== closeGeneration) return;
|
||||
director.selectShot?.(s.sceneId, shotId);
|
||||
director.styleManager?.setPanelCollapsed?.('scene-panel', false, {
|
||||
explicit: true,
|
||||
@@ -871,15 +950,35 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
shareLink() {
|
||||
const here = new URL(location.href);
|
||||
const url = new URL(here.pathname, here.origin);
|
||||
for (const key of [PARAM_STORIES, PARAM_STORY])
|
||||
if (here.searchParams.has(key))
|
||||
url.searchParams.set(key, here.searchParams.get(key));
|
||||
const id = store.mode === 'story' ? store.storyId : store.picked;
|
||||
const story = id ? storyById(id) : null;
|
||||
if (store.mode === 'story' && story && !story.mine) {
|
||||
url.searchParams.set(PARAM_STORY, story.id);
|
||||
const ms = Math.round(store.playback.wallMs);
|
||||
if (Number.isSafeInteger(ms) && ms > 0)
|
||||
url.searchParams.set(PARAM_STORY_TIME, String(ms));
|
||||
} else {
|
||||
url.searchParams.set(PARAM_STORIES, 'explore');
|
||||
if (story && !story.mine)
|
||||
url.searchParams.set(PARAM_SELECTED_STORY, story.id);
|
||||
}
|
||||
return url.toString();
|
||||
},
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
controller.close();
|
||||
destroyed = true;
|
||||
cancelInitialLink();
|
||||
clearTimeout(backTimer);
|
||||
clearTimeout(landingTimer);
|
||||
steppingBack = closingHistory = false;
|
||||
afterTraversal = landed = null;
|
||||
dropPlayer();
|
||||
stopPins();
|
||||
viewer.camera.cancelFlight();
|
||||
store.mode = 'closed';
|
||||
store.storyId = null;
|
||||
store.picked = null;
|
||||
store.expanded = false;
|
||||
// Torn down mid-close: what the close would undo once settled is
|
||||
// undone now (keyboard and voice guard, held share writes).
|
||||
document.body.classList.remove('stories-mode', 'stories-scene');
|
||||
@@ -893,7 +992,6 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
canvas.removeEventListener('pointerup', onExploreInput);
|
||||
canvas.removeEventListener('pointercancel', onExploreInput);
|
||||
canvas.removeEventListener('wheel', onExploreInput);
|
||||
stopTour();
|
||||
canvas.removeEventListener('pointerup', onUp);
|
||||
},
|
||||
};
|
||||
@@ -901,17 +999,21 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
// A shared link opens where it points once GEV has finished loading.
|
||||
const params = new URLSearchParams(location.search);
|
||||
if (params.has(PARAM_STORY) || params.has(PARAM_STORIES)) {
|
||||
const id = params.get(PARAM_STORY);
|
||||
const started = Date.now();
|
||||
const whenReady = () => {
|
||||
readyTimer = 0;
|
||||
if (destroyed) return;
|
||||
const params = new URLSearchParams(location.search);
|
||||
if (!params.has(PARAM_STORY) && !params.has(PARAM_STORIES)) return;
|
||||
const id = params.get(PARAM_STORY);
|
||||
const atMs = storyTime(params);
|
||||
const loading = document.getElementById('loading-screen');
|
||||
if (
|
||||
loading &&
|
||||
!loading.classList.contains('hidden') &&
|
||||
Date.now() - started < 30000
|
||||
) {
|
||||
setTimeout(whenReady, 300);
|
||||
readyTimer = setTimeout(whenReady, 300);
|
||||
return;
|
||||
}
|
||||
// A reload, or Back/Forward into a Stories entry: its history is
|
||||
@@ -920,11 +1022,19 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
// GEV's boot wrote its share hash onto the entry: Stories' entries
|
||||
// carry none.
|
||||
const own = Object.fromEntries(
|
||||
[...params].filter(([k]) => k === PARAM_STORIES || k === PARAM_STORY),
|
||||
[...params].filter(
|
||||
([key]) =>
|
||||
key === PARAM_STORIES ||
|
||||
key === PARAM_STORY ||
|
||||
(key === PARAM_STORY_TIME && id && atMs) ||
|
||||
(key === PARAM_SELECTED_STORY &&
|
||||
!id &&
|
||||
params.has(PARAM_STORIES)),
|
||||
),
|
||||
);
|
||||
history.replaceState(history.state, '', urlFor(own));
|
||||
if (id && storyById(id))
|
||||
controller.openStory(id, { fromHistory: true });
|
||||
controller.openStory(id, { fromHistory: true, atMs });
|
||||
else {
|
||||
controller.open({ fromHistory: true });
|
||||
if (id) store.flashToast(t('That story is not available here'));
|
||||
@@ -933,19 +1043,24 @@ export function createStoriesController({ viewer, director, store }) {
|
||||
}
|
||||
// A new link: Explore sits under a story it opens, so Back lands there.
|
||||
const landing = { stories: 'explore', depth: 0, explore: 0 };
|
||||
const selected =
|
||||
!id && params.has(PARAM_STORIES) ? exploreSelection(params) : null;
|
||||
history.replaceState(
|
||||
{ ...(history.state ?? {}), gevStories: landing },
|
||||
'',
|
||||
urlFor({ [PARAM_STORIES]: 'explore' }),
|
||||
urlFor({
|
||||
[PARAM_STORIES]: 'explore',
|
||||
...(selected ? { [PARAM_SELECTED_STORY]: selected } : {}),
|
||||
}),
|
||||
);
|
||||
if (id && storyById(id)) controller.openStory(id);
|
||||
if (id && storyById(id)) controller.openStory(id, { atMs });
|
||||
else {
|
||||
controller.open({ fromHistory: true });
|
||||
// A story saved on someone else's device, or no longer here.
|
||||
if (id) store.flashToast(t('That story is not available here'));
|
||||
}
|
||||
};
|
||||
setTimeout(whenReady, 300);
|
||||
readyTimer = setTimeout(whenReady, 300);
|
||||
}
|
||||
|
||||
if (import.meta.env?.DEV) globalThis.__gevStories = { viewer, controller };
|
||||
|
||||
+236
-31
@@ -6,6 +6,7 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { createPinia, setActivePinia } from 'pinia';
|
||||
import { createStateChannel } from '../app/stateChannel.js';
|
||||
|
||||
registerHooks({
|
||||
load(url, context, next) {
|
||||
@@ -123,21 +124,31 @@ function setup(options = {}) {
|
||||
const store = useStoriesStore();
|
||||
const viewer = fakeViewer();
|
||||
const director = fakeDirector(options);
|
||||
const controller = createStoriesController({ viewer, director, store });
|
||||
const controller = createStoriesController({
|
||||
viewer,
|
||||
director,
|
||||
store,
|
||||
onEnter: options.onEnter,
|
||||
});
|
||||
store.connect(controller, listStories());
|
||||
return { store, viewer, director, controller };
|
||||
}
|
||||
|
||||
test('Close steps back over every entry Stories pushed', async () => {
|
||||
const { controller } = setup();
|
||||
const entered = [];
|
||||
const { controller } = setup({
|
||||
onEnter: () =>
|
||||
entered.push(document.body.classList.contains('stories-mode')),
|
||||
});
|
||||
const steps = [];
|
||||
const go = history.go;
|
||||
history.go = (n) => steps.push(n);
|
||||
try {
|
||||
controller.open();
|
||||
assert.equal(controller.open(), true);
|
||||
assert.equal(history.state.gevStories.depth, 1);
|
||||
controller.openStory('gev:flights-radar');
|
||||
assert.equal(history.state.gevStories.depth, 2);
|
||||
assert.deepEqual(entered, [true]);
|
||||
await controller.close();
|
||||
// Back after Close would otherwise land on ?story=… and reopen it.
|
||||
assert.deepEqual(steps, [-2]);
|
||||
@@ -158,8 +169,13 @@ test('Close from a Stories link clears Stories from the URL in place', async ()
|
||||
});
|
||||
|
||||
test('Cockpit keeps the camera: Stories does not open', () => {
|
||||
const { controller, store, director } = setup({ refuse: true });
|
||||
controller.open();
|
||||
const { controller, store, director } = setup({
|
||||
refuse: true,
|
||||
onEnter: () => assert.fail('refused entry should not stop voice'),
|
||||
});
|
||||
assert.equal(controller.open({ isCurrent: () => false }), false);
|
||||
assert.deepEqual(director.claims, []);
|
||||
assert.equal(controller.open(), false);
|
||||
assert.equal(store.mode, 'closed');
|
||||
assert.equal(director.stops, 0);
|
||||
// The navigation policy shows the refusal; it needs a sentence for the noun.
|
||||
@@ -169,17 +185,21 @@ test('Cockpit keeps the camera: Stories does not open', () => {
|
||||
});
|
||||
|
||||
test('reopening while a scene tears down keeps the view from before Stories', async () => {
|
||||
const { controller, viewer, director } = setup();
|
||||
const { controller, viewer, director, store } = setup();
|
||||
const before = viewer.camera.positionWC;
|
||||
controller.open();
|
||||
controller.openStory('gev:bhote-koshi-nepal-scene');
|
||||
director.running = true;
|
||||
const closing = controller.close();
|
||||
const toast = store.hostedToast;
|
||||
const closing = controller.openInGev();
|
||||
// The scene has moved the camera; the person opens Stories again at once.
|
||||
viewer.camera.positionWC = new Cesium.Cartesian3(9, 9, 9);
|
||||
controller.open();
|
||||
director.running = false;
|
||||
await closing;
|
||||
assert.deepEqual(director.selected, []);
|
||||
assert.deepEqual(director.styleManager.panels, []);
|
||||
assert.equal(store.hostedToast, toast);
|
||||
assert.equal(
|
||||
viewer.camera.views.length,
|
||||
0,
|
||||
@@ -204,14 +224,36 @@ test('after a GEV scene, the person’s view comes back once the scene has torn
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
test('a share link carries the story, not the sender’s camera and layers', () => {
|
||||
const { controller } = setup();
|
||||
test('Share links to the selection and captures the playing story’s timeline', () => {
|
||||
const { controller, store } = setup();
|
||||
controller.open();
|
||||
assert.equal(new URL(controller.shareLink()).search, '?stories=explore');
|
||||
controller.pick('gev:orbital-watch');
|
||||
assert.equal(
|
||||
new URL(controller.shareLink()).search,
|
||||
'?stories=explore&selectedStory=gev%3Aorbital-watch',
|
||||
);
|
||||
controller.openStory('gev:flights-radar');
|
||||
store.playback = { ...store.playback, playing: true, wallMs: 1250.6 };
|
||||
const link = new URL(controller.shareLink());
|
||||
assert.equal(link.searchParams.get('story'), 'gev:flights-radar');
|
||||
assert.deepEqual(
|
||||
[...link.searchParams],
|
||||
[
|
||||
['story', 'gev:flights-radar'],
|
||||
['storyTime', '1251'],
|
||||
],
|
||||
);
|
||||
assert.equal(link.hash, '');
|
||||
assert.equal(link.searchParams.has('x'), false, 'no other query parameters');
|
||||
store.playback.wallMs = 1850;
|
||||
assert.equal(
|
||||
new URL(controller.shareLink()).searchParams.get('storyTime'),
|
||||
'1850',
|
||||
);
|
||||
controller.backToExplore({ fromHistory: true });
|
||||
assert.equal(
|
||||
new URL(controller.shareLink()).search,
|
||||
'?stories=explore&selectedStory=gev%3Aflights-radar',
|
||||
);
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
@@ -227,7 +269,7 @@ function recordGo(t) {
|
||||
}
|
||||
|
||||
test('Back to Explore after a related story steps past both stories', (t) => {
|
||||
const { controller } = setup();
|
||||
const { controller, store } = setup();
|
||||
const steps = recordGo(t);
|
||||
controller.open();
|
||||
controller.openStory('gev:flights-radar');
|
||||
@@ -235,9 +277,19 @@ test('Back to Explore after a related story steps past both stories', (t) => {
|
||||
assert.equal(history.state.gevStories.depth, 3);
|
||||
assert.equal(history.state.gevStories.explore, 1);
|
||||
controller.backToExplore();
|
||||
// A second click before the traversal lands does nothing more.
|
||||
controller.openStory('gev:flights-radar'); // queued behind Back
|
||||
// The latest Back cancels that queued story without another traversal.
|
||||
controller.backToExplore();
|
||||
assert.deepEqual(steps, [-2]);
|
||||
history.replaceState(
|
||||
{ gevStories: { stories: 'explore', depth: 1, explore: 1 } },
|
||||
'',
|
||||
'/?stories=explore',
|
||||
);
|
||||
dispatchEvent(new PopStateEvent('popstate'));
|
||||
assert.equal(store.mode, 'explore');
|
||||
assert.equal(store.storyId, null);
|
||||
assert.equal(history.state.gevStories.depth, 1, 'no queued story pushed');
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
@@ -246,13 +298,13 @@ test('a second Close after a quick reopen still waits for the scene to tear down
|
||||
controller.open();
|
||||
controller.openStory('gev:bhote-koshi-nepal-scene');
|
||||
director.running = true;
|
||||
controller.close();
|
||||
const first = controller.close({ keepCamera: true });
|
||||
controller.open(); // reopened while the scene is still stopping
|
||||
const closing = controller.close(); // Explore: no GEV story on screen
|
||||
assert.ok(closing, 'this Close waits too');
|
||||
assert.equal(viewer.camera.views.length, 0, 'nothing restored yet');
|
||||
setTimeout(() => (director.running = false), 120);
|
||||
await closing;
|
||||
await Promise.all([first, closing]);
|
||||
assert.equal(viewer.camera.views.length, 1);
|
||||
controller.destroy();
|
||||
});
|
||||
@@ -262,7 +314,7 @@ test('a reload of a Stories entry keeps its history; Close steps all of it back'
|
||||
history.replaceState(
|
||||
{ gevStories: { story: 'gev:flights-radar', depth: 2, explore: 1 } },
|
||||
'',
|
||||
'/?story=gev%3Aflights-radar',
|
||||
'/?story=gev%3Aflights-radar&storyTime=1250',
|
||||
);
|
||||
const steps = recordGo(t);
|
||||
const store = useStoriesStore();
|
||||
@@ -274,6 +326,8 @@ test('a reload of a Stories entry keeps its history; Close steps all of it back'
|
||||
store.connect(controller, listStories());
|
||||
await new Promise((resolve) => setTimeout(resolve, 400));
|
||||
assert.equal(store.storyId, 'gev:flights-radar');
|
||||
assert.equal(store.playback.wallMs, 1250);
|
||||
assert.equal(store.playback.playing, false);
|
||||
assert.equal(history.state.gevStories.depth, 2, 'no extra entry pushed');
|
||||
await controller.close();
|
||||
assert.deepEqual(steps, [-2]);
|
||||
@@ -282,7 +336,7 @@ test('a reload of a Stories entry keeps its history; Close steps all of it back'
|
||||
|
||||
test('a new story link puts Explore under the story', async (t) => {
|
||||
setActivePinia(createPinia());
|
||||
history.replaceState(null, '', '/?story=gev%3Aflights-radar');
|
||||
history.replaceState(null, '', '/?story=gev%3Aflights-radar&storyTime=1250');
|
||||
const steps = recordGo(t);
|
||||
const store = useStoriesStore();
|
||||
const controller = createStoriesController({
|
||||
@@ -293,8 +347,11 @@ test('a new story link puts Explore under the story', async (t) => {
|
||||
store.connect(controller, listStories());
|
||||
await new Promise((resolve) => setTimeout(resolve, 400));
|
||||
assert.equal(store.storyId, 'gev:flights-radar');
|
||||
assert.equal(store.playback.wallMs, 1250);
|
||||
assert.equal(store.playback.playing, false);
|
||||
assert.deepEqual(history.state.gevStories, {
|
||||
story: 'gev:flights-radar',
|
||||
storyTime: 1250,
|
||||
depth: 1,
|
||||
explore: 0,
|
||||
});
|
||||
@@ -377,6 +434,29 @@ function land(hash = '#v=2&lat=1') {
|
||||
dispatchEvent(new PopStateEvent('popstate'));
|
||||
}
|
||||
|
||||
test('a second browser Back during scene teardown supersedes the Stories restore', async () => {
|
||||
const { controller, director, store, viewer } = setup();
|
||||
const share = director.styleManager.shareLinkManager;
|
||||
const holds = [];
|
||||
share.holdWrites = (held) => holds.push(held);
|
||||
director.selection = () => ({ sceneId: 'previous', shotId: 'shot-1' });
|
||||
controller.open();
|
||||
controller.openStory('gev:bhote-koshi-nepal-scene');
|
||||
director.running = true;
|
||||
land();
|
||||
assert.equal(store.mode, 'closed');
|
||||
land('#v=2&lat=2');
|
||||
director.running = false;
|
||||
await tick(0);
|
||||
assert.equal(location.hash, '#v=2&lat=2');
|
||||
assert.equal(viewer.camera.views.length, 0);
|
||||
assert.deepEqual(share.restored, []);
|
||||
assert.deepEqual(director.selected, []);
|
||||
assert.deepEqual(holds, [true, false]);
|
||||
assert.equal(document.body.classList.contains('stories-mode'), false);
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
test('Close after a GEV scene puts the share state back once the step back lands', async (t) => {
|
||||
const { controller, director } = setup();
|
||||
const steps = recordGo(t);
|
||||
@@ -386,8 +466,10 @@ test('Close after a GEV scene puts the share state back once the step back lands
|
||||
await controller.close();
|
||||
assert.deepEqual(steps, [-2]);
|
||||
assert.deepEqual(restored, [], 'not before the landing');
|
||||
assert.equal(document.body.classList.contains('stories-mode'), true);
|
||||
land();
|
||||
assert.deepEqual(restored, ['v=2&lat=1']);
|
||||
assert.equal(document.body.classList.contains('stories-mode'), false);
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
@@ -435,7 +517,7 @@ test('a reloaded Stories entry drops the share hash GEV wrote on boot', async ()
|
||||
history.replaceState(
|
||||
{ gevStories: { stories: 'explore', depth: 1, explore: 1 } },
|
||||
'',
|
||||
'/?stories=explore#v=2&lat=7',
|
||||
'/?stories=explore&selectedStory=gev%3Aorbital-watch#v=2&lat=7',
|
||||
);
|
||||
const store = useStoriesStore();
|
||||
const controller = createStoriesController({
|
||||
@@ -447,7 +529,19 @@ test('a reloaded Stories entry drops the share hash GEV wrote on boot', async ()
|
||||
await new Promise((resolve) => setTimeout(resolve, 400));
|
||||
assert.equal(store.mode, 'explore');
|
||||
assert.equal(location.hash, '');
|
||||
assert.equal(new URL(location.href).searchParams.get('stories'), 'explore');
|
||||
assert.equal(store.picked, 'gev:orbital-watch');
|
||||
assert.equal(
|
||||
location.search,
|
||||
'?stories=explore&selectedStory=gev%3Aorbital-watch',
|
||||
);
|
||||
const exploreState = history.state;
|
||||
const exploreUrl = location.href;
|
||||
controller.openStory('gev:flights-radar');
|
||||
assert.equal(location.search, '?story=gev%3Aflights-radar');
|
||||
history.replaceState(exploreState, '', exploreUrl);
|
||||
dispatchEvent(new PopStateEvent('popstate'));
|
||||
assert.equal(store.mode, 'explore');
|
||||
assert.equal(store.picked, 'gev:orbital-watch');
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
@@ -478,13 +572,13 @@ test('a scene saved to Stories from AUTHORING joins the list at once', () => {
|
||||
shotCount: 2,
|
||||
},
|
||||
];
|
||||
listener({ type: 'stories-changed' });
|
||||
listener({ change: { type: 'stories-changed' } });
|
||||
const story = store.byId('gev:my-scene');
|
||||
assert.equal(story?.title, 'Harbour at dawn');
|
||||
assert.equal(story.mine, true);
|
||||
assert.equal(store.stories[0].id, 'gev:my-scene', 'the person’s own first');
|
||||
mine = [];
|
||||
listener({ type: 'stories-changed' });
|
||||
listener({ change: { type: 'stories-changed' } });
|
||||
assert.equal(store.byId('gev:my-scene'), null, 'removed from Stories');
|
||||
controller.destroy();
|
||||
assert.equal(listener, null, 'unsubscribed');
|
||||
@@ -492,10 +586,13 @@ test('a scene saved to Stories from AUTHORING joins the list at once', () => {
|
||||
|
||||
test('Back to Explore after a scene puts the look back once the scene has torn down, then frames Explore', async () => {
|
||||
const { controller, viewer, director } = setup();
|
||||
history.replaceState(null, '', '/');
|
||||
const flights = [];
|
||||
viewer.camera.flyTo = (f) => flights.push(f);
|
||||
viewer.camera.flyToBoundingSphere = (f) => flights.push(f);
|
||||
const share = director.styleManager.shareLinkManager;
|
||||
const original = 'v=2&lat=1&style=normal';
|
||||
share.snapshotHash = () => original;
|
||||
// GEV's restore writes the hash it applies; Explore's address drops it.
|
||||
share.restore = function (hash) {
|
||||
this.restored.push(hash);
|
||||
@@ -506,13 +603,18 @@ test('Back to Explore after a scene puts the look back once the scene has torn d
|
||||
controller.openStory('gev:bhote-koshi-nepal-scene');
|
||||
director.running = true;
|
||||
flights.length = 0;
|
||||
controller.backToExplore({ fromHistory: true });
|
||||
history.replaceState(
|
||||
{ gevStories: { stories: 'explore', depth: 1, explore: 1 } },
|
||||
'',
|
||||
'/?stories=explore',
|
||||
);
|
||||
dispatchEvent(new PopStateEvent('popstate'));
|
||||
await tick(30);
|
||||
assert.deepEqual(share.restored, [], 'not under the stopping scene');
|
||||
assert.equal(flights.length, 0, 'Explore waits for the scene');
|
||||
director.running = false;
|
||||
await tick(40);
|
||||
assert.deepEqual(share.restored, ['v=2&lat=1']);
|
||||
assert.deepEqual(share.restored, [original]);
|
||||
assert.equal(location.hash, '', 'the address names only Stories');
|
||||
assert.equal(flights.length, 1, 'then Explore frames the globe');
|
||||
// A later Back to Explore with no scene in between restores nothing more.
|
||||
@@ -579,9 +681,16 @@ test('Explore tours from story to story once idle, stops on a pick or a touch, a
|
||||
|
||||
test('a new Explore link keeps the address free of the share hash GEV writes as Stories opens', async () => {
|
||||
setActivePinia(createPinia());
|
||||
history.replaceState(null, '', '/?stories=explore');
|
||||
history.replaceState(
|
||||
null,
|
||||
'',
|
||||
'/?stories=explore&selectedStory=gev%3Aorbital-watch',
|
||||
);
|
||||
const store = useStoriesStore();
|
||||
const director = fakeDirector();
|
||||
const playbackCalls = [];
|
||||
director.startScene = () => playbackCalls.push('start');
|
||||
director.seekScene = () => playbackCalls.push('seek');
|
||||
// Holding writes first writes the view change still waiting.
|
||||
director.styleManager.shareLinkManager.holdWrites = (held) => {
|
||||
if (held) history.replaceState(history.state, '', `${location.search}#v=2`);
|
||||
@@ -595,7 +704,13 @@ test('a new Explore link keeps the address free of the share hash GEV writes as
|
||||
await tick(400);
|
||||
assert.equal(store.mode, 'explore');
|
||||
assert.equal(location.hash, '');
|
||||
assert.equal(location.search, '?stories=explore');
|
||||
assert.equal(
|
||||
location.search,
|
||||
'?stories=explore&selectedStory=gev%3Aorbital-watch',
|
||||
);
|
||||
assert.equal(store.picked, 'gev:orbital-watch');
|
||||
assert.equal(store.storyId, null);
|
||||
assert.deepEqual(playbackCalls, []);
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
@@ -690,13 +805,12 @@ test('Close after Back to Explore still puts AUTHORING’s selection back', asyn
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
test('the person’s unsaved scenes list as drafts, which cannot be shared', () => {
|
||||
test('unsaved scenes appear as local drafts and disappear when deleted', () => {
|
||||
setActivePinia(createPinia());
|
||||
history.replaceState(null, '', '/');
|
||||
const store = useStoriesStore();
|
||||
const director = fakeDirector();
|
||||
director.subscribe = () => () => {};
|
||||
director.draftScenes = () => [
|
||||
const drafts = [
|
||||
{
|
||||
id: 'sketch',
|
||||
title: 'Sketch',
|
||||
@@ -706,6 +820,9 @@ test('the person’s unsaved scenes list as drafts, which cannot be shared', ()
|
||||
tags: [],
|
||||
},
|
||||
];
|
||||
const channel = createStateChannel(() => ({ scenes: drafts }));
|
||||
director.subscribe = channel.subscribe;
|
||||
director.draftScenes = () => drafts;
|
||||
const controller = createStoriesController({
|
||||
viewer: fakeViewer(),
|
||||
director,
|
||||
@@ -715,6 +832,10 @@ test('the person’s unsaved scenes list as drafts, which cannot be shared', ()
|
||||
const draft = store.byId('gev:sketch');
|
||||
assert.equal(draft?.draft, true);
|
||||
assert.equal(draft.mine, true, 'local only: no Share');
|
||||
drafts.length = 0;
|
||||
channel.publish({ type: 'scene-deleted' });
|
||||
controller.open();
|
||||
assert.equal(store.byId('gev:sketch'), null);
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
@@ -755,20 +876,31 @@ test('the tour waits again after a wheel turn or a cancelled press, and a list c
|
||||
assert.equal(flights.length, before + 1, `${type}: then tours`);
|
||||
}
|
||||
canvas.dispatchEvent(new Event('pointerdown'));
|
||||
listener({ type: 'stories-changed' });
|
||||
listener({ change: { type: 'stories-changed' } });
|
||||
const held = flights.length;
|
||||
t.mock.timers.tick(30000);
|
||||
assert.equal(flights.length, held, 'nothing flies under the drag');
|
||||
again.destroy();
|
||||
});
|
||||
|
||||
test('teardown mid-close lets the share link write again', () => {
|
||||
const { controller, director } = setup();
|
||||
test('teardown mid-close releases share writes and cancels a queued reopen', async (t) => {
|
||||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||||
const { controller, director, store, viewer } = setup();
|
||||
recordGo(t);
|
||||
const held = [];
|
||||
director.styleManager.shareLinkManager.holdWrites = (on) => held.push(on);
|
||||
let flights = 0;
|
||||
viewer.camera.flyTo = () => flights++;
|
||||
controller.open();
|
||||
await controller.close();
|
||||
controller.open(); // queued until the Close traversal lands
|
||||
controller.destroy();
|
||||
const before = flights;
|
||||
assert.equal(held.at(-1), false);
|
||||
t.mock.timers.tick(3000);
|
||||
assert.equal(store.mode, 'closed');
|
||||
assert.equal(held.at(-1), false, 'no late reopen holds writes again');
|
||||
assert.equal(flights, before, 'no late flight after teardown');
|
||||
});
|
||||
|
||||
test('place names name only a shipped scene’s untitled shots', () => {
|
||||
@@ -785,3 +917,76 @@ test('place names name only a shipped scene’s untitled shots', () => {
|
||||
);
|
||||
controller.destroy();
|
||||
});
|
||||
|
||||
test('new navigation cancels a delayed initial story link', async (t) => {
|
||||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||||
for (const action of ['back', 'open', 'close']) {
|
||||
setActivePinia(createPinia());
|
||||
history.replaceState(null, '', '/?story=gev%3Aflights-radar');
|
||||
const store = useStoriesStore();
|
||||
const controller = createStoriesController({
|
||||
viewer: fakeViewer(),
|
||||
director: fakeDirector(),
|
||||
store,
|
||||
});
|
||||
store.connect(controller, listStories());
|
||||
try {
|
||||
if (action === 'back') land();
|
||||
else if (action === 'open') controller.open();
|
||||
else controller.close();
|
||||
const url = location.href;
|
||||
t.mock.timers.tick(400);
|
||||
assert.equal(
|
||||
store.mode,
|
||||
action === 'open' ? 'explore' : 'closed',
|
||||
action,
|
||||
);
|
||||
assert.equal(store.storyId, null, action);
|
||||
assert.equal(
|
||||
location.href,
|
||||
url,
|
||||
'the old link does not rewrite navigation',
|
||||
);
|
||||
} finally {
|
||||
controller.destroy();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('an earlier Back timeout cannot release a later traversal', async (t) => {
|
||||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||||
const { controller, store } = setup();
|
||||
const steps = recordGo(t);
|
||||
const landExplore = () => {
|
||||
history.replaceState(
|
||||
{ gevStories: { stories: 'explore', depth: 1, explore: 1 } },
|
||||
'',
|
||||
'/?stories=explore',
|
||||
);
|
||||
dispatchEvent(new PopStateEvent('popstate'));
|
||||
};
|
||||
try {
|
||||
controller.open();
|
||||
controller.openStory('gev:flights-radar');
|
||||
controller.backToExplore();
|
||||
landExplore();
|
||||
t.mock.timers.tick(1500);
|
||||
controller.openStory('gev:orbital-watch');
|
||||
controller.backToExplore();
|
||||
controller.close();
|
||||
t.mock.timers.tick(600);
|
||||
assert.equal(store.mode, 'story', 'Close still waits for the second Back');
|
||||
assert.deepEqual(steps, [-1, -1]);
|
||||
landExplore();
|
||||
// Drain the director's already-idle promise without advancing timers.
|
||||
for (let i = 0; i < 12; i++) await Promise.resolve();
|
||||
assert.equal(store.mode, 'closed');
|
||||
assert.deepEqual(
|
||||
steps,
|
||||
[-1, -1, -1],
|
||||
'queued Close runs once after landing',
|
||||
);
|
||||
} finally {
|
||||
controller.destroy();
|
||||
}
|
||||
});
|
||||
@@ -44,7 +44,7 @@ export function createGevPlayer(director, story, hooks = {}) {
|
||||
let shotIndex = 0;
|
||||
let destroyed = false;
|
||||
// Each Play, Pause, Seek and Destroy takes a new number; a Play that waited
|
||||
// for a teardown or a start goes ahead only if nothing came after it.
|
||||
// for a teardown or a run to finish acts only if nothing came after it.
|
||||
let request = 0;
|
||||
|
||||
const state = () => ({
|
||||
@@ -65,7 +65,8 @@ export function createGevPlayer(director, story, hooks = {}) {
|
||||
wallMs = (snap.sceneElapsedSec ?? 0) * 1000;
|
||||
shotIndex = snap.shotIndex ?? shotIndex;
|
||||
playing = !!snap.running && !snap.seeking;
|
||||
if (!playing && wallMs >= durationMs - 250) wallMs = durationMs;
|
||||
if (!playing && !snap.seeking && wallMs >= durationMs - 250)
|
||||
wallMs = durationMs;
|
||||
tick();
|
||||
});
|
||||
|
||||
@@ -100,13 +101,9 @@ export function createGevPlayer(director, story, hooks = {}) {
|
||||
afterShotId,
|
||||
preview: true,
|
||||
});
|
||||
if (destroyed) return;
|
||||
if (mine !== request) {
|
||||
// Paused or scrubbed while the run was starting: that wins.
|
||||
if (result?.started)
|
||||
director.seekScene(sceneId, durationMs ? wallMs / durationMs : 0);
|
||||
return;
|
||||
}
|
||||
// startScene resolves after the run finishes, not when it starts.
|
||||
// A newer pause, seek or play already owns the director by then.
|
||||
if (destroyed || mine !== request) return;
|
||||
if (!result?.started) {
|
||||
playing = false;
|
||||
tick();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// A GEV scene's Play waits for the last run to tear down and for the new run
|
||||
// to start; a Pause, Seek or Destroy meanwhile must win.
|
||||
// to finish; a Pause, Seek or Destroy meanwhile must win.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createGevPlayer } from './gevPlayer.js';
|
||||
@@ -10,7 +10,7 @@ const story = {
|
||||
chapters: [{ wallMs: 0 }, { wallMs: 30000 }],
|
||||
};
|
||||
|
||||
/** A director whose start resolves when the test says so. */
|
||||
/** A director whose run starts immediately and ends when the test says so. */
|
||||
function deferredDirector({ running = false } = {}) {
|
||||
const calls = [];
|
||||
let release = null;
|
||||
@@ -30,14 +30,15 @@ function deferredDirector({ running = false } = {}) {
|
||||
seekScene: (id, f) => calls.push(`seek ${f}`),
|
||||
startScene: () => {
|
||||
calls.push('start');
|
||||
director.running = true;
|
||||
return new Promise((resolve) => {
|
||||
release = () => {
|
||||
director.running = true;
|
||||
director.running = false;
|
||||
resolve({ started: true });
|
||||
};
|
||||
});
|
||||
},
|
||||
finishStart: () => release?.(),
|
||||
finishRun: () => release?.(),
|
||||
};
|
||||
return director;
|
||||
}
|
||||
@@ -70,17 +71,39 @@ test('a Seek during the last run’s teardown cancels the waiting Play', async (
|
||||
assert.equal(player.state.wallMs, 30000);
|
||||
});
|
||||
|
||||
test('a Pause while the run is starting is applied once it has started', async () => {
|
||||
test('a stopped run’s completion does not repeat a newer seek', async () => {
|
||||
const director = deferredDirector();
|
||||
const player = createGevPlayer(director, story);
|
||||
const playing = player.play();
|
||||
await turns();
|
||||
assert.deepEqual(director.calls, ['start']);
|
||||
assert.equal(director.running, true);
|
||||
player.pause();
|
||||
director.finishStart();
|
||||
player.seek(30000);
|
||||
director.finishRun();
|
||||
await playing;
|
||||
// Pause seeks once when pressed, and again after the late start.
|
||||
assert.equal(director.calls.filter((c) => c.startsWith('seek')).length, 2);
|
||||
assert.deepEqual(director.calls, ['start', 'seek 0', 'seek 0.5']);
|
||||
assert.equal(player.state.playing, false);
|
||||
assert.equal(player.state.wallMs, 30000);
|
||||
});
|
||||
|
||||
test('a paused seek keeps its exact position near the end of a story', () => {
|
||||
const director = deferredDirector();
|
||||
let publishClock;
|
||||
director.subscribeSceneClock = (listener) => {
|
||||
publishClock = listener;
|
||||
return () => {};
|
||||
};
|
||||
const player = createGevPlayer(director, story);
|
||||
player.seek(59800);
|
||||
publishClock({
|
||||
sceneId: story.sceneId,
|
||||
sceneElapsedSec: 59.8,
|
||||
sceneDurationSec: 60,
|
||||
running: false,
|
||||
seeking: true,
|
||||
});
|
||||
assert.equal(player.state.wallMs, 59800);
|
||||
assert.equal(player.state.playing, false);
|
||||
});
|
||||
|
||||
|
||||
@@ -22,15 +22,19 @@ const props = defineProps({
|
||||
const emit = defineEmits(['back', 'home', 'crumb', 'search']);
|
||||
const store = useStoriesStore();
|
||||
// A scene saved on this device only: a link to it opens nothing elsewhere.
|
||||
const localOnly = computed(() => !!store.byId(store.storyId)?.mine);
|
||||
const localOnly = computed(
|
||||
() =>
|
||||
!!store.byId(props.screen === 'story' ? store.storyId : store.picked)?.mine,
|
||||
);
|
||||
|
||||
async function share() {
|
||||
const what = props.screen === 'story' ? t('Story') : t('Stories');
|
||||
const url = store.controller.shareLink();
|
||||
try {
|
||||
await navigator.clipboard.writeText(store.controller.shareLink());
|
||||
await navigator.clipboard.writeText(url);
|
||||
store.flashToast(t('{what} link copied', { what }));
|
||||
} catch {
|
||||
store.flashToast(t('Copy this link: {url}', { url: location.href }), 4000);
|
||||
store.flashToast(t('Copy this link: {url}', { url }), 4000);
|
||||
}
|
||||
}
|
||||
// Long titles scroll gently so the whole name can be read.
|
||||
@@ -131,7 +135,7 @@ onBeforeUnmount(() => observer?.disconnect());
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
v-if="!(screen === 'story' && localOnly)"
|
||||
v-if="!localOnly"
|
||||
class="tbtn hide-m"
|
||||
type="button"
|
||||
:aria-label="t('Share')"
|
||||
|
||||
@@ -430,6 +430,14 @@ const schemas = [
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'open_stories',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
properties: {},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'control_scene',
|
||||
parameters: {
|
||||
|
||||
@@ -59,7 +59,8 @@ test('the complete Realtime tool payload pins the manifest-generated layer relea
|
||||
// move_camera tilt takes an optional pitchDeg angle, described as
|
||||
// absolute with its -45 default, with steps sent as a direction.
|
||||
// show_street_level (map, source, photo) adds one tool.
|
||||
'0c27f62062001e6a07241cd301c3d357f55e9b74f66cd2904d16590510337468',
|
||||
// open_stories adds the Stories Explore entry action.
|
||||
'5a2deb65bef5db8fa49ee55dd66efb884e7c3ba97dbdcaad3fada087170d2225',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -157,6 +158,7 @@ test('all legacy action arguments are byte-identical after removing the delibera
|
||||
'find_imagery',
|
||||
'osm_query',
|
||||
'show_street_level',
|
||||
'open_stories',
|
||||
].includes(tool.name),
|
||||
);
|
||||
// Layer enums are generated from the voice layer manifest and pinned by
|
||||
|
||||
@@ -3,6 +3,7 @@ import { t, translateKnown } from '../i18n/index.js';
|
||||
import { msg } from '../i18n/marker.js';
|
||||
import { createGeminiAudio } from './geminiAudio.js';
|
||||
import { RealtimeInput } from './realtimeInput.js';
|
||||
import { isStoriesOpen } from './realtimeInputPolicy.js';
|
||||
import { RealtimeRadio } from './realtimeRadio.js';
|
||||
import { captureViewportImage } from './realtimeViewport.js';
|
||||
import { createNarrationScheduler } from './narration.js';
|
||||
@@ -652,7 +653,13 @@ export class GeminiSessionController {
|
||||
}
|
||||
|
||||
async start({ pushToTalk = false } = {}) {
|
||||
if (this.disposed || this.isActive() || this.signal?.aborted) return;
|
||||
if (
|
||||
isStoriesOpen() ||
|
||||
this.disposed ||
|
||||
this.isActive() ||
|
||||
this.signal?.aborted
|
||||
)
|
||||
return;
|
||||
const held = pushToTalk && this.input.pushToTalkKeyHeld;
|
||||
const spaceHeld = this.input.spaceKeyHeld;
|
||||
this.stop({ preserveStatus: true });
|
||||
|
||||
+47
-6
@@ -8,6 +8,7 @@ import {
|
||||
import { readLayerLifecycleSummary } from './layerSummary.js';
|
||||
import { SPEECH_BUILDERS, attachVoiceResult } from './speech.js';
|
||||
import { resolveDeicticArgs } from './deixis.js';
|
||||
import { isStoriesOpen } from './realtimeInputPolicy.js';
|
||||
export { readLayerLifecycleSummary } from './layerSummary.js';
|
||||
import { defaultGeospatial } from '../search/defaults.js';
|
||||
import { msg } from '../i18n/index.js';
|
||||
@@ -294,6 +295,7 @@ export function createGevActionRunner({
|
||||
styleManager,
|
||||
dataManager,
|
||||
sceneDirector = null,
|
||||
openStories = null,
|
||||
annotations = null,
|
||||
placeSearch = unavailablePlaceSearch,
|
||||
floorServices = defaultFloorServices,
|
||||
@@ -444,9 +446,51 @@ export function createGevActionRunner({
|
||||
runOptions = {},
|
||||
) {
|
||||
const args = rawArgs && typeof rawArgs === 'object' ? rawArgs : {};
|
||||
// Stories covers GEV and owns its camera and scenes: an open-mic session
|
||||
// must not fly, load or change what is behind it.
|
||||
if (globalThis.document?.body?.classList?.contains?.('stories-mode'))
|
||||
const current = () =>
|
||||
!runOptions.signal?.aborted &&
|
||||
(typeof runOptions.isCurrent !== 'function' || runOptions.isCurrent());
|
||||
if (name === 'open_stories') {
|
||||
const denied = { ok: false, action: name, applied: false };
|
||||
const cancelled = {
|
||||
...denied,
|
||||
code: 'CANCELLED',
|
||||
cancelled: true,
|
||||
error: 'This request was superseded.',
|
||||
};
|
||||
if (!current()) return cancelled;
|
||||
if (typeof openStories !== 'function')
|
||||
return {
|
||||
...denied,
|
||||
unavailable: true,
|
||||
error: 'Stories is unavailable in this host.',
|
||||
say: 'Stories is unavailable in this host.',
|
||||
};
|
||||
// Opening Stories can stop the voice session that requested it. The
|
||||
// action was applied even when that session is no longer current.
|
||||
const opened = await openStories({ isCurrent: current });
|
||||
if (opened === true)
|
||||
return {
|
||||
ok: true,
|
||||
action: name,
|
||||
applied: true,
|
||||
say: 'Stories is open.',
|
||||
};
|
||||
if (!current()) return cancelled;
|
||||
if (opened === 'already-open')
|
||||
return {
|
||||
ok: true,
|
||||
action: name,
|
||||
applied: false,
|
||||
say: 'Stories is already open.',
|
||||
};
|
||||
return {
|
||||
...denied,
|
||||
error: 'Stories could not be opened.',
|
||||
say: 'Stories could not be opened.',
|
||||
};
|
||||
}
|
||||
// Stories owns the camera and scenes. Leave the globe behind it alone.
|
||||
if (isStoriesOpen())
|
||||
return {
|
||||
ok: false,
|
||||
action: name,
|
||||
@@ -455,9 +499,6 @@ export function createGevActionRunner({
|
||||
error: 'Stories is open. Close Stories first.',
|
||||
say: 'Stories is open. Close Stories first to control the globe.',
|
||||
};
|
||||
const current = () =>
|
||||
!runOptions.signal?.aborted &&
|
||||
(typeof runOptions.isCurrent !== 'function' || runOptions.isCurrent());
|
||||
// Step reports for voice narration and the voice card; never fatal.
|
||||
const reportProgress = (step, label = '') => {
|
||||
try {
|
||||
|
||||
@@ -270,6 +270,7 @@ test('voice changes nothing behind Stories while it is open', async () => {
|
||||
camera: { moveEnd: { addEventListener() {} } },
|
||||
};
|
||||
let calls = 0;
|
||||
let storiesVisible = true;
|
||||
const styleManager = {
|
||||
async resetToGlobeView() {
|
||||
calls += 1;
|
||||
@@ -280,6 +281,7 @@ test('voice changes nothing behind Stories while it is open', async () => {
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
openStories: () => (storiesVisible ? 'already-open' : true),
|
||||
});
|
||||
const classes = new Set(['stories-mode']);
|
||||
const priorDocument = globalThis.document;
|
||||
@@ -291,7 +293,16 @@ test('voice changes nothing behind Stories while it is open', async () => {
|
||||
const refused = await runner('zoom_to_globe');
|
||||
assert.equal(refused.ok, false);
|
||||
assert.equal(refused.refused, 'stories-open');
|
||||
const alreadyOpen = await runner('open_stories');
|
||||
assert.equal(alreadyOpen.ok, true);
|
||||
assert.equal(alreadyOpen.applied, false);
|
||||
assert.equal(calls, 0);
|
||||
// The input guard still owns the globe while the director settles.
|
||||
storiesVisible = false;
|
||||
const reopened = await runner('open_stories');
|
||||
assert.equal(reopened.ok, true);
|
||||
assert.equal(reopened.applied, true);
|
||||
assert.equal((await runner('zoom_to_globe')).refused, 'stories-open');
|
||||
classes.clear();
|
||||
await runner('zoom_to_globe');
|
||||
assert.equal(calls, 1, 'works again once Stories has closed');
|
||||
@@ -300,6 +311,47 @@ test('voice changes nothing behind Stories while it is open', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('opening Stories only admits current requests and can stop its own session', async () => {
|
||||
const { viewer, styleManager } = createVoiceNavigationHarness();
|
||||
const first = new AbortController();
|
||||
let loaded = Promise.resolve();
|
||||
let admitted = 0;
|
||||
let opened = 0;
|
||||
const runner = createGevActionRunner({
|
||||
viewer,
|
||||
styleManager,
|
||||
dataManager: { layers: new Map(), getAll: () => [] },
|
||||
async openStories({ isCurrent }) {
|
||||
admitted += 1;
|
||||
await loaded;
|
||||
if (!isCurrent()) return false;
|
||||
opened += 1;
|
||||
first.abort();
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
const applied = await runner('open_stories', {}, { signal: first.signal });
|
||||
assert.equal(applied.ok, true);
|
||||
assert.equal(applied.applied, true);
|
||||
|
||||
const stale = await runner('open_stories', {}, { signal: first.signal });
|
||||
assert.equal(stale.cancelled, true);
|
||||
assert.equal(admitted, 1);
|
||||
|
||||
let finishLoading;
|
||||
loaded = new Promise((resolve) => { finishLoading = resolve; });
|
||||
const second = new AbortController();
|
||||
const pending = runner('open_stories', {}, { signal: second.signal });
|
||||
assert.equal(admitted, 2);
|
||||
second.abort();
|
||||
finishLoading();
|
||||
const canceled = await pending;
|
||||
assert.equal(canceled.cancelled, true);
|
||||
assert.equal(canceled.applied, false);
|
||||
assert.equal(opened, 1);
|
||||
});
|
||||
|
||||
test('dependent voice navigation waits for the destination viewport to arrive', async () => {
|
||||
globalThis.window = globalThis.window || {
|
||||
clearTimeout,
|
||||
|
||||
@@ -358,6 +358,34 @@ test('push-to-talk rechecks focus before the hold threshold claims voice', (t) =
|
||||
assert.equal(f.controller.spaceKeyHeld, false);
|
||||
});
|
||||
|
||||
test('opening Stories cancels a pending Space hold even when focus stays put', (t) => {
|
||||
const f = createPushToTalkFixture(t);
|
||||
const background = pushToTalkTarget();
|
||||
const classes = new Set();
|
||||
f.document.body = { classList: { contains: (name) => classes.has(name) } };
|
||||
|
||||
f.key('keydown', background);
|
||||
classes.add('stories-mode');
|
||||
f.advance(PUSH_TO_TALK_HOLD_DELAY_MS);
|
||||
assert.deepEqual(f.starts, []);
|
||||
assert.deepEqual(f.radio, []);
|
||||
assert.equal(f.controller.spaceKeyHeld, false);
|
||||
assert.equal(f.timers.size, 0);
|
||||
|
||||
classes.delete('stories-mode');
|
||||
f.key('keydown', background);
|
||||
f.advance(PUSH_TO_TALK_HOLD_DELAY_MS);
|
||||
assert.equal(f.microphone.enabled, true);
|
||||
f.key('keyup', background);
|
||||
assert.equal(f.microphone.enabled, false);
|
||||
|
||||
f.key('keydown', background);
|
||||
classes.add('stories-mode');
|
||||
f.advance(PUSH_TO_TALK_HOLD_DELAY_MS);
|
||||
assert.equal(f.starts.length, 1);
|
||||
assert.equal(f.microphone.enabled, false);
|
||||
});
|
||||
|
||||
test('push-to-talk never claims a control-started hold after focus moves outside', (t) => {
|
||||
const f = createPushToTalkFixture(t);
|
||||
const control = pushToTalkTarget({ tagName: 'BUTTON' });
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
import { isStoriesOpen } from './realtimeInputPolicy.js';
|
||||
|
||||
const DISCONNECT_GRACE_MS = 6000;
|
||||
|
||||
@@ -52,7 +53,8 @@ export class RealtimeConnection {
|
||||
return this.readStatus();
|
||||
}
|
||||
async start({ pushToTalk = false } = {}) {
|
||||
if (this.isActive() || this.lifetimeSignal?.aborted) return;
|
||||
if (isStoriesOpen() || this.isActive() || this.lifetimeSignal?.aborted)
|
||||
return;
|
||||
this.pauseRadioForVoice();
|
||||
const pushToTalkKeyHeld = pushToTalk && this.input.pushToTalkKeyHeld;
|
||||
const spaceKeyHeld = this.input.spaceKeyHeld;
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
PUSH_TO_TALK_HOLD_DELAY_MS,
|
||||
MICROPHONE_VISUALIZER_GATE,
|
||||
ASSISTANT_VISUALIZER_GATE,
|
||||
isStoriesOpen,
|
||||
isPushToTalkKey,
|
||||
SPACE_INTERACTIVE_SELECTOR,
|
||||
isInteractiveSpaceTarget,
|
||||
@@ -59,7 +60,7 @@ export class RealtimeInput {
|
||||
// Stories owns the keyboard (body.stories-mode).
|
||||
if (
|
||||
this.ui.state?.chat?.open === true ||
|
||||
globalThis.document?.body?.classList?.contains?.('stories-mode') ||
|
||||
isStoriesOpen() ||
|
||||
!shouldHandlePushToTalkKeyDown(event)
|
||||
)
|
||||
return;
|
||||
@@ -95,6 +96,10 @@ export class RealtimeInput {
|
||||
this.pushToTalkHoldTimer = null;
|
||||
if (holdGeneration !== this.pushToTalkHoldGeneration) return;
|
||||
if (!this.spaceKeyHeld || this.pushToTalkKeyHeld) return;
|
||||
if (isStoriesOpen()) {
|
||||
this.shortcutBlurHandler();
|
||||
return;
|
||||
}
|
||||
// A pointer or Tab focus change during the delay cancels the original
|
||||
// gesture rather than letting voice claim a key held for another owner.
|
||||
if (document.activeElement !== this.pushToTalkHoldFocusOwner) return;
|
||||
|
||||
@@ -9,6 +9,13 @@ export const MICROPHONE_VISUALIZER_GATE = 0.12;
|
||||
|
||||
export const ASSISTANT_VISUALIZER_GATE = 0.04;
|
||||
|
||||
/** Stories takes keyboard and microphone ownership away from voice. */
|
||||
export function isStoriesOpen() {
|
||||
return (
|
||||
globalThis.document?.body?.classList?.contains?.('stories-mode') ?? false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a keyboard event represents the hold-Space voice shortcut.
|
||||
* @param {KeyboardEvent|object|null} event
|
||||
|
||||
+12
-2
@@ -5,7 +5,12 @@
|
||||
* Events: state, transcript, action-call, progress, action-result, interruption,
|
||||
* completion, turn-metrics.
|
||||
*/
|
||||
export function createVoiceSession({ createAdapter, runner, signal }) {
|
||||
export function createVoiceSession({
|
||||
createAdapter,
|
||||
runner,
|
||||
signal,
|
||||
canStart,
|
||||
}) {
|
||||
if (typeof createAdapter !== 'function' || typeof runner !== 'function')
|
||||
throw new TypeError('Voice requires an adapter factory and action runner');
|
||||
const lifetime = new AbortController();
|
||||
@@ -146,7 +151,12 @@ export function createVoiceSession({ createAdapter, runner, signal }) {
|
||||
return () => listeners.delete(listener);
|
||||
},
|
||||
async start(options) {
|
||||
if (disposed || !['idle', 'error'].includes(state)) return;
|
||||
if (
|
||||
disposed ||
|
||||
!['idle', 'error'].includes(state) ||
|
||||
canStart?.(options) === false
|
||||
)
|
||||
return;
|
||||
const attempt = ++startAttempt;
|
||||
emit({ type: 'state', state: 'connecting' });
|
||||
if (disposed || attempt !== startAttempt) return;
|
||||
|
||||
@@ -429,12 +429,13 @@ test('a late rejection cannot settle a newer turn card', async () => {
|
||||
f.session.destroy();
|
||||
});
|
||||
|
||||
function startReentrancyFixture() {
|
||||
function startReentrancyFixture(canStart) {
|
||||
let starts = 0;
|
||||
let stops = 0;
|
||||
const settings = [];
|
||||
const session = createVoiceSession({
|
||||
runner: async () => ({ ok: true }),
|
||||
canStart,
|
||||
createAdapter: ({ emit }) => ({
|
||||
async start(options) {
|
||||
starts++;
|
||||
@@ -515,9 +516,18 @@ test('Stop and explicit reentrant successor start acquire only for the successor
|
||||
f.session.destroy();
|
||||
});
|
||||
|
||||
test('ordinary start forwards caller settings once and remains stoppable', async () => {
|
||||
const f = startReentrancyFixture();
|
||||
const settings = { pushToTalk: true };
|
||||
test('start admission rejects microphone use before connecting and allows typed chat', async () => {
|
||||
const f = startReentrancyFixture((options) => options?.textOnly === true);
|
||||
const states = [];
|
||||
f.session.subscribe((event) => {
|
||||
if (event.type === 'state') states.push(event.state);
|
||||
});
|
||||
await f.session.start({ pushToTalk: true });
|
||||
assert.equal(f.starts(), 0);
|
||||
assert.equal(f.session.state, 'idle');
|
||||
assert.equal(states.includes('connecting'), false);
|
||||
|
||||
const settings = { textOnly: true };
|
||||
await f.session.start(settings);
|
||||
assert.equal(f.settings.length, 1);
|
||||
assert.equal(f.settings[0], settings);
|
||||
|
||||
@@ -34,6 +34,7 @@ export function createVoiceCommands({
|
||||
supportedProviders,
|
||||
onProviderChange,
|
||||
onSessionEvent,
|
||||
canStartVoice,
|
||||
createCard = (options) => new VoiceCardControls(options),
|
||||
pointer = null,
|
||||
referents = null,
|
||||
@@ -49,6 +50,7 @@ export function createVoiceCommands({
|
||||
let panelMount;
|
||||
const session = createVoiceSession({
|
||||
runner,
|
||||
canStart: (options) => options?.textOnly || canStartVoice?.() !== false,
|
||||
signal,
|
||||
createAdapter: (hooks) => {
|
||||
if (panelHost) actionObserver = panelHost.observeActions(hooks);
|
||||
@@ -284,7 +286,7 @@ export function createVoiceCommands({
|
||||
void session.start({ pushToTalk: false });
|
||||
};
|
||||
const buttonHandler = () => {
|
||||
if (adapter.ignoreButtonClick?.()) return;
|
||||
if (canStartVoice?.() === false || adapter.ignoreButtonClick?.()) return;
|
||||
chat?.close();
|
||||
if (session.isActive() && adapter.getStartOptions?.().textOnly) {
|
||||
session.stop();
|
||||
|
||||
@@ -1070,6 +1070,7 @@ const STEP_TITLES = Object.freeze({
|
||||
set_detection: msg('Adjust detection overlay'),
|
||||
set_map_stack: msg('Change map stack'),
|
||||
set_post_processing: msg('Adjust post-processing'),
|
||||
open_stories: msg('Stories'),
|
||||
control_scene: msg('Control scene'),
|
||||
control_cctv: msg('Control CCTV'),
|
||||
control_radio: msg('Control radio'),
|
||||
|
||||
Reference in new issue
Block a user