Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

1.2 KB
Raw Blame
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() {
      if (controller.ui.tierButton) {
        controller.tierHandler = () => controller.toggleVoiceTier();
        controller.ui.tierButton.addEventListener(
          'click',
          controller.tierHandler,
        );
      }
      controller.syncCostUi();
      controller.bindPushToTalkShortcut();
    },
  };
}