Skip to main content

Streaming & Betting System Guide

Complete guide to Hyperscape’s live streaming duel arena with Solana betting integration.

Overview

Hyperscape features a fully automated streaming duel system where AI agents fight each other in real-time while viewers bet on outcomes using Solana CLOB markets. Key Components:
  • Streaming Duel Scheduler - Orchestrates duel cycles (announcement → fighting → resolution)
  • DuelCombatAI - Controls agent combat behavior with LLM-powered trash talk
  • RTMP Bridge - Captures gameplay and streams to Twitch/YouTube/etc.
  • Betting App - Web UI for placing bets on duel outcomes
  • Keeper Bot - Automates market operations (initialize, resolve, claim)
  • Market Maker Bot - Provides liquidity with duel signal integration

Quick Start

Local Development (Devnet)

Start the complete stack with one command:
This starts:
  1. Game server with streaming duel scheduler
  2. Duel matchmaker bots (4 AI agents)
  3. RTMP bridge for streaming
  4. Local HLS stream at http://localhost:5555/live/stream.m3u8
  5. Betting app at http://localhost:4179
  6. Keeper bot for automated market operations

Configuration

Required Environment Variables: packages/server/.env:
Optional RTMP Streaming: packages/server/.env:

Streaming Duel Scheduler

Location: packages/server/src/systems/StreamingDuelScheduler/ Orchestrates automated duel cycles with camera direction and state management.

Duel Cycle Phases

  1. Announcement (30s default)
    • Display upcoming duel matchup
    • Show agent stats and equipment
    • Allow betting window to open
  2. Fighting (150s default)
    • Agents engage in combat
    • Camera follows action
    • Real-time HP updates
    • Trash talk messages
  3. End Warning (10s default)
    • Display imminent duel end
    • Final betting window
  4. Resolution (5s default)
    • Declare winner
    • Settle bets
    • Award points

Configuration

Environment Variables:

Camera Director

Location: packages/server/src/systems/StreamingDuelScheduler/managers/CameraDirector.ts Automatically positions the camera for optimal viewing: Camera Modes:
  • Overview - Wide shot of entire arena (announcement phase)
  • Combat Follow - Tracks both fighters (fighting phase)
  • Victory - Focuses on winner (resolution phase)
Camera Positioning:

DuelCombatAI System

Location: packages/server/src/arena/DuelCombatAI.ts Tick-based PvP combat controller for embedded agents with LLM-powered trash talk.

Combat Behavior

Decision Priority:
  1. Heal - Eat food when HP < threshold
  2. Buff - Use potions in opening phase
  3. Prayer - Activate offensive/defensive prayers
  4. Style Switch - Change attack style based on phase
  5. Attack - Execute attacks at weapon speed cadence
Combat Phases:
  • opening - First 5 ticks, activate buffs
  • trading - Normal combat, balanced approach
  • finishing - Opponent < 25% HP, aggressive
  • desperate - Self < 30% HP, defensive

Trash Talk System

Added in commit 8ff3ad3 AI agents generate contextual trash talk during combat using LLMs or scripted fallbacks. Triggers:
  1. Health Milestones - When HP crosses 75%, 50%, 25%, 10%
    • Own HP: “Not even close!”, “I’ve had worse”
    • Opponent HP: “GG soon”, “You’re done!”
  2. Ambient Taunts - Random periodic messages every 15-25 ticks
    • “Let’s go!”, “Fight me!”, “Too slow”
LLM Integration:
Cooldown:
  • 8 seconds between trash talk messages
  • Prevents spam and rate limiting
  • Fire-and-forget (never blocks combat tick)
Configuration:

LLM Combat Strategy

Optional Feature - Agents can use LLMs to plan combat strategy. Strategy Planning:
Replanning Triggers:
  • Fight start (initial strategy)
  • HP change > 20%
  • Opponent HP < 25% (switch to aggressive)
  • Self HP < 30% (switch to defensive)
Configuration:
Performance:
  • Strategy planning is fire-and-forget (never blocks tick)
  • 8-second minimum interval between replans
  • 3-second LLM timeout (falls back to current strategy)
  • Agents execute latest strategy every tick

RTMP Streaming

Location: packages/server/src/streaming/ Multi-platform RTMP streaming with local HLS fanout.

Supported Platforms

  • Twitch - rtmp://live.twitch.tv/app
  • YouTube - rtmp://a.rtmp.youtube.com/live2
  • Kick - rtmp://ingest.kick.com/live
  • Pump.fun - Limited access streaming
  • X/Twitter - Requires Premium subscription
  • Custom RTMP - Any RTMP server
  • RTMP Multiplexer - Restream, Livepeer, etc.

Configuration

Environment Variables:

Capture Modes

CDP (Chrome DevTools Protocol):
  • Default on macOS
  • Uses Chrome’s native screen capture
  • Lower CPU overhead
  • Best for desktop development
WebCodecs:
  • Default on Linux
  • Uses WebCodecs API for encoding
  • Better performance on headless servers
  • Recommended for production streaming
Configuration:

Rendering Backends

Vulkan:
  • Default backend
  • Best performance on modern GPUs
  • May crash on broken ICD (RTX 5060 Ti)
OpenGL ANGLE:
  • Fallback for broken Vulkan
  • Stable on all hardware
  • Slightly lower performance
SwiftShader:
  • Software rendering (CPU)
  • Slowest but most compatible
  • Use when GPU is unavailable
Configuration:

HLS Output

Local HLS Stream:
  • Default: packages/server/public/live/stream.m3u8
  • Accessible at: http://localhost:5555/live/stream.m3u8
  • Used by betting app for embedded video player
Configuration:

Streaming Stability

Fixes Applied (commits f3aa787, ae42beb, 5e4c6f1, 30cacb0):
  1. Vulkan ICD Crashes - Use GL ANGLE backend on RTX 5060 Ti
  2. FFmpeg SIGSEGV - Use system FFmpeg instead of static build
  3. WebGPU Unavailable - Use Chrome Dev channel on Vast.ai
  4. GPU Compositing - Use headful mode with Xvfb on Linux
Environment Variables:

Solana Betting Integration

CLOB Market (Mainnet)

Commits: dba3e03, 35c14f9 The betting system uses a Central Limit Order Book (CLOB) market on Solana mainnet. Mainnet Program IDs:

Keeper Bot

Location: packages/gold-betting-demo/keeper/ Automates market operations for duel betting. CLOB Instructions:
  • initializeConfig - Set up market configuration
  • initializeMatch - Create new duel match
  • initializeOrderBook - Initialize order book for match
  • resolveMatch - Settle match and distribute payouts
Environment Variables:
Behavior:
  • Polls /api/streaming/state for duel status
  • Initializes markets when duel announced
  • Resolves markets when duel completes
  • Warns and backs off when signer funding is low

Market Maker Bot

Location: packages/market-maker-bot/ Provides liquidity to CLOB markets with duel signal integration. Features:
  • Duel HP signal integration (0.9 weight)
  • HP edge multiplier (0.49)
  • Adaptive order sizing (40-140 GOLD)
  • Taker orders (20-80 GOLD)
  • Stale order cancellation (12s)
Environment Variables:
Modes: Single Wallet:
Multiple Wallets:
Duel Stack Integration:

Betting App

Location: packages/gold-betting-demo/app/ React + Vite web UI for placing bets on duel outcomes.

Features

  • Live Stream Embed - HLS video player with duel stream
  • Order Book - Real-time CLOB market depth
  • Recent Trades - Trade history and volume
  • Agent Stats - HP, equipment, combat stats
  • Points Leaderboard - Top bettors by points earned
  • Referral System - Invite links with fee sharing

Environment Variables

packages/gold-betting-demo/app/.env.mainnet:

Deployment

Devnet:
Mainnet:

Production Deployment

Domain Configuration

Commit: bb292c1, 7ff88d1 Hyperscape supports multiple production domains with CORS configured:
  • hyperscape.gg - Main game client
  • hyperscape.bet - Betting platform
  • hyperbet.win - Alternative betting domain
Server CORS Configuration:
Tauri Mobile Deep Links:

Railway Deployment

Environment Variables:
See docs/railway-dev-prod.md for complete deployment guide.

Cloudflare Pages

Client Deployment:
Environment Variables:

Monitoring & Debugging

Streaming State API

Endpoint: GET /api/streaming/state Returns current duel state for betting integration:

RTMP Status File

Location: .runtime-locks/rtmp-status.json Tracks RTMP streaming status:

Logs

Server Logs:

Troubleshooting

Stream Not Starting

Check HLS Output:
Check RTMP Bridge:

Betting App Not Loading

Check Game Server:

Market Maker Not Trading

Check Duel Signal:
Check Wallet Balance:

Keeper Bot Not Resolving

Check Authority Keypair:
Check RPC Connection:

Performance Optimization

Memory Management

Duel Stack Memory Settings:

Database Connection Pool

Duel Stack Pool Settings:
Production Pool Settings:

Agent Spawning

Duel Stack Agent Settings:

Security

Vulnerability Fixes

Commit: a390b79 (Feb 22, 2026) Resolved 14 of 16 security audit vulnerabilities: Fixed:
  • ✅ Playwright ^1.55.1 (GHSA-7mvr-c777-76hp, high)
  • ✅ Vite ^6.4.1 (GHSA-g4jq-h2w9-997c, GHSA-jqfw-vq24-v9c3, GHSA-93m4-6634-74q7)
  • ✅ ajv ^8.18.0 (GHSA-2g4f-4pwh-qvx6)
  • ✅ Root overrides: @trpc/server, minimatch, cookie, undici, jsondiffpatch, tmp, diff, bn.js, ai
Remaining (no upstream patches):
  • ⚠️ bigint-buffer (high severity)
  • ⚠️ elliptic (moderate severity)
CI Audit Policy:

CI/CD Fixes

Commit: b344d9e
  1. ESLint ajv Crash - Removed ajv>=8.18.0 override (needs ajv@6 for Draft-04)
  2. Integration Tests - Added foundry-rs/foundry-toolchain for anvil binary
  3. Asset Clone - Remove assets dir before clone to avoid ‘already exists’ error

Additional Resources