Skip to content

Commit ca0e843

Browse files
committed
Add the livekit URL in matroyshka mode
This is a bit of a hack, as commented. The way to make it less of a hack is there too. Fixes embedded mode, although users will get a permission prompt without matrix-org/matrix-react-sdk#11209. Fixes #1201
1 parent 3c560ed commit ca0e843

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/widget.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type { MatrixClient } from "matrix-js-sdk/src/client";
2323
import type { IWidgetApiRequest } from "matrix-widget-api";
2424
import { LazyEventEmitter } from "./LazyEventEmitter";
2525
import { getUrlParams } from "./UrlParams";
26+
import { Config } from "./config/Config";
2627

2728
// Subset of the actions in matrix-react-sdk
2829
export enum ElementWidgetActions {
@@ -156,9 +157,33 @@ export const widget: WidgetHelpers | null = (() => {
156157
timelineSupport: true,
157158
useE2eForGroupCall: e2eEnabled,
158159
fallbackICEServerAllowed: allowIceFallback,
160+
// XXX: The client expects the list of foci in its constructor, but we don't
161+
// know this until we fetch the config file. However, we can't wait to construct
162+
// the client object or we'll miss the 'capabilities' request from the host app.
163+
// As of writing this, I have made the embedded widget client send the 'contentLoaded'
164+
// message so that we can use the widget API in less racy mode, but we need to change
165+
// element-web to use waitForIFrameLoad=false. Once that change has rolled out,
166+
// we can just start the client after we've fetched the config.
167+
foci: [],
159168
}
160169
);
161-
const clientPromise = client.startClient().then(() => client);
170+
171+
const clientPromise = new Promise((resolve) => {
172+
(async () => {
173+
await Config.init();
174+
const livekit = Config.get().livekit;
175+
const focus = livekit?.livekit_service_url;
176+
// Now we've fetched the config, be evil and use the getter to inject the focus
177+
// into the client (see above XXX).
178+
if (focus) {
179+
client.getFoci().push({
180+
livekitServiceUrl: livekit.livekit_service_url,
181+
});
182+
}
183+
await client.startClient();
184+
resolve(client);
185+
})();
186+
});
162187

163188
return { api, lazyActions, client: clientPromise };
164189
} else {

0 commit comments

Comments
 (0)