SlidingSync is a high-level data structure which controls the majority of sliding sync. It has no hooks into JS SDK except for needing a MatrixClient to perform the HTTP request. This means this class (and everything it uses) can be used in isolation from JS SDK if needed. To hook this up with the JS SDK, you need to use SlidingSyncSdk.

Hierarchy (view full)

Constructors

Methods

  • Add a custom room subscription, referred to by an arbitrary name. If a subscription with this name already exists, it is replaced. No requests are sent by calling this method.

    Parameters

    • name: string

      The name of the subscription. Only used to reference this subscription in useCustomSubscription.

    • sub: MSC3575RoomSubscription

      The subscription information.

    Returns void

  • Get the room index data for a list.

    Parameters

    • key: string

      The list key

    Returns null | {
        joinedCount: number;
        roomIndexToRoomId: Record<number, string>;
    }

    The list data which contains the rooms in this list

  • Get the full request list parameters for a list index. This function is provided for callers to use in conjunction with setList to update fields on an existing list.

    Parameters

    • key: string

      The list key to get the params for.

    Returns null | MSC3575List

    A copy of the list params or undefined.

  • Get the room subscriptions for the sync API.

    Returns Set<string>

    A copy of the desired room subscriptions.

  • Modify which events to retrieve for room subscriptions. Invalidates all room subscriptions such that they will be sent up afresh.

    Parameters

    Returns Promise<string>

    A promise which resolves to the transaction ID when it has been received down sync (or rejects with the transaction ID if the action was not applied e.g the request was cancelled immediately after sending, in which case the action will be applied in the subsequent request)

  • Modify the room subscriptions for the sync API. Calling this function will interrupt the /sync request to resend new subscriptions. If the /sync stream has not started, this will prepare the room subscriptions for when start() is called.

    Parameters

    • s: Set<string>

      The new desired room subscriptions.

    Returns Promise<string>

    A promise which resolves to the transaction ID when it has been received down sync (or rejects with the transaction ID if the action was not applied e.g the request was cancelled immediately after sending, in which case the action will be applied in the subsequent request)

  • Adds the listener function to the end of the listeners array for the event named event.

    No checks are made to see if the listener has already been added. Multiple calls passing the same combination of event and listener will result in the listener being added, and called, multiple times.

    By default, event listeners are invoked in the order they are added. The prependListener method can be used as an alternative to add the event listener to the beginning of the listeners array.

    Type Parameters

    Parameters

    Returns this

    a reference to the EventEmitter, so that calls can be chained.

  • Register an extension to send with the /sync request.

    Parameters

    • ext: Extension<any, any>

      The extension to register.

    Returns void

  • Removes all listeners, or those of the specified event.

    It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

    Parameters

    Returns this

    a reference to the EventEmitter, so that calls can be chained.

  • Resend a Sliding Sync request. Used when something has changed in the request. Resolves with the transaction ID of this request on success. Rejects with the transaction ID of this request on failure.

    Returns Promise<string>

  • Add or replace a list. Calling this function will interrupt the /sync request to resend new lists.

    Parameters

    • key: string

      The key to modify

    • list: MSC3575List

      The new list parameters.

    Returns Promise<string>

    A promise which resolves to the transaction ID when it has been received down sync (or rejects with the transaction ID if the action was not applied e.g the request was cancelled immediately after sending, in which case the action will be applied in the subsequent request)

  • Set new ranges for an existing list. Calling this function when only the ranges have changed is more efficient than calling setList(index,list) as this function won't resend sticky params, whereas setList always will.

    Parameters

    • key: string

      The list key to modify

    • ranges: number[][]

      The new ranges to apply.

    Returns Promise<string>

    A promise which resolves to the transaction ID when it has been received down sync (or rejects with the transaction ID if the action was not applied e.g the request was cancelled immediately after sending, in which case the action will be applied in the subsequent request)

  • Use a custom subscription previously added via addCustomSubscription. No requests are sent by calling this method. Use modifyRoomSubscriptions to resend subscription information.

    Parameters

    • roomId: string

      The room to use the subscription in.

    • name: string

      The name of the subscription. If this name is unknown, the default subscription will be used.

    Returns void