UNPKG

realtimecursor

Version:

Real-time collaboration system with cursor tracking and approval workflow

110 lines (89 loc) 2.35 kB
# RealtimeCursor SDK (Fixed Version) A fixed version of the RealtimeCursor SDK for real-time cursor tracking and collaboration. ## Installation ```bash npm install realtimecursor-sdk-fixed ``` ## Usage ### React Integration ```jsx import React, { useState, useRef } from 'react'; import { useRealtimeCursor, CursorOverlay } from 'realtimecursor-sdk-fixed'; import 'realtimecursor-sdk-fixed/dist/cursor.css'; function CollaborativeEditor() { const [content, setContent] = useState(''); const editorRef = useRef(null); const { cursors, updateCursor, updateContent, collaborators, connect, disconnect } = useRealtimeCursor({ apiUrl: 'http://localhost:3001', projectId: 'your-project-id', user: { id: 'user-123', name: 'John Doe', color: '#3b82f6' // Optional } }); // Connect on mount useEffect(() => { connect(); return () => disconnect(); }, [connect, disconnect]); const handleMouseMove = (e) => { updateCursor({ x: e.clientX, y: e.clientY }); }; const handleChange = (e) => { const newContent = e.target.value; setContent(newContent); updateContent(newContent); }; return ( <div className="editor-container"> <textarea ref={editorRef} value={content} onChange={handleChange} onMouseMove={handleMouseMove} /> <CursorOverlay cursors={cursors} /> </div> ); } ``` ### Vanilla JavaScript Integration ```javascript import { RealtimeCursor } from 'realtimecursor-sdk-fixed'; import 'realtimecursor-sdk-fixed/dist/cursor.css'; // Initialize the cursor client const cursorClient = new RealtimeCursor({ apiUrl: 'http://localhost:3001', projectId: 'your-project-id', user: { id: 'user-123', name: 'John Doe' } }); // Connect to the real-time service cursorClient.connect(); // Update cursor position on mouse move document.addEventListener('mousemove', (e) => { cursorClient.updateCursor({ x: e.clientX, y: e.clientY }); }); // Update content on change document.getElementById('editor').addEventListener('input', (e) => { cursorClient.updateContent(e.target.value); }); ``` ## Documentation For complete documentation, visit [https://github.com/sourabhpunase/realtimecursor](https://github.com/sourabhpunase/realtimecursor)