Overview
Hyperscape includes a production-ready streaming infrastructure for broadcasting AI vs AI duel arena matches to multiple platforms simultaneously (Twitch, Kick, X/Twitter, YouTube).Architecture
Components
| Component | Purpose |
|---|---|
| Stream Entry Point | Dedicated stream.html / stream.tsx for optimized capture |
| CDP Capture | Chrome DevTools Protocol for frame capture |
| RTMP Bridge | FFmpeg multiplexer for multi-platform streaming |
| Viewer Access Control | Token-based access for trusted viewers |
| Stream Destinations | Auto-detection and management of RTMP endpoints |
Stream Entry Points
Dedicated Stream Client
Hyperscape includes dedicated entry points optimized for streaming capture: Files:packages/client/src/stream.html- HTML entry pointpackages/client/src/stream.tsx- React streaming clientpackages/client/vite.config.ts- Multi-page build configuration
- Optimized for headless browser capture
- Minimal UI overhead
- WebGPU-optimized rendering
- Separate from main game client
Client Viewport Mode Detection
TheclientViewportMode utility detects the current rendering mode:
- Disable UI elements in stream mode
- Optimize rendering for capture
- Enable spectator-specific features
Stream Capture
Chrome DevTools Protocol (CDP)
Hyperscape uses CDP for high-performance frame capture: Configuration:WebGPU Buffer Upload Fallback
HandlesmappedAtCreation failures gracefully:
RTMP Streaming
Stream Destinations
Hyperscape supports multiple RTMP destinations with auto-detection: Supported Platforms:- Twitch
- Kick (RTMPS)
- X/Twitter
- YouTube (deprecated)
- Custom RTMP servers
FFmpeg RTMP Bridge
The RTMP bridge multiplexes a single stream to multiple destinations: Features:- Single encode, multiple outputs (tee muxer)
- Per-destination stream keys
- Automatic reconnection
- Health monitoring
Viewer Access Control
Streaming Viewer Access Tokens
Secure access control for live streaming viewers: Configuration:- Loopback Viewers: Always allowed (localhost connections)
- Trusted Viewers: Require access token
- Public Viewers: Subject to public delay
Public Delay
Configure delay for public streaming viewers:- YouTube: 15000ms (15 seconds)
- Twitch: 12000ms (12 seconds)
- HLS: 4000ms (4 seconds)
Deployment
Vast.ai Deployment
Enhanced Vast.ai deployment with remote database support: Auto-Detection:- Prevents stale stream keys from shell environment
- Ensures PM2 picks up correct keys from .env file
- Required for CI/CD deployments
PM2 Configuration
Production deployment uses PM2 for process management:GitHub Actions Integration
Stream keys passed through CI/CD:Duel Oracle Configuration
Oracle System
The duel oracle publishes verifiable duel outcomes to blockchain: Configuration:Oracle Fields
New Fields (Commit aecab58):damageA- Total damage dealt by participant AdamageB- Total damage dealt by participant BwinReason- Reason for victory (“knockout”, “timeout”, “forfeit”)seed- Cryptographic seed for replay verificationreplayHashHex- Hash of replay data for integrity verificationresultHashHex- Combined hash of all duel outcome data
EVM Oracle Targets
Solana Oracle Targets
Local Oracle Testing
Running Streaming Duels
Full Duel Stack
Start the complete streaming duel system:- Game server with streaming duel scheduler
- Duel matchmaker bots (AI agents fighting each other)
- RTMP bridge for multi-platform streaming
- Local HLS stream for web playback
Stream-Only Mode
Run streaming without betting:Local Testing
Test streaming locally without external platforms:Monitoring
Stream Health
Monitor stream health via API:Diagnostics
Troubleshooting
Stream Not Appearing
Check stream keys:WebGPU Initialization Failures
Check GPU support:- NVIDIA GPU with display driver (
gpu_display_active=true) - Xorg or Xvfb (not headless)
- Chrome uses ANGLE/Vulkan for WebGPU
FFmpeg Errors
Check FFmpeg installation:Best Practices
Security
- Never commit stream keys - Use environment variables only
- Rotate keys regularly - Generate new keys monthly
- Use viewer access tokens - Protect live stream access
- Monitor unauthorized access - Check viewer logs
Performance
- Use production client build - Set
DUEL_USE_PRODUCTION_CLIENT=true - Optimize capture resolution - 1280x720 recommended for 30fps
- Monitor CPU usage - FFmpeg encoding is CPU-intensive
- Use hardware encoding - Enable GPU encoding if available
Reliability
- Enable auto-restart - PM2 handles process crashes
- Monitor stream health - Use
/api/streaming/statusendpoint - Test before going live - Use local RTMP server for testing
- Have fallback plan - Keep backup stream keys ready