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:- Game server with streaming duel scheduler
- Duel matchmaker bots (4 AI agents)
- RTMP bridge for streaming
- Local HLS stream at
http://localhost:5555/live/stream.m3u8 - Betting app at
http://localhost:4179 - Keeper bot for automated market operations
Configuration
Required Environment Variables:packages/server/.env:
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
-
Announcement (30s default)
- Display upcoming duel matchup
- Show agent stats and equipment
- Allow betting window to open
-
Fighting (150s default)
- Agents engage in combat
- Camera follows action
- Real-time HP updates
- Trash talk messages
-
End Warning (10s default)
- Display imminent duel end
- Final betting window
-
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)
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:- Heal - Eat food when HP < threshold
- Buff - Use potions in opening phase
- Prayer - Activate offensive/defensive prayers
- Style Switch - Change attack style based on phase
- Attack - Execute attacks at weapon speed cadence
opening- First 5 ticks, activate buffstrading- Normal combat, balanced approachfinishing- Opponent < 25% HP, aggressivedesperate- Self < 30% HP, defensive
Trash Talk System
Added in commit8ff3ad3
AI agents generate contextual trash talk during combat using LLMs or scripted fallbacks.
Triggers:
-
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!”
-
Ambient Taunts - Random periodic messages every 15-25 ticks
- “Let’s go!”, “Fight me!”, “Too slow”
- 8 seconds between trash talk messages
- Prevents spam and rate limiting
- Fire-and-forget (never blocks combat tick)
LLM Combat Strategy
Optional Feature - Agents can use LLMs to plan combat strategy. Strategy Planning:- Fight start (initial strategy)
- HP change > 20%
- Opponent HP < 25% (switch to aggressive)
- Self HP < 30% (switch to defensive)
- 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
- Default on Linux
- Uses WebCodecs API for encoding
- Better performance on headless servers
- Recommended for production streaming
Rendering Backends
Vulkan:- Default backend
- Best performance on modern GPUs
- May crash on broken ICD (RTX 5060 Ti)
- Fallback for broken Vulkan
- Stable on all hardware
- Slightly lower performance
- Software rendering (CPU)
- Slowest but most compatible
- Use when GPU is unavailable
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
Streaming Stability
Fixes Applied (commitsf3aa787, ae42beb, 5e4c6f1, 30cacb0):
- Vulkan ICD Crashes - Use GL ANGLE backend on RTX 5060 Ti
- FFmpeg SIGSEGV - Use system FFmpeg instead of static build
- WebGPU Unavailable - Use Chrome Dev channel on Vast.ai
- GPU Compositing - Use headful mode with Xvfb on Linux
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 configurationinitializeMatch- Create new duel matchinitializeOrderBook- Initialize order book for matchresolveMatch- Settle match and distribute payouts
- Polls
/api/streaming/statefor 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)
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: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
Railway Deployment
Environment Variables:docs/railway-dev-prod.md for complete deployment guide.
Cloudflare Pages
Client Deployment: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:Betting App Not Loading
Check Game Server:Market Maker Not Trading
Check Duel Signal:Keeper Bot Not Resolving
Check Authority Keypair:Performance Optimization
Memory Management
Duel Stack Memory Settings:Database Connection Pool
Duel Stack 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
- ⚠️ bigint-buffer (high severity)
- ⚠️ elliptic (moderate severity)
CI/CD Fixes
Commit:b344d9e
- ESLint ajv Crash - Removed ajv>=8.18.0 override (needs ajv@6 for Draft-04)
- Integration Tests - Added foundry-rs/foundry-toolchain for anvil binary
- Asset Clone - Remove assets dir before clone to avoid ‘already exists’ error
Additional Resources
- Duel Stack Documentation - Complete duel stack reference
- Streaming Mode Plan - Streaming architecture design
- Railway Deployment - Production deployment guide
- Betting Production Deploy - Betting app deployment