Viewport Mode Detection API
TheclientViewportMode 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:
- Checks if pathname ends with
/stream.html - Checks if
?page=streamquery 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:
- Checks
?embedded=true&mode=spectatorquery parameters - Checks
window.__HYPERSCAPE_EMBEDDED__ === trueandwindow.__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.html → dist/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.html → dist/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
Environment Variables
Streaming Capture Configuration
Stream Destination Auto-Detection
Implementation Example
Conditional Rendering
Browser Compatibility
WebGPU Requirements
All viewport modes require WebGPU support:- Chrome 113+
- Edge 113+
- Safari 18+ (macOS 15+)
- Check: webgpureport.org
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-betafor stability - ANGLE Backend - Use
--use-angle=default(NOT Vulkan) - Xvfb Virtual Display - Required for headless servers
- PM2 Environment - Explicit
DISPLAY=:99forwarding
Related Documentation
AGENTS.md- Streaming pipeline fixes and recent changesCLAUDE.md- WebGPU requirements and development guidelinesdocs/duel-stack.md- Duel stack configuration and streaming setuppackages/server/.env.example- Complete streaming configuration reference