Datalayer VS Code Extension - v0.0.9
    Preparing search index...

    WebSocket adapter that runs in the extension (Node.js context). Manages WebSocket connection to Loro collaboration server.

    Index

    Constructors

    Properties

    adapterId: string

    Unique identifier for this adapter instance

    isDisposed: boolean = false

    Flag indicating whether the adapter has been disposed

    maxQueueSize: 1000

    Maximum number of messages to queue before dropping new ones

    maxReconnectDelay: number = 2500

    Maximum delay in milliseconds for exponential backoff

    messageQueue: unknown[] = []

    Queue of messages waiting to be sent when connection is established

    reconnectDelay: number = 100

    Current delay in milliseconds before next reconnection attempt

    reconnectTimer: Timeout = null

    Timer for scheduled reconnection attempts

    websocketUrl: string

    URL of the Loro WebSocket server to connect to

    webview: Webview

    VS Code Webview instance to send messages to

    ws: WebSocket = null

    The underlying WebSocket connection to the Loro server

    Methods

    • Connect to the WebSocket server. Establishes a new WebSocket connection if one doesn't already exist. Sets up event handlers for open, message, close, and error events. Messages received while disconnected are queued and sent upon reconnection. Automatically attempts to reconnect with exponential backoff on close.

      Returns void

      void

    • Disconnect from the WebSocket server. Cancels any pending reconnection timers and closes the WebSocket connection. Safe to call multiple times; handles null checks internally.

      Returns void

      void

    • Clean up resources and prepare for garbage collection. Marks the adapter as disposed, disconnects from the server, and clears the message queue. After disposal, the adapter should not be used.

      Returns void

      void

    • Private

      Flush all queued messages to the WebSocket server. Called when the WebSocket connection is first established. Clears the queue after sending to prevent duplicate transmissions.

      Returns void

    • Handle incoming messages from the webview. Routes messages to appropriate handlers:

      • 'connect': Initiates WebSocket connection
      • 'disconnect': Closes WebSocket connection
      • 'message': Forwards data to WebSocket server

      Parameters

      • message: LoroMessage

        The message from the webview with type, adapterId, and optional data

      Returns void

      void

    • Check if the WebSocket is currently connected and ready to send. Verifies that the WebSocket exists and readyState is 1 (OPEN).

      Returns boolean

      true if connected and ready, false otherwise

    • Private

      Schedule a reconnection attempt with exponential backoff. Calculates delay using reconnectDelay * 2 up to maxReconnectDelay. Only schedules if no reconnection is already pending.

      Returns void

    • Send a message to the WebSocket server. Supports multiple data types: string (JSON), array (binary/Loro update bytes), or object (JSON). If not connected, messages are queued up to maxQueueSize and sent when connection establishes. Queue overflow is silently dropped to prevent memory issues.

      Parameters

      • data: unknown

        The data to send (string, array, or object)

      Returns void

      void