From 23b8a61e7aae1b6d1fb43b269178af65053ada0d Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 30 Jun 2023 18:12:58 +0100 Subject: [PATCH] Provide sfu config via context --- src/livekit/OpenIDLoader.tsx | 26 +++++++++++++++++++------- src/room/GroupCallView.tsx | 26 ++++++++++++++------------ src/room/InCallView.tsx | 6 +++--- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/livekit/OpenIDLoader.tsx b/src/livekit/OpenIDLoader.tsx index c6d6bd9..34aa5ec 100644 --- a/src/livekit/OpenIDLoader.tsx +++ b/src/livekit/OpenIDLoader.tsx @@ -15,21 +15,29 @@ limitations under the License. */ import { MatrixClient } from "matrix-js-sdk"; -import React, { useEffect, useState } from "react"; +import React, { + ReactNode, + createContext, + useContext, + useEffect, + useState, +} from "react"; import { logger } from "matrix-js-sdk/src/logger"; import { SFUConfig, getSFUConfigWithOpenID } from "./openIDSFU"; import { ErrorView, LoadingView } from "../FullScreenView"; -import { ActiveCall, InCallViewProps } from "../room/InCallView"; -import { UserChoices } from "./useLiveKit"; -interface Props extends Omit { +interface Props { client: MatrixClient; roomName: string; - userChoices: UserChoices; + children: ReactNode; } -export function OpenIDLoader({ client, roomName, ...rest }: Props) { +const SFUConfigContext = createContext(undefined); + +export const useSFUConfig = () => useContext(SFUConfigContext); + +export function OpenIDLoader({ client, roomName, children }: Props) { const [sfuConfig, setSFUConfig] = useState(); const [error, setError] = useState(); @@ -48,7 +56,11 @@ export function OpenIDLoader({ client, roomName, ...rest }: Props) { if (error) { return ; } else if (sfuConfig) { - return ; + return ( + + {children} + + ); } else { return ; } diff --git a/src/room/GroupCallView.tsx b/src/room/GroupCallView.tsx index 2bbd210..888dcbf 100644 --- a/src/room/GroupCallView.tsx +++ b/src/room/GroupCallView.tsx @@ -35,6 +35,7 @@ import { useProfile } from "../profile/useProfile"; import { UserChoices } from "../livekit/useLiveKit"; import { findDeviceByName } from "../media-utils"; import { OpenIDLoader } from "../livekit/OpenIDLoader"; +import { ActiveCall } from "./InCallView"; declare global { interface Window { @@ -222,18 +223,19 @@ export function GroupCallView({ return ; } else if (state === GroupCallState.Entered && userChoices) { return ( - + + + ); } else if (left) { // The call ended view is shown for two reasons: prompting guests to create diff --git a/src/room/InCallView.tsx b/src/room/InCallView.tsx index 10d8818..79a7e73 100644 --- a/src/room/InCallView.tsx +++ b/src/room/InCallView.tsx @@ -81,9 +81,9 @@ import { RageshakeRequestModal } from "./RageshakeRequestModal"; import { VideoTile } from "../video-grid/VideoTile"; import { UserChoices, useLiveKit } from "../livekit/useLiveKit"; import { useMediaDevices } from "../livekit/useMediaDevices"; -import { SFUConfig } from "../livekit/openIDSFU"; import { useFullscreen } from "./useFullscreen"; import { useLayoutStates } from "../video-grid/Layout"; +import { useSFUConfig } from "../livekit/OpenIDLoader"; const canScreenshare = "getDisplayMedia" in (navigator.mediaDevices ?? {}); // There is currently a bug in Safari our our code with cloning and sending MediaStreams @@ -93,11 +93,11 @@ const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); export interface ActiveCallProps extends Omit { userChoices: UserChoices; - sfuConfig: SFUConfig; } export function ActiveCall(props: ActiveCallProps) { - const livekitRoom = useLiveKit(props.userChoices, props.sfuConfig); + const sfuConfig = useSFUConfig(); + const livekitRoom = useLiveKit(props.userChoices, sfuConfig); return ( livekitRoom && (