matrix-js-sdk
    Preparing search index...

    Interface Extension<Req, Res>

    An interface that must be satisfied to register extensions

    interface Extension<Req extends object, Res extends object> {
        name(): string;
        onRequest(isInitial: boolean): Promise<Req>;
        onResponse(data: Res): Promise<void>;
        onResponseComplete?(): Promise<void>;
        when(): ExtensionState;
    }

    Type Parameters

    • Req extends object
    • Res extends object
    Index
    • The extension name to go under 'extensions' in the request body.

      Returns string

      The JSON key.

    • A function which is called when the request JSON is being formed. Returns the data to insert under this key.

      Parameters

      • isInitial: boolean

        True when this is part of the initial request.

      Returns Promise<Req>

      The request JSON to send.

    • A function which is called when there is response JSON under this extension.

      Parameters

      • data: Res

        The response JSON under the extension name.

      Returns Promise<void>

    • An optional function which is called once per sync response, after onResponse has been called on all of the extensions (of the same when() stage) which were present in the response. It is called even if this extension was not itself present in the response.

      This allows extensions which need to combine their data with that of other extensions (such as e2ee and to_device) to act once the whole response has been seen.

      Returns Promise<void>