You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-09 10:22:46 +03:00
move to create opts + test
This commit is contained in:
@@ -1082,6 +1082,32 @@ describe("MatrixClient", function () {
|
||||
|
||||
await client._unstable_updateDelayedEvent(delayId, action);
|
||||
});
|
||||
|
||||
it("uses custom timeout for restart delayed event", async () => {
|
||||
// make another client so we can pass creation opts
|
||||
makeClient({ delayedEventRestartLocalTimeoutMS: 2300 });
|
||||
const delayId = "id";
|
||||
const action = UpdateDelayedEventAction.Restart;
|
||||
httpLookups = [
|
||||
{
|
||||
method: "POST",
|
||||
prefix: unstableMSC4140Prefix,
|
||||
path: `/delayed_events/${encodeURIComponent(delayId)}`,
|
||||
data: {
|
||||
action,
|
||||
},
|
||||
},
|
||||
];
|
||||
await client._unstable_updateDelayedEvent(delayId, action);
|
||||
|
||||
expect(client.http.authedRequest).toHaveBeenLastCalledWith(
|
||||
"POST",
|
||||
"/delayed_events/id",
|
||||
undefined,
|
||||
{ action: "restart" },
|
||||
{ localTimeoutMs: 2300, prefix: "/_matrix/client/unstable/org.matrix.msc4140" },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("extended profiles", () => {
|
||||
|
@@ -45,6 +45,7 @@ export const membershipTemplate: SessionMembershipData & { user_id: string } = {
|
||||
|
||||
export type MockClient = Pick<
|
||||
MatrixClient,
|
||||
| "http"
|
||||
| "getUserId"
|
||||
| "getDeviceId"
|
||||
| "sendEvent"
|
||||
@@ -65,6 +66,7 @@ export function makeMockClient(userId: string, deviceId: string): MockClient {
|
||||
cancelPendingEvent: jest.fn(),
|
||||
_unstable_updateDelayedEvent: jest.fn(),
|
||||
_unstable_sendDelayedStateEvent: jest.fn(),
|
||||
http: { authedRequest: jest.fn() } as any, // Mocking http request for compatibility
|
||||
};
|
||||
}
|
||||
|
||||
|
@@ -340,6 +340,19 @@ export interface ICreateClientOpts {
|
||||
*/
|
||||
localTimeoutMs?: number;
|
||||
|
||||
/**
|
||||
* The maximum amount of time to wait before timing out the `POST /_matrix/client/v1/delayed_events/{delay_id}` with `action = "restart"` requests.
|
||||
* If not specified, it uses `localTimeoutMs` if set, otherwise there is no timeout.
|
||||
*
|
||||
* This setting is used in the context of MatrixRTC. We need to restart the dealyed events to make sure
|
||||
* the HomeServer is sending the delayed rtc leave event. In bad network environments we might end up
|
||||
* waiting for too long for the event to arrive and we will not send another restart event until the local timeout is reached.
|
||||
*
|
||||
* In those scenarios chances for success are higher if we use a lower local timeout to increase the tries we do instead of waiting
|
||||
* for responses on requests which are stuck.
|
||||
*/
|
||||
delayedEventRestartLocalTimeoutMS?: number;
|
||||
|
||||
/**
|
||||
* Set to false to send the access token to the server via a query parameter rather
|
||||
* than the Authorization HTTP header.
|
||||
@@ -493,19 +506,6 @@ export interface IStartClientOpts {
|
||||
*/
|
||||
pollTimeout?: number;
|
||||
|
||||
/**
|
||||
* The maximum amount of time to wait before timing out the `POST /_matrix/client/v1/delayed_events/{delay_id}` with `action = "restart"` requests.
|
||||
* If not specified, the default `localTimeoutMs` will be used.
|
||||
*
|
||||
* This setting is used in the context of MatrixRTC. We need to restart the dealyed events to make sure
|
||||
* the HomeServer is sending the delayed rtc leave event. In bad network environments we might end up
|
||||
* waiting for too long for the event to arrive and we will not send another restart event until the local timeout is reached.
|
||||
*
|
||||
* In those scenarios chances for success are higher if we use a lower local timeout to increase the tries we do instead of waiting
|
||||
* for responses on requests which are stuck.
|
||||
*/
|
||||
delayedEventRestartLocalTimeoutMS?: number;
|
||||
|
||||
/**
|
||||
* The filter to apply to /sync calls.
|
||||
*/
|
||||
@@ -1285,6 +1285,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
protected txnCtr = 0;
|
||||
protected mediaHandler = new MediaHandler(this);
|
||||
protected sessionId: string;
|
||||
protected delayedEventRestartLocalTimeoutMS: number | undefined;
|
||||
|
||||
/** IDs of events which are currently being encrypted.
|
||||
*
|
||||
@@ -1327,7 +1328,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
|
||||
const userId = opts.userId || null;
|
||||
this.credentials = { userId };
|
||||
|
||||
this.delayedEventRestartLocalTimeoutMS = opts.delayedEventRestartLocalTimeoutMS;
|
||||
this.http = new MatrixHttpApi(this as ConstructorParameters<typeof MatrixHttpApi>[0], {
|
||||
fetchFn: opts.fetchFn,
|
||||
baseUrl: opts.baseUrl,
|
||||
@@ -3487,7 +3488,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
action,
|
||||
};
|
||||
const opts = {
|
||||
localTimeoutMs: action === "restart" ? this.clientOpts?.delayedEventRestartLocalTimeoutMS : undefined,
|
||||
localTimeoutMs: action === "restart" ? this.delayedEventRestartLocalTimeoutMS : undefined,
|
||||
...requestOptions,
|
||||
};
|
||||
return await this.http.authedRequest(Method.Post, path, undefined, data, {
|
||||
|
@@ -191,7 +191,6 @@ export function defaultClientOpts(opts?: IStoredClientOpts): IStoredClientOpts {
|
||||
initialSyncLimit: 8,
|
||||
resolveInvitesToProfiles: false,
|
||||
pollTimeout: 30 * 1000,
|
||||
delayedEventRestartLocalTimeoutMS: 2300,
|
||||
pendingEventOrdering: PendingEventOrdering.Chronological,
|
||||
threadSupport: false,
|
||||
...opts,
|
||||
|
Reference in New Issue
Block a user