Public
Like
1
WebRTC
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.
Viewing readonly version of main branch: v12View latest version
A minimal WebRTC demonstration that shows real-time mouse cursor sharing between multiple users.
- 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
index.html: Main page with Tailwind CSS stylingwebrtc.js: WebRTC client logic for peer connections and mouse tracking
index.ts: Hono server with signaling API endpoints
- User visits page: Automatically generates a unique peer ID
- Registration: Registers with signaling server and gets list of existing peers
- WebRTC handshake: Establishes peer-to-peer connections using HTTP polling for signaling
- Mouse sharing: Broadcasts mouse positions directly between browsers via WebRTC data channels
- Visual feedback: Shows each user's cursor as a colored dot on screen
POST /api/register- Register a new peerPOST /api/offer- Send WebRTC offerGET /api/offers/:peerId- Poll for incoming offersPOST /api/answer- Send WebRTC answerGET /api/answers/:peerId- Poll for incoming answersPOST /api/ice- Send ICE candidateGET /api/ice/:peerId- Poll for ICE candidates
- 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
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!
