diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index f5299a3466..b1ea2a84f6 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -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", () => { diff --git a/src/client.ts b/src/client.ts index 6ee06d4294..72eec01b26 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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. @@ -1272,6 +1285,7 @@ export class MatrixClient extends TypedEventEmitter