@@ -23,6 +23,7 @@ import type { MatrixClient } from "matrix-js-sdk/src/client";
23
23
import type { IWidgetApiRequest } from "matrix-widget-api" ;
24
24
import { LazyEventEmitter } from "./LazyEventEmitter" ;
25
25
import { getUrlParams } from "./UrlParams" ;
26
+ import { Config } from "./config/Config" ;
26
27
27
28
// Subset of the actions in matrix-react-sdk
28
29
export enum ElementWidgetActions {
@@ -156,9 +157,33 @@ export const widget: WidgetHelpers | null = (() => {
156
157
timelineSupport : true ,
157
158
useE2eForGroupCall : e2eEnabled ,
158
159
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 : [ ] ,
159
168
}
160
169
) ;
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
+ } ) ;
162
187
163
188
return { api, lazyActions, client : clientPromise } ;
164
189
} else {
0 commit comments