A real-time collaborative text editor using WebRTC for peer-to-peer communication and Conflict-free Replicated Data Types (CRDTs) for consistency.
- Real-time collaborative editing with CRDTs
- WebRTC for direct peer-to-peer connections
- Signaling server for WebRTC connection establishment
- User presence indicators
- Vector clock synchronization
- Document title and content synchronization
This application demonstrates how to build a distributed, collaborative text editor using:
- Go: Backend signaling server
- WebRTC: For direct peer-to-peer data exchange
- CRDTs: For conflict resolution in distributed editing
- WebSockets: For initial signaling and peer discovery
- Nginx: For serving the frontend static content
- Go 1.18+ (for running without Docker)
- Modern web browser with WebRTC support
- Docker and Docker Compose (optional, for containerized deployment)
The easiest way to run this application is with Docker:
# Build and start the application
docker-compose up -d
# Stop the application
docker-compose downOnce running, access the application at http://localhost
The application is split into two services when running with Docker:
- webrtc-crdt-server: Go-based WebRTC signaling server (port 8080)
- nginx-frontend: Nginx server hosting the HTML/JS/CSS frontend (port 80)
Nginx is configured to proxy WebSocket connections to the Go server.
go mod downloadgo run main.goOpen your browser and go to http://localhost:8080
- Enter a room name and click "Connect"
- Share the room name with others you want to collaborate with
- Start editing the document - changes will be synchronized in real-time
- User cursors and selections will be shown with different colors
- Signaling Server: Written in Go, handles WebRTC connection establishment
- WebRTC: Enables direct peer-to-peer connections
- CRDT Implementation: Ensures consistency across all connected peers
- Presence System: Tracks user cursors and selections
main.go: Go signaling server implementationindex.html: Frontend application with HTML, CSS, and JavaScriptDockerfile: For building the Go signaling serverdocker-compose.yml: Orchestrates both the Go server and Nginx frontendnginx.conf: Nginx configuration for serving the frontend and proxying WebSocket connections
- The client-side CRDT implementation is integrated into the index.html file
- The signaling server handles only the initial WebRTC connection setup
- Once connected, peers communicate directly without server involvement
- Nginx proxies WebSocket connections to the Go signaling server
MIT