Collaboration Module¶
Overview¶
The Collaboration module enables real-time collaborative editing in the BidScript application. It provides synchronisation capabilities for multiple users to work on the same document simultaneously, with conflict resolution and change tracking.
Configuration¶
The Collaboration module uses Yjs and related technologies for conflict-free replicated data types (CRDT):
- Yjs: Core CRDT library
- Y-Websocket: WebSocket provider for Yjs
- Y-Protocols: Communication protocols for Yjs
Key Components¶
Collaboration Module¶
The main module that orchestrates the collaboration functionality:
@Module({
imports: [
// Dependencies
],
controllers: [
// Controllers
],
providers: [
// Services
],
exports: [
// Exported services
],
})
export class CollaborationModule {}
Services¶
The module includes several services:
- Collaboration Service: Core service that manages document collaboration
- Document Sync Service: Handles document synchronisation
- Presence Service: Tracks and broadcasts user presence information
WebSocket Integration¶
The module leverages WebSockets for real-time communication:
- Bi-directional communication for document changes
- Awareness protocol for user presence
- Broadcasting of document updates
Integration with Other Modules¶
The Collaboration module integrates with:
- Editor Module: For document editing features
- Authentication Module: For user identification
- WebSocket Module: For real-time communication
Technical Implementation¶
The module uses the following technologies:
- Yjs: For conflict-free replicated data types
- WebSockets: For real-time communication
- CRDT: For conflict resolution and data synchronisation
Usage Example¶
When a user edits a document, the following flow occurs:
- User makes changes in the editor
- Changes are converted to Yjs operations
- Operations are broadcast to all connected clients
- Clients apply operations to their local document
- Document state is synchronised across all clients
Dependencies¶
yjs: Core CRDT libraryy-websocket: WebSocket provider for Yjsy-protocols: Communication protocols for Yjslib0: Utility library for Yjs@nestjs/websockets: NestJS WebSocket integrationsocket.io: WebSocket implementation