Hierarchy

Constructors

Properties

#private: any
acknowledgementCount: number
acknowledgements: Map<string, number>
causalHistorySize: number
channelId: string
filter: DefaultBloomFilter
handlers: Handlers = ...
incomingBuffer: SdsMessage[]
lamportTimestamp: number
localHistory: {
    historyEntry: HistoryEntry;
    timestamp: number;
}[]

Type declaration

  • historyEntry: HistoryEntry
  • timestamp: number
outgoingBuffer: SdsMessage[]
receivedMessageTimeout: number
receivedMessageTimeoutEnabled: boolean
tasks: Task[] = []
timeReceived: Map<string, number>

Methods

  • Parameters

    • payload: Uint8Array
    • Optional callback: ((message) => Promise<boolean>)
        • (message): Promise<boolean>
        • Parameters

          • message: SdsMessage

          Returns Promise<boolean>

    Returns Promise<void>

  • Parameters

    • payload: Uint8Array
    • Optional callback: ((message) => Promise<{
          retrievalHint?: Uint8Array;
          success: boolean;
      }>)
        • (message): Promise<{
              retrievalHint?: Uint8Array;
              success: boolean;
          }>
        • Parameters

          • message: SdsMessage

          Returns Promise<{
              retrievalHint?: Uint8Array;
              success: boolean;
          }>

    Returns Promise<void>

  • Type Parameters

    Parameters

    • type: K
    • listener: null | EventHandler<MessageChannelEvents[K]>
    • Optional options: boolean | AddEventListenerOptions

    Returns void

  • Parameters

    • event: Event

    Returns boolean

  • Parameters

    • type: string

    Returns number

  • Processes all queued tasks sequentially to ensure proper message ordering.

    This method should be called periodically by the library consumer to execute queued send/receive operations in the correct sequence.

    Returns Promise<void>

    Example

    const channel = new MessageChannel("my-channel");

    // Queue some operations
    await channel.sendMessage(payload, callback);
    channel.receiveMessage(incomingMessage);

    // Process all queued operations
    await channel.processTasks();

    Throws

    Will emit a 'taskError' event if any task fails, but continues processing remaining tasks

  • Queues a received message for processing.

    The message will be processed when processTasks() is called, ensuring proper dependency resolution and causal ordering.

    Parameters

    • message: SdsMessage

      The message to receive and process

    Returns void

    Example

    const channel = new MessageChannel("chat-room");

    // Receive a message from the network
    channel.receiveMessage(incomingMessage);

    // Process the received message
    await channel.processTasks();
  • Type Parameters

    Parameters

    • type: K
    • Optional listener: null | EventHandler<MessageChannelEvents[K]>
    • Optional options: boolean | EventListenerOptions

    Returns void

  • Type Parameters

    • Detail

    Parameters

    Returns boolean

  • Sends a short-lived message without synchronization or reliability requirements.

    Sends a message without a timestamp, causal history, or bloom filter. Ephemeral messages are not added to the outgoing buffer. Upon reception, ephemeral messages are delivered immediately without checking for causal dependencies or including in the local log.

    See https://rfc.vac.dev/vac/raw/sds/#ephemeral-messages

    Parameters

    • payload: Uint8Array

      The payload to send.

    • Optional callback: ((message) => Promise<boolean>)

      A callback function that returns a boolean indicating whether the message was sent successfully.

        • (message): Promise<boolean>
        • Parameters

          • message: SdsMessage

          Returns Promise<boolean>

    Returns Promise<void>

  • Queues a message to be sent on this channel.

    The message will be processed sequentially when processTasks() is called. This ensures proper lamport timestamp ordering and causal history tracking.

    Parameters

    • payload: Uint8Array

      The message content as a byte array

    • Optional callback: ((message) => Promise<{
          retrievalHint?: Uint8Array;
          success: boolean;
      }>)

      Optional callback function called after the message is processed

        • (message): Promise<{
              retrievalHint?: Uint8Array;
              success: boolean;
          }>
        • Parameters

          • message: SdsMessage

          Returns Promise<{
              retrievalHint?: Uint8Array;
              success: boolean;
          }>

    Returns Promise<void>

    Promise that resolves when the message is queued (not sent)

    Example

    const channel = new MessageChannel("chat-room");
    const message = new TextEncoder().encode("Hello, world!");

    await channel.sendMessage(message, async (processedMessage) => {
    console.log("Message processed:", processedMessage.messageId);
    return { success: true };
    });

    // Actually send the message
    await channel.processTasks();
  • Send a sync message to the SDS channel.

    Increments the lamport timestamp, constructs a Message object with an empty load. Skips outgoing buffer, filter, and local log.

    See https://rfc.vac.dev/vac/raw/sds/#send-sync-message

    Parameters

    • Optional callback: ((message) => Promise<boolean>)

      A callback function that returns a boolean indicating whether the message was sent successfully.

        • (message): Promise<boolean>
        • Parameters

          • message: SdsMessage

          Returns Promise<boolean>

    Returns Promise<boolean>

  • Processes messages in the incoming buffer, delivering those with satisfied dependencies.

    Returns HistoryEntry[]

    Array of history entries for messages still missing dependencies

  • Returns {
        possiblyAcknowledged: SdsMessage[];
        unacknowledged: SdsMessage[];
    }

    • possiblyAcknowledged: SdsMessage[]
    • unacknowledged: SdsMessage[]