Files
gods-eye-view/src/voice/realtimeSession.js
T
Sameh Khamis b20c80e590 Switch language in place, without a reload
Choosing a language in the picker now applies it at once. The choice is
stored and ?lang is kept in step through replaceState, and the picker keeps
focus.

Code that writes translated text itself re-presents it on a switch:
onLocaleChange() lets an owner listen, removed at teardown, and status
writers hand over a function of the locale (voice cards, scene director,
SDR, draw hints, imagery split, map sources, Bhote Koshi media) so the
words are rebuilt rather than re-sent. The HUD, cockpit, radio, CCTV,
launch, awareness and credit texts follow the same hook, and
applyDocumentTranslations can be applied again without undoing text code
wrote since.

The unsaved-work registry and persistLocaleAndReload existed only to guard
the reload, so they go, with their catalog entries.
2026-11-01 16:47:39 -08:00

42 lines
1.4 KiB
JavaScript

import { GevRealtimeController } from './realtimeController.js';
/** Adapt the existing WebRTC implementation to the common voice session. */
export function createRealtimeSession({
emit,
runAction,
createController = (options) => new GevRealtimeController(options),
...options
}) {
const controller = createController({
...options,
actionExecutor: runAction,
onSessionEvent: emit,
});
return {
controller,
capabilities: { costControls: true, pushToTalk: true },
start: (settings) => controller.start(settings),
getStartOptions: () => ({ pushToTalk: Boolean(controller.pushToTalkMode) }),
stop: (settings) => controller.stop(settings),
sendText: (text) => controller.sendTextCommand(text),
sendMapEvent: (event) => controller.notifyMapEvent(event),
ignoreButtonClick: () => Boolean(controller.spaceKeyHeld),
bindControls() {
// Kept as the remover; a full stop releases it. The cost readout and
// tier toggle are worded again in a new locale.
const offTier = controller.ui.on('tier', () =>
controller.toggleVoiceTier(),
);
const offLocale = controller.ui.on('locale', () =>
controller.syncCostUi(),
);
controller.tierHandler = () => {
offTier();
offLocale();
};
controller.syncCostUi();
controller.bindPushToTalkShortcut();
},
};
}