Vite embedded build of Element Call (#3077)
* Embedded package build of Element Call Part of https://github.com/element-hq/element-call/issues/2994 This creates a new "embedded" build (vs "full" build) at the vite level. It will be used by a later PR that actually provides platform specific packages. Embedded build: - Uses relative URLs - Uses relative config.json path and other resource loading - Has a config.json built in - Doesn't include the public folder (e.g. favicon) Out of scope: - this doesn't attempt to exclude SPA functionality, so technically the build could be used in SPA - the above means that the crypto-wasm binary is included in the build * CI artifact name based on type of build * Update src/config/Config.ts
This commit is contained in:
@@ -29,7 +29,20 @@ export class Config {
|
||||
const internalInstance = new Config();
|
||||
Config.internalInstance = internalInstance;
|
||||
|
||||
Config.internalInstance.initPromise = downloadConfig("/config.json").then(
|
||||
let fetchTarget: string;
|
||||
|
||||
if (
|
||||
window.location.pathname.endsWith("/room/") ||
|
||||
window.location.pathname.endsWith("/room")
|
||||
) {
|
||||
// it looks like we are running in standalone mode so use the config at the root
|
||||
fetchTarget = new URL("/config.json", window.location.href).href;
|
||||
} else {
|
||||
// otherwise we are probably running as a widget so use the config in the same directory
|
||||
fetchTarget = "config.json";
|
||||
}
|
||||
|
||||
Config.internalInstance.initPromise = downloadConfig(fetchTarget).then(
|
||||
(config) => {
|
||||
internalInstance.config = merge({}, DEFAULT_CONFIG, config);
|
||||
},
|
||||
@@ -71,11 +84,8 @@ export class Config {
|
||||
private initPromise?: Promise<void>;
|
||||
}
|
||||
|
||||
async function downloadConfig(
|
||||
configJsonFilename: string,
|
||||
): Promise<ConfigOptions> {
|
||||
const url = new URL(configJsonFilename, window.location.href);
|
||||
const response = await fetch(url);
|
||||
async function downloadConfig(fetchTarget: string): Promise<ConfigOptions> {
|
||||
const response = await fetch(fetchTarget);
|
||||
|
||||
if (isFailure(response)) {
|
||||
// Lack of a config isn't an error, we should just use the defaults.
|
||||
|
||||
Reference in New Issue
Block a user