From 95a54c99e44eb74ca9838f7f236b22b932b2c163 Mon Sep 17 00:00:00 2001 From: Timo K Date: Mon, 19 Feb 2024 12:40:44 +0100 Subject: [PATCH] Add customHomeserver url to urlParams. Signed-off-by: Timo K --- docs/url-params.md | 20 ++++++++++++++++++++ src/UrlParams.ts | 16 ++++++++++++++++ src/config/Config.ts | 11 ++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/docs/url-params.md b/docs/url-params.md index 266eee8f..bfbd267f 100644 --- a/docs/url-params.md +++ b/docs/url-params.md @@ -199,3 +199,23 @@ If set to false, the widget will show a blank page after leaving the call. ``` returnToLobby: boolean; (default: false) ``` + +**viaServers** +This defines the homeserver that is going to be used when joining a room. +It has to be set to a non default value for links to rooms +that are not on the default homeserver, +that is in use for the current user. + +``` +viaServers: string; (default: undefined) +``` + +**customHomeserver** +This defines the homeserver that is going to be used when registering +a new (guest) user. +This can be user to configure a non default guest user server when +creating a spa link. + +``` +customHomeserver: string; (default: undefined) +``` diff --git a/src/UrlParams.ts b/src/UrlParams.ts index da2a8aae..3977bfc4 100644 --- a/src/UrlParams.ts +++ b/src/UrlParams.ts @@ -130,6 +130,20 @@ export interface UrlParams { * This is useful for video rooms. */ returnToLobby: boolean; + /** + * This defines the homeserver that is going to be used when joining a room. + * It has to be set to a non default value for links to rooms + * that are not on the default homeserver, + * that is in use for the current user. + */ + viaServers: string | null; + /** + * This defines the homeserver that is going to be used when registering + * a new (guest) user. + * This can be user to configure a non default guest user server when + * creating a spa link. + */ + customHomeserver: string | null; } // This is here as a stopgap, but what would be far nicer is a function that @@ -229,6 +243,8 @@ export const getUrlParams = ( perParticipantE2EE: parser.getFlagParam("perParticipantE2EE"), skipLobby: parser.getFlagParam("skipLobby"), returnToLobby: parser.getFlagParam("returnToLobby"), + viaServers: parser.getParam("viaServers"), + customHomeserver: parser.getParam("customHomeserver"), }; }; diff --git a/src/config/Config.ts b/src/config/Config.ts index 0930af49..713afd3e 100644 --- a/src/config/Config.ts +++ b/src/config/Config.ts @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +import { getUrlParams } from "../UrlParams"; import { DEFAULT_CONFIG, ConfigOptions, @@ -45,10 +46,18 @@ export class Config { // Convenience accessors public static defaultHomeserverUrl(): string | undefined { - return Config.get().default_server_config?.["m.homeserver"].base_url; + return ( + getUrlParams().customHomeserver ?? + Config.get().default_server_config?.["m.homeserver"].base_url + ); } public static defaultServerName(): string | undefined { + const customHomeserver = getUrlParams().customHomeserver; + if (customHomeserver) { + const url = new URL(customHomeserver); + return url.hostname; + } return Config.get().default_server_config?.["m.homeserver"].server_name; }