Add Jitsi auth check

Checks for auth needed by looking up a well-known file from the preferred Jitsi domain. No file existing will assume no auth.
pull/21833/head
Jason Robinson 2020-09-04 10:03:30 +03:00
parent 0d290c9bd2
commit 5d8a082eb1
1 changed files with 24 additions and 0 deletions

View File

@ -34,6 +34,30 @@ export class Jitsi {
return this.domain || 'jitsi.riot.im';
}
/**
* Checks for auth needed by looking up a well-known file
*
* If the file does not exist, we assume no auth.
*
* See TODO add link
*/
public async getJitsiAuth(): Promise<string|null> {
if (!this.preferredDomain) {
return null;
}
let data;
try {
const response = await fetch(`https://${this.preferredDomain}/.well-known/element/jitsi`);
data = await response.json();
} catch (error) {
return null;
}
if (data.auth) {
return data.auth;
}
return null;
}
public start() {
const cli = MatrixClientPeg.get();
cli.on("WellKnown.client", this.update);