mirror of
https://github.com/vector-im/element-call.git
synced 2026-10-16 23:45:50 +00:00
The remaining reads of the widget global were all asking one of two different questions, so they get two different answers. The app shell — the auth hooks, automatic guest registration, the group call loader's diagnostic and the initial mute state — wants to know whether Element Call was launched as a widget. That is a property of the URL it was launched with, so expose the isWidget that computeUrlParams already computed internally, documented as being for shell use only. The call interface — whether to offer the profile settings tab — wants to know something about its host, so it asks the bridge. A host that can dismiss Element Call owns the user's account, so their profile is not ours to edit; this reuses the close capability as a proxy, with a TODO alongside the others. ClientContext also takes supportsReactions from the bridge rather than checking four widget capabilities itself, which removes widgetApi from InitResult — a field that was always null outside widget mode. Note this changes behaviour for a malformed widget URL: one carrying a widget ID and parent URL but missing the room, user, device or base URL would previously have fallen back to registering a guest user, and will now not.
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
/*
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE in the repository root for full details.
|
|
*/
|
|
|
|
import { type ICreateClientOpts, MatrixError } from "matrix-js-sdk";
|
|
import { logger } from "matrix-js-sdk/lib/logger";
|
|
|
|
import { Config } from "../config/Config";
|
|
import { fallbackICEServerAllowed, initClient } from "./matrix";
|
|
import type { InitResult, Session } from "../ClientContext";
|
|
|
|
export async function initSPA(
|
|
loadSession: () => Session | undefined,
|
|
clearSession: () => void,
|
|
): Promise<InitResult | null> {
|
|
// We're running as a standalone application
|
|
try {
|
|
const session = loadSession();
|
|
if (!session) {
|
|
logger.log("No session stored; continuing without a client");
|
|
return null;
|
|
}
|
|
|
|
logger.log("Using a standalone client");
|
|
|
|
/* eslint-disable camelcase */
|
|
const { user_id, device_id, access_token, passwordlessUser } = session;
|
|
const initClientParams: ICreateClientOpts = {
|
|
baseUrl: Config.defaultHomeserverUrl()!,
|
|
accessToken: access_token,
|
|
userId: user_id,
|
|
deviceId: device_id,
|
|
fallbackICEServerAllowed,
|
|
livekitServiceURL: Config.get().livekit?.livekit_service_url,
|
|
};
|
|
|
|
try {
|
|
const client = await initClient(initClientParams, true);
|
|
return {
|
|
client,
|
|
passwordlessUser,
|
|
};
|
|
} catch (err) {
|
|
if (err instanceof MatrixError && err.errcode === "M_UNKNOWN_TOKEN") {
|
|
// We can't use this session anymore, so let's log it out
|
|
logger.log(
|
|
"The session from local store is invalid; continuing without a client",
|
|
);
|
|
clearSession();
|
|
// returning null = "no client` pls register" (undefined = "loading" which is the current value when reaching this line)
|
|
return null;
|
|
}
|
|
throw err;
|
|
}
|
|
} catch (err) {
|
|
clearSession();
|
|
throw err;
|
|
}
|
|
}
|