A real-time collaborative text editor built with Vue.js 3 and Yjs, featuring both plain text and rich text editing capabilities with live user awareness and cursor tracking.
- Real-time Collaboration: Multiple users can edit the same document simultaneously
- Dual Editor Modes: Switch between plain text and rich text editing
- User Awareness: See other users' cursors, selections, and typing indicators
- Document Sessions: Create or join document sessions using unique IDs
- Persistent Documents: Documents persist across sessions using Yjs CRDT technology
- EditorJS Integration: Professional rich text editing with blocks
- Structured Content: Support for headers, paragraphs, lists, and more
- Block-based Editing: Modern content creation experience
- Live Cursors: See where other users are editing in real-time
- User Identification: Each user gets a unique name and color
- Typing Indicators: Visual feedback when users are actively typing
- Connection Status: Enhanced server logging and user tracking
- Vue.js 3 - Progressive JavaScript framework with Composition API
- Vite - Fast build tool and development server
- Yjs - Conflict-free Replicated Data Type (CRDT) for collaborative editing
- y-websocket - WebSocket provider for Yjs
- EditorJS - Block-styled rich text editor
- Node.js - JavaScript runtime
- WebSocket (ws) - Real-time bidirectional communication
- Yjs Server - Document synchronization and persistence
- Express - Web application framework (if needed for additional routes)
realtime-editor.js/
βββ ui/ # Vue.js frontend application
β βββ src/
β β βββ components/
β β β βββ DocumentSelector.vue # Document selection interface
β β β βββ PlainTextEditor.vue # Plain text collaborative editor
β β β βββ RichTextEditor.vue # Rich text collaborative editor
β β βββ utils/
β β β βββ userUtils.js # User management utilities
β β βββ App.vue # Main application component
β β βββ main.js # Application entry point
β βββ package.json
β βββ vite.config.js
βββ server/ # Node.js backend server
β βββ server.js # WebSocket server with Yjs integration
β βββ package.json
βββ package.json # Root package configuration
- Node.js (v16 or higher)
- npm or yarn
-
Clone the repository
git clone <repository-url> cd realtime-editor.js
-
Install root dependencies
npm install
-
Install server dependencies
cd server npm install cd ..
-
Install UI dependencies
cd ui npm install cd ..
-
Start the WebSocket Server
cd server node server.jsThe server will start on
ws://localhost:1234and display enhanced logging with user activity tracking. -
Start the Vue.js Development Server
cd ui npm run devThe UI will be available at
http://localhost:5173(or the port shown in your terminal). -
Open Multiple Browser Tabs
To test collaboration, open the application in multiple browser tabs or different browsers and join the same document session.
- Enter a Document ID: Use any alphanumeric string as your document identifier
- Select Editor Type: Choose between "Plain Text" or "Rich Text" editing
- Start Editing: Click "Start Editing" to join the collaborative session
- Multiple Users: Share the same document ID with others to collaborate
- Real-time Updates: See changes appear instantly as others type
- User Awareness: Observe other users' cursors and selections
- Persistent Sessions: Documents remain available as long as the server is running
- Simple, fast text editing
- Real-time synchronization
- Cursor and selection tracking
- Suitable for code, notes, or simple documents
- Block-based content creation
- Headers, paragraphs, and lists
- Professional editing experience
- Structured document creation
The WebSocket server runs on port 1234 by default. To change this:
- Edit
server/server.js - Modify the port in the WebSocketServer configuration:
const wss = new WebSocketServer({ port: YOUR_PORT })
The frontend is configured to connect to ws://localhost:1234. For production or different environments:
- Update WebSocket connection URLs in the editor components
- Modify the Vite configuration if needed for deployment
-
Build the UI
cd ui npm run build -
Preview Production Build
cd ui npm run preview
- Hot Module Replacement: Changes to Vue components update instantly
- Enhanced Logging: Server provides detailed activity logs
- Error Handling: Comprehensive error handling for WebSocket connections
- User Tracking: Detailed user session management and awareness
The application uses Yjs (Y.js), a CRDT implementation that enables:
- Conflict-free Merging: Multiple users can edit simultaneously without conflicts
- Offline Support: Changes can be made offline and synchronized when reconnected
- Undo/Redo: Built-in operation history
- Binary Efficiency: Optimized data transmission
- Client Identification: Each connection gets a unique client ID
- User Metadata: Names, colors, and connection timestamps
- Cursor Tracking: Real-time cursor position and selection data
- Activity Monitoring: Typing indicators and user presence
- Session Isolation: Each document ID creates an isolated collaboration space
- Memory Storage: Documents persist in server memory during runtime
- Connection Mapping: Robust mapping between WebSocket connections and documents
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is open source. Please check the license file for more details.
-
Connection Failed
- Ensure the WebSocket server is running on port 1234
- Check for firewall or antivirus blocking the connection
-
Changes Not Syncing
- Verify all clients are connected to the same document ID
- Check browser console for WebSocket errors
-
Performance Issues
- Large documents may experience slower synchronization
- Consider breaking large documents into smaller sections
The server provides extensive logging. Monitor the server console for:
- Connection status
- Document activity
- User awareness updates
- Error messages
For issues, questions, or contributions, please create an issue in the repository or contact the development team.
Happy Collaborative Editing! π