Skip to main content

Viewport Mode Detection API

The clientViewportMode utility provides automatic detection of different viewport modes for conditional rendering and optimization.

Location

packages/shared/src/runtime/clientViewportMode.ts

Functions

isStreamPageRoute(win?: Window): boolean

Detects if the client is running in streaming capture mode. Returns: true if running on /stream.html or with ?page=stream query parameter. Usage:
Detection Logic:
  • Checks if pathname ends with /stream.html
  • Checks if ?page=stream query parameter is present
  • Case-insensitive matching

isEmbeddedSpectatorViewport(win?: Window): boolean

Detects if the client is running as an embedded spectator (e.g., in betting app iframe). Returns: true if running with ?embedded=true&mode=spectator or configured via __HYPERSCAPE_EMBEDDED__ and __HYPERSCAPE_CONFIG__. Usage:
Detection Logic:
  • Checks ?embedded=true&mode=spectator query parameters
  • Checks window.__HYPERSCAPE_EMBEDDED__ === true and window.__HYPERSCAPE_CONFIG__.mode === 'spectator'
  • Supports both URL-based and programmatic configuration

isStreamingLikeViewport(win?: Window): boolean

Detects any streaming-like viewport (streaming capture or embedded spectator). Returns: true if either isStreamPageRoute() or isEmbeddedSpectatorViewport() returns true. Usage:

Streaming Entry Points

Main Game Entry

File: packages/client/src/index.htmldist/index.html Purpose: Full game client with all UI features and player controls. URL: http://localhost:3333/ or https://hyperscape.gg/

Streaming Capture Entry

File: packages/client/src/stream.htmldist/stream.html Purpose: Optimized for RTMP streaming capture with minimal UI overhead. URL: http://localhost:3333/stream.html or http://localhost:3333/?page=stream Features:
  • Minimal UI (no panels, no controls)
  • Optimized rendering for streaming
  • Automatic viewport mode detection
  • Separate bundle for faster loading
Vite Configuration:

Environment Variables

Streaming Capture Configuration

Stream Destination Auto-Detection

Implementation Example

Conditional Rendering

Browser Compatibility

WebGPU Requirements

All viewport modes require WebGPU support:

Server/Streaming Requirements

For Vast.ai and GPU server deployments:
  • NVIDIA GPU with Display Driver - Must have gpu_display_active=true
  • Chrome Beta Channel - google-chrome-beta for stability
  • ANGLE Backend - Use --use-angle=default (NOT Vulkan)
  • Xvfb Virtual Display - Required for headless servers
  • PM2 Environment - Explicit DISPLAY=:99 forwarding
  • AGENTS.md - Streaming pipeline fixes and recent changes
  • CLAUDE.md - WebGPU requirements and development guidelines
  • docs/duel-stack.md - Duel stack configuration and streaming setup
  • packages/server/.env.example - Complete streaming configuration reference