2016-05-06 15:19:56 +02:00
|
|
|
/*
|
2024-09-09 15:57:16 +02:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
Copyright 2019-2022 The Matrix.org Foundation C.I.C.
|
2016-05-06 15:19:56 +02:00
|
|
|
Copyright 2016 OpenMarket Ltd
|
|
|
|
|
2024-09-09 15:57:16 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2016-05-06 15:19:56 +02:00
|
|
|
*/
|
|
|
|
|
2022-03-18 17:12:36 +01:00
|
|
|
import { Optional } from "matrix-events-sdk";
|
2023-04-26 11:36:00 +02:00
|
|
|
import { mergeWith } from "lodash";
|
2022-03-01 19:06:17 +01:00
|
|
|
|
2022-03-18 17:12:36 +01:00
|
|
|
import { SnakedObject } from "./utils/SnakedObject";
|
|
|
|
import { IConfigOptions, ISsoRedirectOptions } from "./IConfigOptions";
|
2023-04-26 11:36:00 +02:00
|
|
|
import { isObject, objectClone } from "./utils/objects";
|
|
|
|
import { DeepReadonly, Defaultize } from "./@types/common";
|
2022-03-01 19:53:09 +01:00
|
|
|
|
2022-03-18 17:12:36 +01:00
|
|
|
// see element-web config.md for docs, or the IConfigOptions interface for dev docs
|
2023-04-26 11:36:00 +02:00
|
|
|
export const DEFAULTS: DeepReadonly<IConfigOptions> = {
|
2020-07-09 19:25:03 +02:00
|
|
|
brand: "Element",
|
2023-06-14 09:45:19 +02:00
|
|
|
help_url: "https://element.io/help",
|
|
|
|
help_encryption_url: "https://element.io/help#encryption",
|
2016-05-06 15:19:56 +02:00
|
|
|
integrations_ui_url: "https://scalar.vector.im/",
|
|
|
|
integrations_rest_url: "https://scalar.vector.im/api",
|
2023-01-16 16:00:03 +01:00
|
|
|
uisi_autorageshake_app: "element-auto-uisi",
|
2023-10-13 15:24:00 +02:00
|
|
|
show_labs_settings: false,
|
2024-10-03 10:55:06 +02:00
|
|
|
force_verification: false,
|
2023-01-16 16:00:03 +01:00
|
|
|
|
2020-03-18 22:50:05 +01:00
|
|
|
jitsi: {
|
2022-03-18 17:12:36 +01:00
|
|
|
preferred_domain: "meet.element.io",
|
2020-03-18 22:50:05 +01:00
|
|
|
},
|
2022-09-16 17:12:27 +02:00
|
|
|
element_call: {
|
|
|
|
url: "https://call.element.io",
|
2022-09-25 16:57:25 +02:00
|
|
|
use_exclusively: false,
|
2022-10-07 22:16:35 +02:00
|
|
|
participant_limit: 8,
|
2022-10-07 20:10:17 +02:00
|
|
|
brand: "Element Call",
|
2022-09-16 17:12:27 +02:00
|
|
|
},
|
2022-03-18 17:12:36 +01:00
|
|
|
|
|
|
|
// @ts-ignore - we deliberately use the camelCase version here so we trigger
|
|
|
|
// the fallback behaviour. If we used the snake_case version then we'd break
|
|
|
|
// everyone's config which has the camelCase property because our default would
|
|
|
|
// be preferred over their config.
|
2020-09-17 01:23:37 +02:00
|
|
|
desktopBuilds: {
|
|
|
|
available: true,
|
2024-10-16 17:43:07 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
2022-03-03 18:51:38 +01:00
|
|
|
logo: require("../res/img/element-desktop-logo.svg").default,
|
2020-09-17 01:23:37 +02:00
|
|
|
url: "https://element.io/get-started",
|
|
|
|
},
|
2022-10-12 00:31:28 +02:00
|
|
|
voice_broadcast: {
|
2022-11-10 11:53:49 +01:00
|
|
|
chunk_length: 2 * 60, // two minutes
|
|
|
|
max_length: 4 * 60 * 60, // four hours
|
2022-10-12 00:31:28 +02:00
|
|
|
},
|
2023-04-26 11:36:00 +02:00
|
|
|
|
|
|
|
feedback: {
|
|
|
|
existing_issues_url:
|
|
|
|
"https://github.com/vector-im/element-web/issues?q=is%3Aopen+is%3Aissue+sort%3Areactions-%2B1-desc",
|
|
|
|
new_issue_url: "https://github.com/vector-im/element-web/issues/new/choose",
|
|
|
|
},
|
2023-10-13 11:43:39 +02:00
|
|
|
|
|
|
|
desktop_builds: {
|
|
|
|
available: true,
|
|
|
|
logo: "vector-icons/1024.png",
|
|
|
|
url: "https://element.io/download",
|
2024-07-30 15:16:21 +02:00
|
|
|
url_macos: "https://packages.element.io/desktop/install/macos/Element.dmg",
|
|
|
|
url_win64: "https://packages.element.io/desktop/install/win32/x64/Element%20Setup.exe",
|
|
|
|
url_win32: "https://packages.element.io/desktop/install/win32/ia32/Element%20Setup.exe",
|
|
|
|
url_linux: "https://element.io/download#linux",
|
2023-10-13 11:43:39 +02:00
|
|
|
},
|
|
|
|
mobile_builds: {
|
|
|
|
ios: "https://apps.apple.com/app/vector/id1083446067",
|
|
|
|
android: "https://play.google.com/store/apps/details?id=im.vector.app",
|
|
|
|
fdroid: "https://f-droid.org/repository/browse/?fdid=im.vector.app",
|
|
|
|
},
|
2016-05-06 15:19:56 +02:00
|
|
|
};
|
|
|
|
|
2023-04-26 11:36:00 +02:00
|
|
|
export type ConfigOptions = Defaultize<IConfigOptions, typeof DEFAULTS>;
|
|
|
|
|
|
|
|
function mergeConfig(
|
|
|
|
config: DeepReadonly<IConfigOptions>,
|
|
|
|
changes: DeepReadonly<Partial<IConfigOptions>>,
|
|
|
|
): DeepReadonly<IConfigOptions> {
|
|
|
|
// return { ...config, ...changes };
|
|
|
|
return mergeWith(objectClone(config), changes, (objValue, srcValue) => {
|
|
|
|
// Don't merge arrays, prefer values from newer object
|
|
|
|
if (Array.isArray(objValue)) {
|
|
|
|
return srcValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't allow objects to get nulled out, this will break our types
|
|
|
|
if (isObject(objValue) && !isObject(srcValue)) {
|
|
|
|
return objValue;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
type ObjectType<K extends keyof IConfigOptions> = IConfigOptions[K] extends object
|
|
|
|
? SnakedObject<NonNullable<IConfigOptions[K]>>
|
|
|
|
: Optional<SnakedObject<NonNullable<IConfigOptions[K]>>>;
|
|
|
|
|
2019-12-12 22:37:32 +01:00
|
|
|
export default class SdkConfig {
|
2023-04-26 11:36:00 +02:00
|
|
|
private static instance: DeepReadonly<IConfigOptions>;
|
|
|
|
private static fallback: SnakedObject<DeepReadonly<IConfigOptions>>;
|
2019-12-12 22:37:32 +01:00
|
|
|
|
2023-04-26 11:36:00 +02:00
|
|
|
private static setInstance(i: DeepReadonly<IConfigOptions>): void {
|
2019-12-12 22:37:32 +01:00
|
|
|
SdkConfig.instance = i;
|
2022-03-18 17:12:36 +01:00
|
|
|
SdkConfig.fallback = new SnakedObject(i);
|
2019-12-12 22:37:32 +01:00
|
|
|
|
|
|
|
// For debugging purposes
|
2022-03-01 19:06:17 +01:00
|
|
|
window.mxReactSdkConfig = i;
|
2019-12-12 22:37:32 +01:00
|
|
|
}
|
|
|
|
|
2022-03-18 17:12:36 +01:00
|
|
|
public static get(): IConfigOptions;
|
|
|
|
public static get<K extends keyof IConfigOptions>(key: K, altCaseName?: string): IConfigOptions[K];
|
|
|
|
public static get<K extends keyof IConfigOptions = never>(
|
2022-12-12 12:24:14 +01:00
|
|
|
key?: K,
|
|
|
|
altCaseName?: string,
|
2023-04-26 11:36:00 +02:00
|
|
|
): DeepReadonly<IConfigOptions> | DeepReadonly<IConfigOptions>[K] {
|
2022-03-18 17:12:36 +01:00
|
|
|
if (key === undefined) {
|
|
|
|
// safe to cast as a fallback - we want to break the runtime contract in this case
|
|
|
|
return SdkConfig.instance || <IConfigOptions>{};
|
|
|
|
}
|
|
|
|
return SdkConfig.fallback.get(key, altCaseName);
|
|
|
|
}
|
|
|
|
|
2023-04-26 11:36:00 +02:00
|
|
|
public static getObject<K extends keyof IConfigOptions>(key: K, altCaseName?: string): ObjectType<K> {
|
2022-03-18 17:12:36 +01:00
|
|
|
const val = SdkConfig.get(key, altCaseName);
|
2023-04-26 11:36:00 +02:00
|
|
|
if (isObject(val)) {
|
2022-03-18 17:12:36 +01:00
|
|
|
return new SnakedObject(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the same type for sensitive callers (some want `undefined` specifically)
|
2023-04-26 11:36:00 +02:00
|
|
|
return (val === undefined ? undefined : null) as ObjectType<K>;
|
2016-05-06 15:19:56 +02:00
|
|
|
}
|
|
|
|
|
2023-04-26 11:36:00 +02:00
|
|
|
public static put(cfg: DeepReadonly<ConfigOptions>): void {
|
|
|
|
SdkConfig.setInstance(mergeConfig(DEFAULTS, cfg));
|
2016-05-06 15:19:56 +02:00
|
|
|
}
|
|
|
|
|
2022-03-18 17:12:36 +01:00
|
|
|
/**
|
2023-04-26 11:36:00 +02:00
|
|
|
* Resets the config.
|
2022-03-18 17:12:36 +01:00
|
|
|
*/
|
2023-04-26 11:36:00 +02:00
|
|
|
public static reset(): void {
|
|
|
|
SdkConfig.setInstance(mergeConfig(DEFAULTS, {})); // safe to cast - defaults will be applied
|
2016-05-06 15:19:56 +02:00
|
|
|
}
|
2019-04-15 22:46:00 +02:00
|
|
|
|
2023-04-26 11:36:00 +02:00
|
|
|
public static add(cfg: Partial<ConfigOptions>): void {
|
|
|
|
SdkConfig.put(mergeConfig(SdkConfig.get(), cfg));
|
2019-04-15 22:46:00 +02:00
|
|
|
}
|
2016-05-06 15:19:56 +02:00
|
|
|
}
|
2021-10-21 16:35:00 +02:00
|
|
|
|
2022-03-18 17:12:36 +01:00
|
|
|
export function parseSsoRedirectOptions(config: IConfigOptions): ISsoRedirectOptions {
|
2021-10-21 16:35:00 +02:00
|
|
|
// Ignore deprecated options if the config is using new ones
|
|
|
|
if (config.sso_redirect_options) return config.sso_redirect_options;
|
|
|
|
|
|
|
|
// We can cheat here because the default is false anyways
|
|
|
|
if (config.sso_immediate_redirect) return { immediate: true };
|
|
|
|
|
|
|
|
// Default: do nothing
|
|
|
|
return {};
|
|
|
|
}
|