Merge v0.4.2 hotfixes

This commit is contained in:
David Baker
2023-07-12 17:57:54 +01:00
parent 89c326f0bb
commit e264a71d1e
7 changed files with 92 additions and 49 deletions

View File

@@ -60,7 +60,7 @@
"i18next-http-backend": "^1.4.4", "i18next-http-backend": "^1.4.4",
"livekit-client": "1.12.0", "livekit-client": "1.12.0",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#d79d9ae69c3220c02406706d4a1ec52c22c44fbd", "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#b698217445318f453e0b1086364a33113eaa85d9",
"matrix-widget-api": "^1.3.1", "matrix-widget-api": "^1.3.1",
"mermaid": "^8.13.8", "mermaid": "^8.13.8",
"normalize.css": "^8.0.1", "normalize.css": "^8.0.1",

View File

@@ -327,10 +327,6 @@ async function loadClient(): Promise<InitResult> {
logger.log("Using a standalone client"); logger.log("Using a standalone client");
const foci = Config.get().livekit
? [{ livekitServiceUrl: Config.get().livekit!.livekit_service_url }]
: undefined;
/* eslint-disable camelcase */ /* eslint-disable camelcase */
const { user_id, device_id, access_token, passwordlessUser } = session; const { user_id, device_id, access_token, passwordlessUser } = session;
const initClientParams = { const initClientParams = {
@@ -339,7 +335,7 @@ async function loadClient(): Promise<InitResult> {
userId: user_id, userId: user_id,
deviceId: device_id, deviceId: device_id,
fallbackICEServerAllowed: fallbackICEServerAllowed, fallbackICEServerAllowed: fallbackICEServerAllowed,
foci, livekitServiceURL: Config.get().livekit!.livekit_service_url,
}; };
try { try {

View File

@@ -22,6 +22,7 @@ import {
useState, useState,
} from "react"; } from "react";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { GroupCall } from "matrix-js-sdk";
import { import {
OpenIDClientParts, OpenIDClientParts,
@@ -32,7 +33,7 @@ import { ErrorView, LoadingView } from "../FullScreenView";
interface Props { interface Props {
client: OpenIDClientParts; client: OpenIDClientParts;
livekitServiceURL: string; groupCall: GroupCall;
roomName: string; roomName: string;
children: ReactNode; children: ReactNode;
} }
@@ -41,12 +42,7 @@ const SFUConfigContext = createContext<SFUConfig | undefined>(undefined);
export const useSFUConfig = () => useContext(SFUConfigContext); export const useSFUConfig = () => useContext(SFUConfigContext);
export function OpenIDLoader({ export function OpenIDLoader({ client, groupCall, roomName, children }: Props) {
client,
livekitServiceURL,
roomName,
children,
}: Props) {
const [state, setState] = useState< const [state, setState] = useState<
SFUConfigLoading | SFUConfigLoaded | SFUConfigFailed SFUConfigLoading | SFUConfigLoaded | SFUConfigFailed
>({ kind: "loading" }); >({ kind: "loading" });
@@ -56,7 +52,7 @@ export function OpenIDLoader({
try { try {
const result = await getSFUConfigWithOpenID( const result = await getSFUConfigWithOpenID(
client, client,
livekitServiceURL, groupCall,
roomName roomName
); );
setState({ kind: "loaded", sfuConfig: result }); setState({ kind: "loaded", sfuConfig: result });
@@ -65,7 +61,7 @@ export function OpenIDLoader({
setState({ kind: "failed", error: e as Error }); setState({ kind: "failed", error: e as Error });
} }
})(); })();
}, [client, livekitServiceURL, roomName]); }, [client, groupCall, roomName]);
switch (state.kind) { switch (state.kind) {
case "loading": case "loading":

View File

@@ -14,9 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { MatrixClient } from "matrix-js-sdk"; import { GroupCall, IOpenIDToken, MatrixClient } from "matrix-js-sdk";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { Config } from "../config/Config";
export interface SFUConfig { export interface SFUConfig {
url: string; url: string;
jwt: string; jwt: string;
@@ -30,12 +32,68 @@ export type OpenIDClientParts = Pick<
export async function getSFUConfigWithOpenID( export async function getSFUConfigWithOpenID(
client: OpenIDClientParts, client: OpenIDClientParts,
livekitServiceURL: string, groupCall: GroupCall,
roomName: string roomName: string
): Promise<SFUConfig> { ): Promise<SFUConfig> {
const openIdToken = await client.getOpenIdToken(); const openIdToken = await client.getOpenIdToken();
logger.debug("Got openID token", openIdToken); logger.debug("Got openID token", openIdToken);
// if the call has a livekit service URL, try it.
if (groupCall.livekitServiceURL) {
try {
logger.info(`Trying to get JWT from ${groupCall.livekitServiceURL}...`);
const sfuConfig = await getLiveKitJWT(
client,
groupCall.livekitServiceURL,
roomName,
openIdToken
);
return sfuConfig;
} catch (e) {
logger.warn(
`Failed to get JWT from group call's configured URL of ${groupCall.livekitServiceURL}.`,
e
);
}
}
// otherwise, try our configured one and, if it works, update the call's service URL in the state event
// NB. This wuill update it for everyone so we may end up with multiple clients updating this when they
// join at similar times, but we don't have a huge number of options here.
const urlFromConf = Config.get().livekit!.livekit_service_url;
logger.info(`Trying livekit service URL from our config: ${urlFromConf}...`);
try {
const sfuConfig = await getLiveKitJWT(
client,
urlFromConf,
roomName,
openIdToken
);
logger.info(`Updating call livekit service URL with: ${urlFromConf}...`);
try {
await groupCall.updateLivekitServiceURL(urlFromConf);
} catch (e) {
logger.warn(
`Failed to update call livekit service URL: continuing anyway.`
);
}
return sfuConfig;
} catch (e) {
logger.error("Failed to get JWT from URL defined in Config.", e);
throw e;
}
}
async function getLiveKitJWT(
client: OpenIDClientParts,
livekitServiceURL: string,
roomName: string,
openIDToken: IOpenIDToken
): Promise<SFUConfig> {
try {
const res = await fetch(livekitServiceURL + "/sfu/get", { const res = await fetch(livekitServiceURL + "/sfu/get", {
method: "POST", method: "POST",
headers: { headers: {
@@ -43,7 +101,7 @@ export async function getSFUConfigWithOpenID(
}, },
body: JSON.stringify({ body: JSON.stringify({
room: roomName, room: roomName,
openid_token: openIdToken, openid_token: openIDToken,
device_id: client.getDeviceId(), device_id: client.getDeviceId(),
}), }),
}); });
@@ -51,4 +109,7 @@ export async function getSFUConfigWithOpenID(
throw new Error("SFU Config fetch failed with status code " + res.status); throw new Error("SFU Config fetch failed with status code " + res.status);
} }
return await res.json(); return await res.json();
} catch (e) {
throw new Error("SFU Config fetch failed with exception " + e);
}
} }

View File

@@ -36,7 +36,6 @@ import { UserChoices } from "../livekit/useLiveKit";
import { findDeviceByName } from "../media-utils"; import { findDeviceByName } from "../media-utils";
import { OpenIDLoader } from "../livekit/OpenIDLoader"; import { OpenIDLoader } from "../livekit/OpenIDLoader";
import { ActiveCall } from "./InCallView"; import { ActiveCall } from "./InCallView";
import { Config } from "../config/Config";
declare global { declare global {
interface Window { interface Window {
@@ -219,20 +218,13 @@ export function GroupCallView({
undefined undefined
); );
const livekitServiceURL =
groupCall.foci[0]?.livekitServiceUrl ??
Config.get().livekit?.livekit_service_url;
if (!livekitServiceURL) {
return <ErrorView error={new Error("No livekit_service_url defined")} />;
}
if (error) { if (error) {
return <ErrorView error={error} />; return <ErrorView error={error} />;
} else if (state === GroupCallState.Entered && userChoices) { } else if (state === GroupCallState.Entered && userChoices) {
return ( return (
<OpenIDLoader <OpenIDLoader
client={client} client={client}
livekitServiceURL={livekitServiceURL} groupCall={groupCall}
roomName={`${groupCall.room.roomId}-${groupCall.groupCallId}`} roomName={`${groupCall.room.roomId}-${groupCall.groupCallId}`}
> >
<ActiveCall <ActiveCall

View File

@@ -164,7 +164,7 @@ export const widget: WidgetHelpers | null = (() => {
// message so that we can use the widget API in less racy mode, but we need to change // 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, // element-web to use waitForIFrameLoad=false. Once that change has rolled out,
// we can just start the client after we've fetched the config. // we can just start the client after we've fetched the config.
foci: [], livekitServiceURL: undefined,
} }
); );
@@ -178,9 +178,7 @@ export const widget: WidgetHelpers | null = (() => {
// Now we've fetched the config, be evil and use the getter to inject the focus // Now we've fetched the config, be evil and use the getter to inject the focus
// into the client (see above XXX). // into the client (see above XXX).
if (focus) { if (focus) {
client.getFoci().push({ client.setLivekitServiceURL(livekit.livekit_service_url);
livekitServiceUrl: livekit.livekit_service_url,
});
} }
await client.startClient(); await client.startClient();
resolve(client); resolve(client);

View File

@@ -2187,9 +2187,9 @@
clsx "^1.2.1" clsx "^1.2.1"
"@matrix-org/matrix-sdk-crypto-js@^0.1.1": "@matrix-org/matrix-sdk-crypto-js@^0.1.1":
version "0.1.2" version "0.1.3"
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-js/-/matrix-sdk-crypto-js-0.1.2.tgz#b58679e161f3d734359a8665922956309b1a4417" resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-js/-/matrix-sdk-crypto-js-0.1.3.tgz#19981e7613d3673d07c885a98d39276b5fe74ef0"
integrity sha512-bbal0RcWwerS/DgqhOgM7wkXJ2YSv9fySK/qgLlrAsdYLpMSTqG8wDQ89/v+RYo9WmA5hwUN/wXcCDdFaFEXQQ== integrity sha512-RcRlE3wcMnE5ijACHIHmhXFogEEJdIcb/CbJ4rK1PCMduQ4yvxycVpMxwh7aKxFNitZbHZLCK7TfRzUpzjU2tw==
"@matrix-org/olm@https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz": "@matrix-org/olm@https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.14.tgz":
version "3.2.14" version "3.2.14"
@@ -11012,9 +11012,9 @@ matrix-events-sdk@0.0.1:
resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1.tgz#c8c38911e2cb29023b0bbac8d6f32e0de2c957dd" resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1.tgz#c8c38911e2cb29023b0bbac8d6f32e0de2c957dd"
integrity sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA== integrity sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA==
"matrix-js-sdk@github:matrix-org/matrix-js-sdk#d79d9ae69c3220c02406706d4a1ec52c22c44fbd": "matrix-js-sdk@github:matrix-org/matrix-js-sdk#b698217445318f453e0b1086364a33113eaa85d9":
version "26.2.0" version "26.2.0"
resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/d79d9ae69c3220c02406706d4a1ec52c22c44fbd" resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/b698217445318f453e0b1086364a33113eaa85d9"
dependencies: dependencies:
"@babel/runtime" "^7.12.5" "@babel/runtime" "^7.12.5"
"@matrix-org/matrix-sdk-crypto-js" "^0.1.1" "@matrix-org/matrix-sdk-crypto-js" "^0.1.1"