Return the widget from initializeWidget instead of assigning a global

Element Call reached the widget API through a mutable module-level
binding, which every consumer imported directly. Nothing outside the app
shell needs it any more, so hand it back from initializeWidget and thread
it through: the initializer returns it, main passes it to App, and App
uses it to build the host bridge and to await the client the host is
lending us.

ClientContext's loadClient is now only about restoring or creating a
session of Element Call's own, since a widget's client arrives as a prop
like any other host's would.

Also fixes an early return added in the previous commit, which skipped
starting the analytics settings listener when a client was supplied. That
was harmless until now, but would have stopped analytics following the
user's choices in widget mode.

sdk/main.ts asked the host to close by hand; it now uses the bridge, which
also stops the transport as the app does.
This commit is contained in:
Valere
2026-09-02 16:56:09 +02:00
parent f6f47ede62
commit 182be8676d
7 changed files with 84 additions and 72 deletions
+5 -3
View File
@@ -32,7 +32,7 @@ import { Config } from "./config/Config";
import { seedSettingsFromConfig } from "./settings/settings";
import { platform } from "./Platform";
import { isFailure } from "./utils/fetch";
import { initializeWidget } from "./widget";
import { initializeWidget, type WidgetHelpers } from "./widget";
import { enableExtendedLivekitLogs } from "./settings/settings.ts";
import {
type AnalyticsConfig,
@@ -155,8 +155,8 @@ export class Initializer {
return !!Initializer.internalInstance?.isInitialized;
}
public static async initBeforeReact(): Promise<void> {
initializeWidget();
public static async initBeforeReact(): Promise<WidgetHelpers | null> {
const widget = initializeWidget();
const polyfills: Promise<unknown>[] = [];
if (shouldPolyfillSegmenter()) {
@@ -243,6 +243,8 @@ export class Initializer {
});
window.setLKLogLevel = setLKLogLevel;
return widget;
}
public static init(): Promise<void> | null {