Skip to main content

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

Stream Entry Points

Dedicated Stream Client

Hyperscape includes dedicated entry points optimized for streaming capture: Files:
  • packages/client/src/stream.html - HTML entry point
  • packages/client/src/stream.tsx - React streaming client
  • packages/client/vite.config.ts - Multi-page build configuration
Features:
  • Optimized for headless browser capture
  • Minimal UI overhead
  • WebGPU-optimized rendering
  • Separate from main game client
Access:

Client Viewport Mode Detection

The clientViewportMode utility detects the current rendering mode:
Use Cases:
  • 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

Handles mappedAtCreation failures gracefully:
Impact: Improves WebGPU stability on various GPU drivers.

RTMP Streaming

Stream Destinations

Hyperscape supports multiple RTMP destinations with auto-detection: Supported Platforms:
  • Twitch
  • Kick (RTMPS)
  • X/Twitter
  • YouTube (deprecated)
  • Custom RTMP servers
Auto-Detection:
Explicit Destination Control:

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
Configuration:

Viewer Access Control

Streaming Viewer Access Tokens

Secure access control for live streaming viewers: Configuration:
Access Levels:
  1. Loopback Viewers: Always allowed (localhost connections)
  2. Trusted Viewers: Require access token
  3. Public Viewers: Subject to public delay
Implementation:
Usage:

Public Delay

Configure delay for public streaming viewers:
Platform Defaults:
  • 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:
Stream Key Management:
Why This Matters:
  • 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 A
  • damageB - Total damage dealt by participant B
  • winReason - Reason for victory (“knockout”, “timeout”, “forfeit”)
  • seed - Cryptographic seed for replay verification
  • replayHashHex - Hash of replay data for integrity verification
  • resultHashHex - Combined hash of all duel outcome data
Database Schema:

EVM Oracle Targets

Solana Oracle Targets

Local Oracle Testing

Running Streaming Duels

Full Duel Stack

Start the complete streaming duel system:
This starts:
  • 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
Options:

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:
Check PM2 environment:

WebGPU Initialization Failures

Check GPU support:
Vast.ai Requirements:
  • 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:
Check RTMP connectivity:

Best Practices

Security

  1. Never commit stream keys - Use environment variables only
  2. Rotate keys regularly - Generate new keys monthly
  3. Use viewer access tokens - Protect live stream access
  4. Monitor unauthorized access - Check viewer logs

Performance

  1. Use production client build - Set DUEL_USE_PRODUCTION_CLIENT=true
  2. Optimize capture resolution - 1280x720 recommended for 30fps
  3. Monitor CPU usage - FFmpeg encoding is CPU-intensive
  4. Use hardware encoding - Enable GPU encoding if available

Reliability

  1. Enable auto-restart - PM2 handles process crashes
  2. Monitor stream health - Use /api/streaming/status endpoint
  3. Test before going live - Use local RTMP server for testing
  4. Have fallback plan - Keep backup stream keys ready

AI Agents

Learn about ElizaOS agent integration

Deployment

Deploy to production environments

Configuration

Environment variable reference

Duel Arena

Duel arena system documentation