mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-21 00:28:08 +08:00
Be stricter with what is passed in to the openid components
This commit is contained in:
parent
9e95e8b5a7
commit
f2eabec382
@ -14,7 +14,6 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { MatrixClient } from "matrix-js-sdk";
|
||||
import React, {
|
||||
ReactNode,
|
||||
createContext,
|
||||
@ -24,11 +23,16 @@ import React, {
|
||||
} from "react";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import { SFUConfig, getSFUConfigWithOpenID } from "./openIDSFU";
|
||||
import {
|
||||
OpenIDClientParts,
|
||||
SFUConfig,
|
||||
getSFUConfigWithOpenID,
|
||||
} from "./openIDSFU";
|
||||
import { ErrorView, LoadingView } from "../FullScreenView";
|
||||
|
||||
interface Props {
|
||||
client: MatrixClient;
|
||||
client: OpenIDClientParts;
|
||||
livekitServiceURL: string;
|
||||
roomName: string;
|
||||
children: ReactNode;
|
||||
}
|
||||
@ -37,21 +41,30 @@ const SFUConfigContext = createContext<SFUConfig>(undefined);
|
||||
|
||||
export const useSFUConfig = () => useContext(SFUConfigContext);
|
||||
|
||||
export function OpenIDLoader({ client, roomName, children }: Props) {
|
||||
export function OpenIDLoader({
|
||||
client,
|
||||
livekitServiceURL,
|
||||
roomName,
|
||||
children,
|
||||
}: Props) {
|
||||
const [sfuConfig, setSFUConfig] = useState<SFUConfig>();
|
||||
const [error, setError] = useState<Error>();
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
const result = await getSFUConfigWithOpenID(client, roomName);
|
||||
const result = await getSFUConfigWithOpenID(
|
||||
client,
|
||||
livekitServiceURL,
|
||||
roomName
|
||||
);
|
||||
setSFUConfig(result);
|
||||
} catch (e) {
|
||||
logger.error("Failed to fetch SFU config: ", e);
|
||||
setError(new Error("Failed to fetch SFU config"));
|
||||
}
|
||||
})();
|
||||
}, [client, roomName]);
|
||||
}, [client, livekitServiceURL, roomName]);
|
||||
|
||||
if (error) {
|
||||
return <ErrorView error={error} />;
|
||||
|
@ -17,27 +17,26 @@ limitations under the License.
|
||||
import { MatrixClient } from "matrix-js-sdk";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import { Config } from "../config/Config";
|
||||
|
||||
export interface SFUConfig {
|
||||
url: string;
|
||||
jwt: string;
|
||||
}
|
||||
|
||||
// The bits we need from MatrixClient
|
||||
export type OpenIDClientParts = Pick<
|
||||
MatrixClient,
|
||||
"getOpenIdToken" | "getDeviceId"
|
||||
>;
|
||||
|
||||
export async function getSFUConfigWithOpenID(
|
||||
client: MatrixClient,
|
||||
client: OpenIDClientParts,
|
||||
livekitServiceURL: string,
|
||||
roomName: string
|
||||
): Promise<SFUConfig> {
|
||||
const openIdToken = await client.getOpenIdToken();
|
||||
logger.debug("Got openID token", openIdToken);
|
||||
|
||||
const livekitCfg = Config.get().livekit;
|
||||
|
||||
if (!livekitCfg?.livekit_service_url) {
|
||||
throw new Error("No livekit service URL defined");
|
||||
}
|
||||
|
||||
const res = await fetch(livekitCfg.livekit_service_url + "/sfu/get", {
|
||||
const res = await fetch(livekitServiceURL + "/sfu/get", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
@ -36,6 +36,7 @@ import { UserChoices } from "../livekit/useLiveKit";
|
||||
import { findDeviceByName } from "../media-utils";
|
||||
import { OpenIDLoader } from "../livekit/OpenIDLoader";
|
||||
import { ActiveCall } from "./InCallView";
|
||||
import { Config } from "../config/Config";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@ -219,11 +220,21 @@ export function GroupCallView({
|
||||
undefined
|
||||
);
|
||||
|
||||
const lkServiceURL = Config.get().livekit?.livekit_service_url;
|
||||
|
||||
if (!lkServiceURL) {
|
||||
return <ErrorView error={new Error("No livekit_service_url defined")} />;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <ErrorView error={error} />;
|
||||
} else if (state === GroupCallState.Entered && userChoices) {
|
||||
return (
|
||||
<OpenIDLoader client={client} roomName={matrixInfo.roomName}>
|
||||
<OpenIDLoader
|
||||
client={client}
|
||||
livekitServiceURL={lkServiceURL}
|
||||
roomName={matrixInfo.roomName}
|
||||
>
|
||||
<ActiveCall
|
||||
client={client}
|
||||
groupCall={groupCall}
|
||||
|
Loading…
Reference in New Issue
Block a user