Skip to main content

Command Palette

Search for a command to run...

Building TalkRush, a Real-Time Anonymous Web Chat

P2P Video Streaming: Lightweight WebRTC Signaling

Updated
3 min readView as Markdown
Building TalkRush, a Real-Time Anonymous Web Chat

Building a fast real-time chat app without persistent user accounts or bloated auth flows introduces unique frontend and state-synchronization challenges.

​I built TalkRush as a browser-first, lightweight platform where users can jump straight into 1v1 text, direct video calls, custom group rooms, and live interactive canvas/board games without setup friction or server-side media retention.

​Here is a practical look at how the real-time mechanics and features are wired together.

​1. Zero-Storage Media Sharing

​To prioritize user privacy and keep infrastructure costs zero, TalkRush does not store image media on servers or databases.

  • Ephemeral Transfer: Media payloads are transmitted either directly peer-to-peer via WebRTC Data Channels (for 1v1 sessions) or held strictly in transient memory during an active session.

  • Zero Persistence: No disk writes, no S3/bucket storage, and no database bloat. Once a session ends or a tab closes, the in-memory object URLs are discarded immediately by the browser garbage collector.

​2. Multi-Mode Architecture: 1v1, DMs, & Group Rooms

​The platform handles three distinct messaging topologies:

  1. Random 1v1 Matching: An ephemeral queue matches two active session IDs, exchanges signaling tokens, and drops both users into an isolated conversation path.

  2. Direct Messaging (DM): Direct peer-to-peer or unique room-token links that allow two individuals to connect without exposing contact lists or identity markers.

  3. Public & Private Group Rooms:

    • ​Public rooms act as open broadcast channels for shared topics.

    • ​Private rooms require a client-verified access code or passkey, dynamically scoping the real-time listeners so unauthenticated sessions cannot read message packets.

​3. P2P Video Calling via WebRTC

​Video calls are established peer-to-peer without passing video frames through a media server:

  • Signaling: Real-time database listeners serve solely as the handshake wire to trade SDP offers, SDP answers, and ICE candidates.

  • Direct Stream: Once NAT traversal completes via STUN/TURN, media tracks (MediaStreamTrack) stream directly between browsers. This eliminates backend bandwidth costs and keeps video latency near zero.

​4. In-Chat Interactive Games & Collaborative Canvas

​A static chat box can get boring fast. TalkRush embeds interactive multiplayer features directly into the active conversation view:

​Real-Time Tic-Tac-Toe

  • State Synchronization: The game board state is represented as a compact 9-element array (e.g., ['X', null, 'O', ...]) synced over the active room socket/node.

  • Turn Validation: Turn locks and win-condition checks are verified locally on state change, instantly updating the UI on both ends without lagging the text chat.

​Live Collaborative Drawing

  • Vector Coordinate Streaming: Instead of transmitting heavy canvas image frames, the client listens to touch/pointer movements, normalizes coordinates (X, Y), and streams small coordinate packets {x0, y0, x1, y1, color, size}.

  • Canvas Rendering: The receiving client draws path segments immediately using the HTML5 Canvas 2D context, delivering smooth, simultaneous drawing with minimal payload overhead.

​5. Managing Lifecycle & Ghost Connections

​In an anonymous app, users rarely click "Leave"—they close the tab, swipe away their browser, or lose cell reception.

  • Presence Hooks: Dynamic disconnect hooks (onDisconnect) trigger automatically on connection loss to purge active signaling keys, vacate open game slots, and update peer status.

  • Memory Management: Canvas contexts, audio/video streams, and WebSocket listeners are explicitly terminated and nullified on component teardown to prevent memory leaks across long sessions.

​TalkRush shows that by combining browser-native WebRTC with lightweight real-time state sync, you can build rich, interactive, privacy-first web apps that require zero logins and store zero user media.