index : matrix-js-sdk

My fork of matrix-js-sdk

diff options
context:
space:
mode:
authorMichael Telatynski <[email protected]>2020-06-03 10:47:10 +0100
committerGitHub <[email protected]>2020-06-03 10:47:10 +0100
commitc525a19df58d4dc507155c763edbaa425dc22202 (patch)
treec572b8391dad65f8a193e0d5475645a3fed189ec
parenta987a31667ae6aa14389c4e69eb5aafdde645822 (diff)
parent10329c3436e97aeb76392f58cc4b8d163118a1df (diff)
downloadmatrix-js-sdk-c525a19df58d4dc507155c763edbaa425dc22202.tar.gz
Merge pull request #1394 from matrix-org/t3chguy/e2eedefault
Add js-sdk mechanism for polling client well-known for config
-rw-r--r--src/client.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/client.js b/src/client.js
index 114f5dd6..d390441e 100644
--- a/src/client.js
+++ b/src/client.js
@@ -54,6 +54,7 @@ import {randomString} from './randomstring';
import {PushProcessor} from "./pushprocessor";
import {encodeBase64, decodeBase64} from "./crypto/olmlib";
import { User } from "./models/user";
+import {AutoDiscovery} from "./autodiscovery";
const SCROLLBACK_DELAY_MS = 3000;
export const CRYPTO_ENABLED = isCryptoAvailable();
@@ -4719,6 +4720,9 @@ MatrixClient.prototype.deactivateSynapseUser = function(userId) {
* @param {Boolean=} opts.lazyLoadMembers True to not load all membership events during
* initial sync but fetch them when needed by calling `loadOutOfBandMembers`
* This will override the filter option at this moment.
+ * @param {Number=} opts.clientWellKnownPollPeriod The number of seconds between polls
+ * to /.well-known/matrix/client, undefined to disable. This should be in the order of hours.
+ * Default: undefined.
*/
MatrixClient.prototype.startClient = async function(opts) {
if (this.clientRunning) {
@@ -4767,6 +4771,29 @@ MatrixClient.prototype.startClient = async function(opts) {
this._clientOpts = opts;
this._syncApi = new SyncApi(this, opts);
this._syncApi.sync();
+
+ if (opts.clientWellKnownPollPeriod !== undefined) {
+ this._clientWellKnownIntervalID =
+ setInterval(() => {
+ this._fetchClientWellKnown();
+ }, 1000 * opts.clientWellKnownPollPeriod);
+ this._fetchClientWellKnown();
+ }
+};
+
+MatrixClient.prototype._fetchClientWellKnown = async function() {
+ try {
+ this._clientWellKnown = await AutoDiscovery.getRawClientConfig(this.getDomain());
+ this.emit("WellKnown.client", this._clientWellKnown);
+ } catch (err) {
+ logger.error("Failed to get client well-known", err);
+ this._clientWellKnown = undefined;
+ this.emit("WellKnown.error", err);
+ }
+};
+
+MatrixClient.prototype.getClientWellKnown = function() {
+ return this._clientWellKnown;
};
/**
@@ -4808,6 +4835,9 @@ MatrixClient.prototype.stopClient = function() {
this._peekSync.stopPeeking();
}
global.clearTimeout(this._checkTurnServersTimeoutID);
+ if (this._clientWellKnownIntervalID !== undefined) {
+ global.clearInterval(this._clientWellKnownIntervalID);
+ }
};
/**