• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
stevekrouse

stevekrouse

WebRTC

Public
Like
1
WebRTC
Home
Code
3
backend
1
frontend
2
README.md
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
8/29/2025
Viewing readonly version of main branch: v19
View latest version
README.md

WebRTC Mouse Cursor Demo

A minimal WebRTC demonstration that shows real-time mouse cursor sharing between multiple users.

Features

  • Real-time mouse cursor sharing: See other users' mouse positions in real-time
  • Peer-to-peer communication: Uses WebRTC data channels for direct browser-to-browser communication
  • HTTP-based signaling: Simple REST API for WebRTC signaling (offers, answers, ICE candidates)
  • Automatic connection: Users automatically connect when they visit the page
  • Minimal UI: Clean, simple interface with colored cursors for each user

Architecture

Frontend (/frontend/)

  • index.html: Main page with Tailwind CSS styling
  • webrtc.js: WebRTC client logic for peer connections and mouse tracking

Backend (/backend/)

  • index.ts: Hono server with signaling API endpoints

How it Works

  1. User visits page: Automatically generates a unique peer ID
  2. Registration: Registers with signaling server and gets list of existing peers
  3. WebRTC handshake: Establishes peer-to-peer connections using HTTP polling for signaling
  4. Mouse sharing: Broadcasts mouse positions directly between browsers via WebRTC data channels
  5. Visual feedback: Shows each user's cursor as a colored dot on screen

API Endpoints

  • POST /api/register - Register a new peer
  • POST /api/offer - Send WebRTC offer
  • GET /api/offers/:peerId - Poll for incoming offers
  • POST /api/answer - Send WebRTC answer
  • GET /api/answers/:peerId - Poll for incoming answers
  • POST /api/ice - Send ICE candidate
  • GET /api/ice/:peerId - Poll for ICE candidates

Technical Details

  • Throttling: Mouse positions are throttled to 50ms intervals
  • Cleanup: Automatic cleanup of stale connections and signaling data
  • STUN server: Uses Google's public STUN server for NAT traversal
  • Data channels: Unordered data channels for low-latency mouse position updates

Usage

Simply visit the page and move your mouse around. Open multiple browser tabs or share the URL with others to see multiple cursors in real-time!

FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.