An Omegle-inspired, modern web application for instant 1-on-1 random video and text conversations with strangers. Built with a reactive React + TypeScript frontend, WebSockets for matchmaking and signaling, and WebRTC for direct media streaming and data relay, backed by a self-hosted Coturn TURN/STUN infrastructure.
- Overview & Architecture
- Key Features
- Frontend Deep Dive (Primary Focus)
- Backend Overview & Signaling
- Project Directory Structure
- Installation & Setup
- Drawbacks, Limitations & Edge Cases
- Keyboard Shortcuts
- License
StrangerThings connects two anonymous online users in an ephemeral room for synchronized video, audio, and text interaction. Once connected, media flows directly peer-to-peer (P2P) between the browsers using WebRTC, while the Node.js Signaling Server coordinates matchmaking, session negotiation (SDP offers/answers), ICE candidates, and chat messaging.
βββββββββββββββββββ βββββββββββββββββββ
β β 1. Join / Queue Match β β
β User A Browser βββββββββββββββββββββββββββββββββββΆβ Node.js Server β
β (Initiator) ββββββββββββββββββββββββββββββββββββ (Socket.IO) β
β β 2. Room Matched Event β β
ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ
β β
β 3. Exchange SDP Offer / Answer & ICE Candidates β
βββββββββββββββββββββββββββββββββββββββββββββββββββββΆβ
β β
β 4. STUN/TURN Relaying (If symmetric NAT) βΌ
β ββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββΆβ Coturn Server (Docker / Host Network) β
β β STUN: 3478 UDP | TURN: 49152-65535 UDP Relay β
β ββββββββββββββββββββββββββββββββββββββββββββββββββ
β
β 5. Direct Peer-to-Peer WebRTC Media Stream (Audio / Video)
βΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββ
β User B Browser β
β (Receiver) β
βββββββββββββββββββ
- Instant Matchmaking Queue: FIFO pairing engine that groups users into unique, isolated rooms immediately upon arrival or skip.
- Low-Latency P2P Video & Audio: Ultra-low latency streaming using browser-native WebRTC
RTCPeerConnection. - Live Text Chat: Real-time text chat synchronized with the active peer in the room.
- Resilient WebRTC Negotiation: Adheres to the WebRTC Perfect Negotiation Pattern to prevent glare and race conditions during renegotiations.
- Adaptive Device Controls: Live mic toggle (mute/unmute), camera switch (enable/disable), dynamic track injection, and instant skip.
- Real-Time HUD / Telemetry: On-screen diagnostic telemetry showing ICE connection state, signaling status, peer connection health, and active video tracks.
- Mobile Responsive Drawer: Seamless experience across desktop monitors and mobile devices with a slide-out live chat drawer.
- Live Presence Counter: Real-time counter broadcasting the total active online users.
The frontend is located in StrangerThings/ and provides a fast, resilient single-page experience without page reloads.
| Technology | Purpose |
|---|---|
| React 18 | Declarative component UI model with concurrent features |
| TypeScript | Strict type definitions across WebRTC payloads, stores, and hooks |
| Vite | Fast module bundler and hot-module replacement (HMR) development server |
| Tailwind CSS | Modern utility-first responsive dark theme design |
| Zustand | Centralized, lightweight call state and streaming store |
| Socket.IO Client | Bi-directional signaling channel with reconnection resilience |
| Framer Motion | Polished micro-interactions, layout transitions, and dialog reveals |
| Lucide React | Consistent, scalable vector iconography |
Found in src/store/useCallStore.ts, the application relies on a single Zustand store to manage synchronous state across disparate components:
- Connection State: Tracked as
'disconnected' | 'connecting' | 'connected' | 'searching' | 'partner_left'. - Media Streams:
localStream(User's webcam/mic) andremoteStream(Stranger's incoming media). - Hardware Toggles:
isMutedandcameraOnbooleans dynamically enabling/disabling individual tracks on active streams. - Session Info: Current
roomId,messagesarray,onlineCount, andisBackendOfflineconnectivity flags.
Located in src/hooks/useWebRTC.ts, this is the core engine handling media life cycles and peer negotiation:
- Dynamic ICE Fetching: On initial mount, queries the backend (
GET /api/ice-servers) to obtain production STUN/TURN configurations with secure credentials, falling back to public Google STUN servers if offline. - Perfect Negotiation Pattern: Uses polite/impolite peer roles (
isInitiatorRef) to resolve race conditions (SDP glare) where both sides attempt to create an offer simultaneously. - Candidate Queueing: Collects incoming ICE candidates in a
pendingCandidatesqueue if remote descriptions have not yet finished setting, preventingInvalidStateError. - Track Recovery: If the user grants webcam/mic permissions after matching, the tracks are dynamically injected into the running
RTCPeerConnectionusingaddTrack()and renegotiated cleanly. - Instant Rematch / Skip: Cleaning up audio/video tracks, terminating current
RTCPeerConnection, and immediately re-emitting thejoinsocket event without page refresh.
Located in src/hooks/useSocket.ts:
- Singleton Socket Instance: Instantiated outside the React component tree to prevent duplicate socket connections under React 18 Strict Mode (which aggressively mounts, unmounts, and remounts components in development).
- Auto Reconnect & Health Tracking: Tracks connection status and automatically sets
isBackendOfflinein the Zustand store to alert the user via an overlay when signaling drops.
-
VideoPlayer.tsx:- Renders the incoming full-screen stranger video with
object-cover. - Floating Picture-in-Picture (PiP) mirror for the local camera feed.
- Floating status alerts (
Searching for stranger...,Backend Offline,Stranger disconnected). - Diagnostic HUD displaying real-time ICE status:
ICE: connected | Sig: stable | Conn: connected | VTracks: 1.
- Renders the incoming full-screen stranger video with
-
ControlsBar.tsx:- Microphone Toggle: toggles audio tracks and prompts permission if missing.
- Camera Toggle: toggles video tracks without dropping the audio call.
- Fast-forward Skip Button: cleanly tears down the session and requests a new partner.
- Global hotkey listener: press Escape to skip instantly.
-
ChatPanel.tsx:- Interactive message list displaying color-coded sender/stranger speech bubbles.
- Input field with automatic focus, disabled when searching or disconnected.
- Auto-scroll to bottom on new messages.
-
Header.tsx:- Clean brand bar displaying the animated live online user count indicator (
π’ X Online).
- Clean brand bar displaying the animated live online user count indicator (
-
Home.tsx:- Layout orchestration combining video viewport and chat panel.
- Responsive breakpoint handler: renders chat alongside video on desktop (
lg:block), or as an overlay sliding drawer modal on mobile devices.
The backend source is located in StrangerThings backend/ and runs a lightweight Node.js + Express + Socket.IO server (server.js).
- User connects and fires the
joinevent. - The server checks
waitingUser:- If empty: the caller is stored as
waitingUser. - If populated (and not self): generates a unique
room_${Date.now()}, joins both sockets to the room, setssocket.roomId, and emitsmatchedwith:- User A:
{ roomId, initiator: true } - User B:
{ roomId, initiator: false }
- User A:
- Resets
waitingUser = null.
- If empty: the caller is stored as
The server acts as an efficient message relay without inspecting packet contents:
offerβ‘οΈ relays SDP offer toroomId.answerβ‘οΈ relays SDP answer toroomId.ice-candidateβ‘οΈ relays network routing candidates to peer.chat-messageβ‘οΈ sends text message to peer inroomId.skip/disconnectβ‘οΈ notifies partner withpartner-left, purges the queue if the disconnected client was waiting, and decrements theonline-count.
The backend exposes GET /api/ice-servers which returns:
{
"iceServers": [
{ "urls": "stun:stun.l.google.com:19302" },
{ "urls": "stun:stun1.l.google.com:19302" },
{ "urls": "stun:<YOUR_IP>:3478" },
{
"urls": "turn:<YOUR_IP>:3478",
"username": "stranger",
"credential": "thingspassword"
},
{
"urls": "turn:<YOUR_IP>:3478?transport=tcp",
"username": "stranger",
"credential": "thingspassword"
}
]
}Warning
Security Notice regarding Coturn Credentials:
The credentials shown above (stranger / thingspassword) are intended strictly as temporary demonstration credentials for local development. Do not use these default credentials in production! Anyone with access to your credentials and public IP can abuse your TURN server as an open relay to forward arbitrary bandwidth. Always replace these with strong, custom credentials or dynamic time-limited tokens (--use-auth-secret) in your .env and Docker configs.
StrangerThings/
βββ StrangerThings/ # π» FRONTEND REPOSITORY (React + Vite)
β βββ public/ # Static assets (favicons, etc.)
β βββ src/
β β βββ components/
β β β βββ ChatPanel.tsx # Text chat UI & message list
β β β βββ ControlsBar.tsx # Mic, Camera, and Skip buttons
β β β βββ Header.tsx # Brand logo & online count badge
β β β βββ VideoPlayer.tsx # Video displays, PiP, and debug HUD
β β βββ hooks/
β β β βββ useSocket.ts # Socket.IO client singleton lifecycle
β β β βββ useWebRTC.ts # PeerConnection, negotiation, tracks
β β βββ pages/
β β β βββ Home.tsx # Main layout & mobile drawer
β β βββ store/
β β β βββ useCallStore.ts # Central Zustand state store
β β βββ App.tsx # Root layout & Toaster provider
β β βββ main.tsx # React DOM entry
β β βββ index.css # Tailwind CSS declarations
β βββ .env # Frontend environment variables
β βββ package.json
β βββ tailwind.config.js
β βββ tsconfig.json
β βββ vite.config.ts
β
βββ StrangerThings backend/ # π BACKEND REPOSITORY (Node.js Signaling)
βββ .env # STUN/TURN and port configuration
βββ coturn-setup.md # Guide for on-device Coturn setup
βββ package.json
βββ server.js # Express + Socket.IO signaling server
Open a terminal and navigate to the backend directory:
cd "C:\codes\StrangerThings backend"
npm installCreate or configure .env inside StrangerThings backend/:
PORT=3000
STUN_URL="stun:YOUR_PUBLIC_OR_LOCAL_IP:3478"
TURN_URL="turn:YOUR_PUBLIC_OR_LOCAL_IP:3478"
TURN_URL_TCP="turn:YOUR_PUBLIC_OR_LOCAL_IP:3478?transport=tcp"
TURN_USERNAME="stranger" # Temporary demo username (change in production)
TURN_CREDENTIAL="thingspassword" # Temporary demo password (change in production)Start the signaling server:
npm start
# Output: Signaling server running on port 3000To enable peer-to-peer traversal when clients are on different networks, behind NATs, or behind mobile cellular firewalls:
- Ensure Docker Desktop is running with WSL2 enabled.
- Run the Coturn container bound to your host network:
docker run -d --network=host --name coturn coturn/coturn `
-n `
--log-file=stdout `
--min-port=49152 `
--max-port=65535 `
--realm=strangerthings `
--user=stranger:thingspassword `
--external-ip=YOUR_PUBLIC_IPNote
The --user=stranger:thingspassword flag uses temporary demo credentials. For production deployments or public hosting, make sure to replace stranger and thingspassword with a strong, secure username and password matching your backend .env.
- Firewall & Port Forwarding:
- In Windows Defender Firewall, allow inbound rules for:
- UDP 3478 & TCP 3478 (STUN/TURN)
- UDP 49152-65535 (WebRTC Media Relay)
- On your home router, forward external ports
3478and UDP49152-65535to your machine's local IPv4 address (192.168.x.x).
- In Windows Defender Firewall, allow inbound rules for:
Open a new terminal and navigate to the frontend directory:
cd "C:\codes\StrangerThings"
npm installConfigure .env in StrangerThings/:
# For local development:
VITE_BACKEND_URL="http://localhost:3000"
# Or if exposing via Dev Tunnels / ngrok / Cloudflare Tunnel:
# VITE_BACKEND_URL="https://your-tunnel-url.ms"Start the Vite development server:
npm run devVisit the displayed local or network URL (typically http://localhost:5173) across two browser windows or different devices on your network to test matching.
To build for production:
npm run buildBecause this project is engineered as a self-hosted, on-device architecture rather than utilizing enterprise cloud TURN providers (such as Twilio Network Traversal or Metered.ca), several inherent trade-offs exist:
- WSL2 Virtual NAT Layer: Running Coturn inside Docker on Windows with
--network=hostrelies on WSL2 network bridging. When the laptop goes to sleep or wakes from standby, the WSL2 virtual network adapter can become unresponsive or drop binding on UDP port ranges (49152-65535). - Symptom: The diagnostic HUD shows
ICE: checkingor hangs indefinitely without reachingICE: connected. - Workaround: Simply refreshing the webpage (F5) or clicking Skip triggers a fresh ICE gathering cycle. If Docker has stalled, restarting the container (
docker restart coturn) re-binds the ports immediately.
- Most home ISPs assign dynamic public IP addresses that rotate every few days or on router reboots.
- If your public IP changes, the Coturn
--external-ipparameter and the backend.env(STUN_URL/TURN_URL) will point to an invalid IP address, preventing remote peers from resolving relay candidates. You will need to update.envwith your new public IP.
- Strict mobile networks (4G/5G) often use Carrier-Grade NAT (CGNAT) and block direct UDP hole-punching. When testing a mobile phone on cellular against a laptop on home Wi-Fi, connection success depends entirely on the TURN relay working properly.
- If port forwarding on the router is not active, peer-to-peer connection will fail across different networks.
- Matchmaking state is stored in memory (
waitingUservariable in Node.js memory). If the server restarts, any active user in the queue is cleared, and active peer-to-peer connections will continue until either user skips.
| Shortcut | Action |
|---|---|
| Escape | Skip to Next Stranger: Instantly disconnects current call and queues for a new partner. |
| Enter | Send Chat Message: Submits the typed message inside the chat panel. |
This project is licensed under the ISC License. Feel free to use, modify, and distribute for educational and personal experimentation.