Skip to content

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:

  1. User makes changes in the editor
  2. Changes are converted to Yjs operations
  3. Operations are broadcast to all connected clients
  4. Clients apply operations to their local document
  5. Document state is synchronised across all clients

Dependencies

  • yjs: Core CRDT library
  • y-websocket: WebSocket provider for Yjs
  • y-protocols: Communication protocols for Yjs
  • lib0: Utility library for Yjs
  • @nestjs/websockets: NestJS WebSocket integration
  • socket.io: WebSocket implementation