Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the livekit URL in matroyshka mode #1225

Merged
merged 3 commits into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type { MatrixClient } from "matrix-js-sdk/src/client";
import type { IWidgetApiRequest } from "matrix-widget-api";
import { LazyEventEmitter } from "./LazyEventEmitter";
import { getUrlParams } from "./UrlParams";
import { Config } from "./config/Config";

// Subset of the actions in matrix-react-sdk
export enum ElementWidgetActions {
Expand Down Expand Up @@ -156,9 +157,35 @@ export const widget: WidgetHelpers | null = (() => {
timelineSupport: true,
useE2eForGroupCall: e2eEnabled,
fallbackICEServerAllowed: allowIceFallback,
// XXX: The client expects the list of foci in its constructor, but we don't
// know this until we fetch the config file. However, we can't wait to construct
// the client object or we'll miss the 'capabilities' request from the host app.
// As of writing this, I have made the embedded widget client send the 'contentLoaded'
// message so that we can use the widget API in less racy mode, but we need to change
// element-web to use waitForIFrameLoad=false. Once that change has rolled out,
// we can just start the client after we've fetched the config.
foci: [],
}
);
const clientPromise = client.startClient().then(() => client);

const clientPromise = new Promise<MatrixClient>((resolve) => {
(async () => {
// wait for the config file to be ready (we load very early on so it might not
// be otherwise)
await Config.init();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be redundant with what the initializer is doing? do we not have the initializer in embedded mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, added a comment

Copy link
Contributor

@toger5 toger5 Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This migh result in duplicated downloads of the json right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config.init has a few lines that look like this:

    if (Config.internalInstance?.initPromise) {
      return Config.internalInstance.initPromise;
    }

so that doesn't appear to be the case. If there's already a request promise in flight, it returns that same promise.

const livekit = Config.get().livekit;
const focus = livekit?.livekit_service_url;
// Now we've fetched the config, be evil and use the getter to inject the focus
// into the client (see above XXX).
if (focus) {
client.getFoci().push({
livekitServiceUrl: livekit.livekit_service_url,
});
}
await client.startClient();
resolve(client);
})();
});

return { api, lazyActions, client: clientPromise };
} else {
Expand Down