Skip to content

prudh-vi/pairup-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”₯ PairUp

Connect. Chat. Discover.

A production-grade real-time stranger video chat platform built with WebRTC and Socket.IO

Live Demo β€’ Report Bug β€’ Request Feature

License: MIT PRs Welcome Made with Love

PairUp Demo


✨ Features

πŸŽ₯ Real-Time Video & Audio

Crystal-clear WebRTC peer-to-peer streaming with automatic quality adjustment

πŸ’¬ Live Text Chat

Instant messaging alongside video with typing indicators and message history

πŸ”€ Smart Matchmaking

Intelligent stranger pairing system with instant connections

⏭ Skip & Reconnect

Don't like your match? Skip instantly and connect with someone new

πŸ” Secure & Private

End-to-end encrypted connections with WSS and SSL/TLS

πŸ“± Fully Responsive

Seamless experience across desktop, tablet, and mobile devices


🎯 Why PairUp?

Unlike other video chat platforms, PairUp is:

  • βœ… Open Source - Transparent, auditable, and community-driven
  • βœ… Self-Hostable - Complete control over your data and infrastructure
  • βœ… Production Ready - Battle-tested with proper NAT traversal using TURN servers
  • βœ… Optimized - Low latency P2P connections with minimal server relay
  • βœ… Modern Stack - Built with cutting-edge technologies (React, TypeScript, Bun)

πŸ›  Tech Stack

Frontend

React TypeScript TailwindCSS

  • React 18+ with TypeScript
  • Tailwind CSS for styling
  • Framer Motion for animations
  • Socket.IO Client for signaling
  • WebRTC APIs for media streaming

Backend

Bun Socket.io TypeScript

  • Bun runtime for blazing speed
  • Socket.IO for WebSocket signaling
  • TypeScript for type safety
  • Custom matchmaking logic
  • Room-based connection handling

Infrastructure

Google Cloud NGINX Let's Encrypt

  • Google Cloud VM (Compute Engine)
  • Coturn TURN server for NAT traversal
  • NGINX reverse proxy
  • Let's Encrypt SSL certificates
  • PM2 for process management

πŸ— System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Client Browser                           β”‚
β”‚              (React App + WebRTC Media Handler)                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β”‚ HTTPS + WSS (Secure WebSocket)
                         β”‚
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     NGINX Reverse Proxy                         β”‚
β”‚            SSL Termination + WebSocket Upgrade                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β”‚ HTTP + WebSocket (Internal)
                         β”‚
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Socket.IO Signaling Server                    β”‚
β”‚                        (Bun Runtime)                            β”‚
β”‚  β€’ Matchmaking Logic     β€’ Room Management                      β”‚
β”‚  β€’ WebRTC Signaling      β€’ Message Relay                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β”‚ WebRTC Signaling (Offer/Answer/ICE)
                         β”‚
                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    TURN/STUN Servers                            β”‚
β”‚               (NAT Traversal & Relay)                           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                         β–Ό
             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚   Peer-to-Peer       β”‚
             β”‚   Media Stream       β”‚
             β”‚  (Video + Audio)     β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„ Connection Flow

  1. Client connects to signaling server via WSS
  2. Server matches two waiting clients and creates a room
  3. WebRTC negotiation happens (SDP offer/answer exchange)
  4. ICE candidates are exchanged for NAT traversal
  5. P2P connection established (with TURN relay as fallback)
  6. Media streams flow directly between peers
  7. Chat messages relayed through signaling server

πŸš€ Getting Started

Prerequisites

  • Bun >= 1.0.0 (Install Bun)
  • Node.js >= 18.0.0 (for frontend tooling)
  • Google Cloud Account (for production deployment)
  • Domain name (optional, for SSL)

πŸ“¦ Installation

1. Clone the Repository

git clone https://github.com/prudh-vi/pairup-server.git
cd pairup-server

2. Backend Setup

# Install dependencies
bun install

# Create environment file
cp .env.example .env

# Edit .env with your configuration
nano .env

# Start development server
bun run dev

# Production mode
bun run start

Environment Variables (.env):

PORT=8000
NODE_ENV=development
ALLOWED_ORIGINS=http://localhost:5173,https://yourdomain.com

3. Frontend Setup

cd frontend

# Install dependencies
bun install

# Start development server
bun run dev

# Build for production
bun run build

Frontend Configuration:

Update src/config.ts:

export const SOCKET_URL = 
  process.env.NODE_ENV === 'production' 
    ? 'wss://api.yourdomain.com'
    : 'ws://localhost:8000';

🌐 Production Deployment

Backend Deployment (Google Cloud)

1. Create VM Instance

# Create e2-small instance (recommended for 500-1000 users)
gcloud compute instances create pairup-server \
  --machine-type=e2-small \
  --zone=us-central1-a \
  --image-family=debian-12 \
  --image-project=debian-cloud \
  --boot-disk-size=20GB \
  --tags=http-server,https-server

2. Configure Firewall

# Allow HTTP, HTTPS, and WebSocket
gcloud compute firewall-rules create allow-pairup \
  --allow=tcp:80,tcp:443,tcp:8000 \
  --source-ranges=0.0.0.0/0 \
  --target-tags=http-server,https-server

3. Setup TURN Server

# SSH into VM
gcloud compute ssh pairup-server --zone=us-central1-a

# Run TURN setup script (from repository)
chmod +x scripts/setup-turn.sh
./scripts/setup-turn.sh

# Note down your TURN credentials!

4. Deploy Backend

# Install Bun
curl -fsSL https://bun.sh/install | bash

# Clone and setup
git clone https://github.com/prudh-vi/pairup-server.git
cd pairup-server
bun install

# Install PM2
npm install -g pm2

# Start with PM2
pm2 start src/index.ts --name pairup --interpreter bun
pm2 save
pm2 startup

5. Configure NGINX

sudo apt install nginx certbot python3-certbot-nginx

# Copy NGINX config
sudo cp scripts/nginx.conf /etc/nginx/sites-available/pairup
sudo ln -s /etc/nginx/sites-available/pairup /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

# Get SSL certificate
sudo certbot --nginx -d api.yourdomain.com

Frontend Deployment (Vercel)

# Install Vercel CLI
npm i -g vercel

# Deploy
cd frontend
vercel --prod

Or use the Vercel GitHub Integration for automatic deployments.


πŸ“Š Monitoring & Maintenance

View Logs

# PM2 logs
pm2 logs pairup

# NGINX logs
sudo tail -f /var/log/nginx/access.log
sudo tail -f /var/log/nginx/error.log

# TURN server logs
sudo tail -f /var/log/turnserver.log

Monitor Resources

# Server resources
pm2 monit

# Active connections
sudo netstat -an | grep 3478 | wc -l

# Bandwidth usage
sudo iftop

Restart Services

# Restart backend
pm2 restart pairup

# Restart NGINX
sudo systemctl restart nginx

# Restart TURN server
sudo systemctl restart coturn

πŸ”§ Configuration

WebRTC Configuration

Update frontend/src/config/webrtc.ts:

export const rtcConfig: RTCConfiguration = {
  iceServers: [
    { urls: 'stun:stun.l.google.com:19302' },
    {
      urls: 'turn:YOUR_SERVER_IP:3478',
      username: 'YOUR_TURN_USERNAME',
      credential: 'YOUR_TURN_PASSWORD'
    },
  ],
  iceCandidatePoolSize: 10,
};

Matchmaking Settings

Edit backend/src/matchmaking.ts:

const QUEUE_TIMEOUT = 30000; // 30 seconds
const MAX_RETRIES = 3;

πŸ“ˆ Scaling Guide

Handling More Users

Users VM Type TURN Servers Monthly Cost
100-500 e2-small 1Γ— e2-small ~$20
500-2,500 e2-medium 2Γ— e2-small ~$60
2,500-5,000 e2-standard-2 3Γ— e2-medium ~$200
5,000-10,000 e2-standard-4 5Γ— e2-standard-2 ~$500

Optimization Tips

  1. Enable P2P First - Campus WiFi users connect directly (saves 60% bandwidth)
  2. Lower Video Quality - Use 480p instead of 720p during peak hours
  3. Set Time Limits - 10-minute max calls prevent bandwidth abuse
  4. Geographic Distribution - Deploy TURN servers in multiple regions
  5. Redis Adapter - Scale Socket.IO horizontally across multiple servers

🀝 Contributing

Contributions are what make the open-source community amazing! Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

See CONTRIBUTING.md for detailed guidelines.


πŸ› Known Issues

  • Occasional connection drops on mobile Safari (investigating)
  • TURN relay not working on some corporate networks (firewall issue)
  • Memory leak on long-running sessions (fix in progress)

See the open issues for a full list.


πŸ—Ί Roadmap

  • Basic video chat functionality
  • TURN server integration
  • Production deployment
  • User authentication system
  • Interest-based matching
  • Reporting & moderation tools
  • Screen sharing support
  • Group video calls (3-4 people)
  • Virtual backgrounds
  • Redis adapter for horizontal scaling
  • Mobile apps (React Native)

πŸ“„ License

Distributed under the MIT License. See LICENSE for more information.


πŸ‘¨β€πŸ’» Author

Prudhvi


πŸ™ Acknowledgments

  • WebRTC - For making P2P communication possible
  • Socket.IO - For reliable WebSocket connections
  • Coturn - For TURN/STUN server
  • Tailwind CSS - For beautiful UI
  • Bun - For blazing fast runtime

πŸ’– Support

If you found this project helpful, please give it a ⭐️!

⬆ back to top

Made with ❀️ by Prudhvi

About

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages