From a674131a8c6ab2e723ed14cc5ece896720395f3f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 3 Jun 2020 13:58:17 +0100 Subject: [PATCH] Fix Jitsi wellknown hooks Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/Lifecycle.js | 2 +- src/widgets/Jitsi.ts | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 0494628472..bf442e93d5 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -619,7 +619,7 @@ async function startMatrixClient(startSyncing=true) { } // Now that we have a MatrixClientPeg, update the Jitsi info - await Jitsi.getInstance().update(); + await Jitsi.getInstance().start(); // dispatch that we finished starting up to wire up any other bits // of the matrix client that cannot be set prior to starting up. diff --git a/src/widgets/Jitsi.ts b/src/widgets/Jitsi.ts index 4dda48c3a3..858685b86a 100644 --- a/src/widgets/Jitsi.ts +++ b/src/widgets/Jitsi.ts @@ -34,17 +34,20 @@ export class Jitsi { return this.domain || 'jitsi.riot.im'; } - public async update(): Promise { + public start() { + const cli = MatrixClientPeg.get(); + cli.on("WellKnown.client", this.update); + const discoveryResponse = cli.getClientWellKnown(); + if (discoveryResponse) { + // if we missed the first WellKnown.client event then call update anyway + this.update(discoveryResponse); + } + } + + private update = async (discoveryResponse): Promise => { // Start with a default of the config's domain let domain = (SdkConfig.get()['jitsi'] || {})['preferredDomain'] || 'jitsi.riot.im'; - const cli = MatrixClientPeg.get(); - const discoveryResponse = cli && MatrixClientPeg.get().getClientWellKnown(); - - if (cli) { - cli.on("WellKnown.client", () => this.update); - } - console.log("Attempting to get Jitsi conference information from homeserver"); if (discoveryResponse && discoveryResponse[JITSI_WK_PROPERTY]) { const wkPreferredDomain = discoveryResponse[JITSI_WK_PROPERTY]['preferredDomain']; @@ -54,7 +57,7 @@ export class Jitsi { // Put the result into memory for us to use later this.domain = domain; console.log("Jitsi conference domain:", this.preferredDomain); - } + }; /** * Parses the given URL into the data needed for a Jitsi widget, if the widget