diff --git a/src/matrix/net/HomeServerApi.ts b/src/matrix/net/HomeServerApi.ts index c459ab9c..8f6ab0df 100644 --- a/src/matrix/net/HomeServerApi.ts +++ b/src/matrix/net/HomeServerApi.ts @@ -27,13 +27,20 @@ type RequestMethod = "POST" | "GET" | "PUT"; const CS_R0_PREFIX = "/_matrix/client/r0"; const DEHYDRATION_PREFIX = "/_matrix/client/unstable/org.matrix.msc2697.v2"; +type Ctor = { + homeserver: string; + accessToken: string; + request: RequestFunction; + reconnector: Reconnector; +}; + export class HomeServerApi { private readonly _homeserver: string; private readonly _accessToken: string; private readonly _requestFn: RequestFunction; private readonly _reconnector: Reconnector; - constructor({homeserver, accessToken, request, reconnector}: {homeserver: string, accessToken: string, request: RequestFunction, reconnector: Reconnector}) { + constructor({homeserver, accessToken, request, reconnector}: Ctor) { // store these both in a closure somehow so it's harder to get at in case of XSS? // one could change the homeserver as well so the token gets sent there, so both must be protected from read/write this._homeserver = homeserver; diff --git a/src/matrix/net/Reconnector.ts b/src/matrix/net/Reconnector.ts index 0d20b623..607ba0b4 100644 --- a/src/matrix/net/Reconnector.ts +++ b/src/matrix/net/Reconnector.ts @@ -27,6 +27,12 @@ export enum ConnectionStatus { "Online" }; +type Ctor = { + retryDelay: ExponentialRetryDelay; + createMeasure: () => TimeMeasure; + onlineStatus: OnlineStatus +}; + export class Reconnector { private readonly _retryDelay: ExponentialRetryDelay; private readonly _createTimeMeasure: () => TimeMeasure; @@ -36,7 +42,7 @@ export class Reconnector { private _versionsResponse?: IVersionResponse; private _stateSince: TimeMeasure; - constructor({retryDelay, createMeasure, onlineStatus}: {retryDelay: ExponentialRetryDelay, createMeasure: () => TimeMeasure, onlineStatus: OnlineStatus}) { + constructor({retryDelay, createMeasure, onlineStatus}: Ctor) { this._onlineStatus = onlineStatus; this._retryDelay = retryDelay; this._createTimeMeasure = createMeasure;