A modern, high-performance video streaming player with aggressive buffering, custom controls, and secure CORS proxy support.
- π Aggressive Buffering - Preloads up to 45 seconds ahead for smooth playback
- π¨ Modern UI - Beautiful gradient design with glassmorphism effects
- β‘ Fast Seeking - Jump to any point instantly with optimized chunk loading
- π Secure CORS Proxy - HMAC-signed URLs for secure video streaming
- π Real-time Stats - Live buffer and network speed monitoring
- β¨οΈ Keyboard Shortcuts - Full keyboard control support
- π― Click to Play - Click anywhere on the video to play/pause
- πΌοΈ Picture-in-Picture - Multitask while watching
- π¬ Variable Speed - Play at speeds from 0.25x to 100x
- π± Responsive - Works on all screen sizes
- π HMAC Authentication - Time-limited signed URLs prevent unauthorized access
β οΈ Robust Error Handling - Clear error messages for network, timeout, and format issues- β±οΈ Smart Timeout Detection - Automatic detection of stuck loading states
- π‘οΈ Rate Limiting - Protection against server overload
- Node.js (v14 or higher)
- Modern web browser (Chrome, Firefox, Safari, Edge)
- Clone the repository:
git clone https://github.com/saahiyo/Realtime-Streaming-website.git
cd Realtime-Streaming-website-
Install dependencies (required for local proxy server):
npm install
This installs the
dotenvpackage needed to load environment variables. -
Set up environment variables (for proxy security):
- Copy
.env.exampleto.env:cp .env.example .env
- Edit
.envand set a strong secret key:STREAM_SECRET=your-secure-secret-key-here
β οΈ Important: Use a strong, random secret in production!
- Copy
-
No other dependencies - Frontend is pure vanilla JavaScript!
Simply open index.html in your browser for direct video URL streaming (no proxy features).
node server.jsThen open http://localhost:4001 in your browser.
The proxy server includes:
- HMAC-based security - All proxy requests require signed URLs with timestamps
- Automatic URL signing - Server generates signed URLs via
/generate-signed-urlendpoint - Runs on port 4001 (configurable via
PORTenvironment variable) - Handles CORS restrictions transparently
- Maintains keep-alive connections for better performance
- Supports up to 200 concurrent streams
- Time-limited URLs (5-minute expiration)
- Rate limiting and overload protection
Security Note: The player automatically requests signed URLs from the server when the "Use Proxy" option is enabled. You don't need to manually sign URLs.
Deploy the proxy as a serverless edge function for global, scalable performance:
-
Set up environment variables in Vercel:
- Go to your Vercel project settings
- Add environment variable:
STREAM_SECRET=your-production-secret-key β οΈ Critical: Use a strong, unique secret in production!
-
Install Vercel CLI (if not already installed):
npm install -g vercel- Deploy to Vercel:
vercel- Access your deployment:
- Health check:
https://your-domain.vercel.app/api/server(returns status JSON) - Sign URL endpoint:
https://your-domain.vercel.app/api/server?action=sign(POST) - Proxy endpoint:
https://your-domain.vercel.app/api/server?url=...&t=...&nonce=...&sig=...(signed URLs)
- Health check:
The Vercel edge function includes:
- Same HMAC security as local server
- Automatically scales based on demand
- Runs on Vercel's global edge network
- Supports up to 100 concurrent streams per region
- 25-second timeout limit (edge runtime requirement)
- Health check endpoint for monitoring
Automatic Environment Detection: The player automatically detects the environment:
- π Local development: Uses
http://localhost:4001/generate-signed-urlandhttp://localhost:4001/proxy - π Production (Vercel): Uses your Vercel domain's
generate-signed-urlendpoint - No manual configuration needed!
- Enter Video URL: Paste a direct video URL (MP4, WebM, OGG, HLS, DASH)
- Enable Proxy (if needed): Toggle "Use Local Proxy" for CORS-blocked videos
- Click Stream: Start watching instantly
| Key | Action |
|---|---|
Space |
Play/Pause |
F |
Toggle Fullscreen |
M |
Mute/Unmute |
P |
Picture-in-Picture |
β |
Skip backward 10s |
β |
Skip forward 10s |
β |
Volume up |
β |
Volume down |
0-9 |
Jump to 0%-90% |
Click time display |
Jump to specific timestamp |
index.html- Main application interfaceplayer.js- Video player logic and buffering enginestyles.css- Styling and animationsserver.js- Node.js CORS proxy server (local development)api/server.js- Vercel edge function (production deployment)package.json- Node.js dependencies (dotenv).env.example- Environment variable template.gitignore- Git ignore rules
- Vanilla JavaScript - No framework dependencies
- HTML5 Video API - Native video capabilities
- Node.js HTTP/HTTPS - Proxy server implementation
- CSS3 Animations - Smooth transitions and effects
StreamFlow uses an aggressive buffering approach:
- Target buffer: 45 seconds ahead
- Low buffer threshold: 10 seconds
- Continuous buffer pressure to maximize preloading
- Smart seek optimization for instant jumps
Create a .env file in the project root:
# Required for proxy security (both local and Vercel)
STREAM_SECRET=your-secure-random-key-here
# Optional: Custom port for local server (default: 4001)
PORT=4001Security Requirements:
- Use a strong, random secret key (minimum 32 characters recommended)
- Never commit
.envto version control (already in.gitignore) - Use different secrets for development and production
- Set
STREAM_SECRETin Vercel environment variables for production
Edit server.js to customize local server behavior:
const PORT = process.env.PORT || 4001; // Server port
const MAX_CONCURRENT = 200; // Max concurrent streams
const REQUEST_TIMEOUT_MS = 30_000; // Request timeout (30s)
const KEEPALIVE_MAX_SOCKETS = 500; // Max keep-alive sockets
const MAX_SKEW_SECONDS = 300; // URL expiration time (5 min)
const MAX_REDIRECTS = 5; // Max redirect followsEdit api/server.js to customize edge function behavior:
const MAX_CONCURRENT = 100; // Max concurrent streams per region
const REQUEST_TIMEOUT_MS = 25000; // Request timeout (25s, edge limit)
const MAX_SKEW_SECONDS = 300; // URL expiration time (5 min)
const MAX_REDIRECTS = 5; // Max redirect followsEdit player.js to customize buffering and timeouts:
this.TARGET_BUFFER = 45; // Target buffer in seconds
this.LOW_BUFFER = 10; // Low buffer warning threshold
this.LOADING_TIMEOUT_MS = 15000; // Loading timeout (15 seconds)The application includes comprehensive error handling for a smooth user experience:
- β±οΈ Loading Timeout - Detects and reports videos that fail to load within 15 seconds
- π΄ Media Errors - Clear messages for:
- Network failures (
MEDIA_ERR_NETWORK) - Format/codec issues (
MEDIA_ERR_DECODE) - Unsupported sources (
MEDIA_ERR_SRC_NOT_SUPPORTED) - Aborted loads (
MEDIA_ERR_ABORTED)
- Network failures (
- π State Detection - Monitors video loading states to prevent stuck "Buffering..." UI
- π― User Feedback - Error overlay with specific, actionable messages
- π Security Errors:
401 Unauthorized- Missing or invalid signature403 Link Expired- URL timestamp older than 5 minutes403 Invalid Signature- HMAC verification failed
- π« Request Errors:
400 Invalid URL- Malformed or non-HTTP(S) URLs503 Server Busy- Too many concurrent requests (withRetry-Afterheader)502 Proxy Error- Upstream server issues502 Content Not Streamable- HTML pages blocked (anti-bot protection)
- β±οΈ Timeout Protection - 30s local / 25s edge function timeout
- π Auto-Retry - Graceful handling of network resets and interruptions
- Keep-alive connections - Reduces latency with connection reuse (local server)
- TCP_NODELAY - Disables Nagle's algorithm for faster streaming
- High water marks - 256KB buffers for optimal throughput
- Connection pooling - Up to 500 concurrent keep-alive sockets
- Smart preloading - Metadata first, then aggressive buffering on play
- Target buffer: 45 seconds - Ensures smooth playback even on unstable networks
- Continuous buffer pressure - 500ms interval checks to maintain buffer
- Time-limited URLs - 5-minute expiration minimizes unauthorized access window
- HMAC-SHA256 - Fast cryptographic signing with minimal overhead
- Nonce-based replay protection - Prevents URL reuse attacks
- β Chrome 90+
- β Firefox 88+
- β Safari 14+
- β Edge 90+
- MP4 (H.264/H.265)
- WebM (VP8/VP9)
- OGG (Theora)
- HLS (m3u8)
- DASH (mpd)
Contributions are welcome! Please feel free to submit a Pull Request.
This project is open source and available under the MIT License.
Built with β€οΈ for smooth video streaming experiences.
Note: This player is designed for personal use and educational purposes. Always respect copyright and content licensing when streaming videos.