realtimecursor
v1.0.0
Published
Real-time collaboration system with cursor tracking and approval workflow
Maintainers
Readme
RealtimeCursor SDK
This repository contains multiple versions of the RealtimeCursor SDK for real-time collaboration features.
Available Versions
Fixed SDK (v1.1.0)
A fixed version of the original SDK that resolves critical issues:
- Infinite Loop Issue: Prevents the infinite loop of
room-usersevents by tracking project join status - User Duplication: Prevents duplicate users in the collaborators list
- Cursor Tracking: Improves cursor position tracking and updates
- Connection Stability: Better connection handling and reconnection logic
Enhanced SDK (v1.2.0)
A user-friendly version with additional features:
- Typing Indicators: Shows when users are typing in real-time
- Ready-to-use Components: Includes a complete
CollaborativeEditorcomponent - Better UI: Improved cursor animations and collaborator list
- Dark Mode: Supports light and dark themes
- Event System: Better event handling for vanilla JavaScript
Quick Start
Fixed SDK Demo
# From the project root
./start-test.shThis will:
- Build the fixed SDK
- Start the backend server
- Install dependencies for the React test
- Start the React test application
Open multiple browser windows to http://localhost:3000 to see the real-time collaboration in action.
Enhanced SDK Demo
# From the project root
./run-enhanced-demo.shThis will:
- Build the enhanced SDK
- Start the backend server
- Start a simple HTTP server for the demo
Open multiple browser windows to http://localhost:8080 to see the enhanced real-time collaboration features in action.
Using the SDK in Your Project
Fixed SDK
Install from Local
# From your project
npm install /path/to/realtimecursor/fixed-sdkInstall from npm
# From your project
npm install realtimecursor-sdk-fixedEnhanced SDK
Install from Local
# From your project
npm install /path/to/realtimecursor/enhanced-sdkInstall from npm
# From your project
npm install realtimecursor-enhancedReact Usage
import React, { useState, useRef, useEffect } from 'react';
import { useRealtimeCursor, CursorOverlay, CollaboratorsList } from 'realtimecursor-sdk-fixed';
import 'realtimecursor-sdk-fixed/dist/cursor.css';
function CollaborativeEditor() {
const [content, setContent] = useState('');
const editorRef = useRef(null);
const {
cursors,
collaborators,
connected,
updateCursor,
updateContent,
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]);
// Update cursor position on mouse move
const handleMouseMove = (e) => {
if (!editorRef.current) return;
const rect = editorRef.current.getBoundingClientRect();
updateCursor({
x: e.clientX,
y: e.clientY,
relativeX: e.clientX - rect.left,
relativeY: e.clientY - rect.top
});
};
// Update content when changed
const handleContentChange = (e) => {
const newContent = e.target.value;
setContent(newContent);
updateContent(newContent);
};
return (
<div className="collaborative-editor">
<div className="editor-container" ref={editorRef} onMouseMove={handleMouseMove}>
<textarea
value={content}
onChange={handleContentChange}
placeholder="Start typing..."
/>
<CursorOverlay cursors={cursors} />
</div>
<div className="collaborators-panel">
<h3>Active Collaborators ({collaborators.length})</h3>
<CollaboratorsList collaborators={collaborators} />
</div>
</div>
);
}Vanilla JavaScript Usage
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',
color: '#3b82f6' // Optional
}
});
// Connect to the real-time service
cursorClient.connect();
// Set up event handlers
cursorClient.onConnect = () => {
console.log('Connected to real-time service');
};
cursorClient.onDisconnect = () => {
console.log('Disconnected from real-time service');
};
cursorClient.onCursorsChange = (cursors) => {
console.log('Cursors updated:', cursors);
// Render cursors
};
cursorClient.onCollaboratorsChange = (collaborators) => {
console.log('Collaborators updated:', collaborators);
// Update UI
};
// Update cursor position on mouse move
document.getElementById('editor').addEventListener('mousemove', (e) => {
const rect = e.currentTarget.getBoundingClientRect();
cursorClient.updateCursor({
x: e.clientX,
y: e.clientY,
relativeX: e.clientX - rect.left,
relativeY: e.clientY - rect.top
});
});
// Update content when changed
document.getElementById('editor').addEventListener('input', (e) => {
cursorClient.updateContent(e.target.value);
});Publishing to npm
Fixed SDK
To publish the fixed SDK to npm:
# From the project root
./publish-npm.shEnhanced SDK
To publish the enhanced SDK to npm:
# From the project root
./publish-enhanced.shIntegrating with Any React Project
Use the integration script to quickly add the SDK to any React project:
# From the project root
./integrate-sdk.sh /path/to/your/react-projectThis will:
- Build the SDK
- Install it in your React project
- Create a sample component ready to use
Directory Structure
/fixed-sdk- The fixed version of the SDK (v1.1.0)/enhanced-sdk- The enhanced version of the SDK (v1.2.0)/react-test- A React test application using the fixed SDK/enhanced-demo- A demo page for the enhanced SDK/api- The backend server for real-time communication/html-test- A simple HTML test page for the fixed SDK
Upgrading from Previous Version
If you're upgrading from a previous version of the SDK, see UPGRADE.md for detailed instructions.
Changelogs
- Fixed SDK: CHANGELOG.md
- Enhanced SDK: CHANGELOG.md
License
MIT
