Provide sfu config via context
This commit is contained in:
parent
4efd88905d
commit
23b8a61e7a
3 changed files with 36 additions and 22 deletions
|
@ -15,21 +15,29 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { MatrixClient } from "matrix-js-sdk";
|
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 { logger } from "matrix-js-sdk/src/logger";
|
||||||
|
|
||||||
import { SFUConfig, getSFUConfigWithOpenID } from "./openIDSFU";
|
import { SFUConfig, getSFUConfigWithOpenID } from "./openIDSFU";
|
||||||
import { ErrorView, LoadingView } from "../FullScreenView";
|
import { ErrorView, LoadingView } from "../FullScreenView";
|
||||||
import { ActiveCall, InCallViewProps } from "../room/InCallView";
|
|
||||||
import { UserChoices } from "./useLiveKit";
|
|
||||||
|
|
||||||
interface Props extends Omit<InCallViewProps, "livekitRoom"> {
|
interface Props {
|
||||||
client: MatrixClient;
|
client: MatrixClient;
|
||||||
roomName: string;
|
roomName: string;
|
||||||
userChoices: UserChoices;
|
children: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function OpenIDLoader({ client, roomName, ...rest }: Props) {
|
const SFUConfigContext = createContext<SFUConfig>(undefined);
|
||||||
|
|
||||||
|
export const useSFUConfig = () => useContext(SFUConfigContext);
|
||||||
|
|
||||||
|
export function OpenIDLoader({ client, roomName, children }: Props) {
|
||||||
const [sfuConfig, setSFUConfig] = useState<SFUConfig>();
|
const [sfuConfig, setSFUConfig] = useState<SFUConfig>();
|
||||||
const [error, setError] = useState<Error>();
|
const [error, setError] = useState<Error>();
|
||||||
|
|
||||||
|
@ -48,7 +56,11 @@ export function OpenIDLoader({ client, roomName, ...rest }: Props) {
|
||||||
if (error) {
|
if (error) {
|
||||||
return <ErrorView error={error} />;
|
return <ErrorView error={error} />;
|
||||||
} else if (sfuConfig) {
|
} else if (sfuConfig) {
|
||||||
return <ActiveCall client={client} sfuConfig={sfuConfig} {...rest} />;
|
return (
|
||||||
|
<SFUConfigContext.Provider value={sfuConfig}>
|
||||||
|
{children}
|
||||||
|
</SFUConfigContext.Provider>
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return <LoadingView />;
|
return <LoadingView />;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import { useProfile } from "../profile/useProfile";
|
||||||
import { UserChoices } from "../livekit/useLiveKit";
|
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";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
@ -222,18 +223,19 @@ export function GroupCallView({
|
||||||
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} roomName={matrixInfo.roomName}>
|
||||||
client={client}
|
<ActiveCall
|
||||||
roomName={matrixInfo.roomName}
|
client={client}
|
||||||
groupCall={groupCall}
|
groupCall={groupCall}
|
||||||
participants={participants}
|
participants={participants}
|
||||||
onLeave={onLeave}
|
onLeave={onLeave}
|
||||||
unencryptedEventsFromUsers={unencryptedEventsFromUsers}
|
unencryptedEventsFromUsers={unencryptedEventsFromUsers}
|
||||||
hideHeader={hideHeader}
|
hideHeader={hideHeader}
|
||||||
matrixInfo={matrixInfo}
|
matrixInfo={matrixInfo}
|
||||||
userChoices={userChoices}
|
userChoices={userChoices}
|
||||||
otelGroupCallMembership={otelGroupCallMembership}
|
otelGroupCallMembership={otelGroupCallMembership}
|
||||||
/>
|
/>
|
||||||
|
</OpenIDLoader>
|
||||||
);
|
);
|
||||||
} else if (left) {
|
} else if (left) {
|
||||||
// The call ended view is shown for two reasons: prompting guests to create
|
// The call ended view is shown for two reasons: prompting guests to create
|
||||||
|
|
|
@ -81,9 +81,9 @@ import { RageshakeRequestModal } from "./RageshakeRequestModal";
|
||||||
import { VideoTile } from "../video-grid/VideoTile";
|
import { VideoTile } from "../video-grid/VideoTile";
|
||||||
import { UserChoices, useLiveKit } from "../livekit/useLiveKit";
|
import { UserChoices, useLiveKit } from "../livekit/useLiveKit";
|
||||||
import { useMediaDevices } from "../livekit/useMediaDevices";
|
import { useMediaDevices } from "../livekit/useMediaDevices";
|
||||||
import { SFUConfig } from "../livekit/openIDSFU";
|
|
||||||
import { useFullscreen } from "./useFullscreen";
|
import { useFullscreen } from "./useFullscreen";
|
||||||
import { useLayoutStates } from "../video-grid/Layout";
|
import { useLayoutStates } from "../video-grid/Layout";
|
||||||
|
import { useSFUConfig } from "../livekit/OpenIDLoader";
|
||||||
|
|
||||||
const canScreenshare = "getDisplayMedia" in (navigator.mediaDevices ?? {});
|
const canScreenshare = "getDisplayMedia" in (navigator.mediaDevices ?? {});
|
||||||
// There is currently a bug in Safari our our code with cloning and sending MediaStreams
|
// 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<InCallViewProps, "livekitRoom"> {
|
export interface ActiveCallProps extends Omit<InCallViewProps, "livekitRoom"> {
|
||||||
userChoices: UserChoices;
|
userChoices: UserChoices;
|
||||||
sfuConfig: SFUConfig;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ActiveCall(props: ActiveCallProps) {
|
export function ActiveCall(props: ActiveCallProps) {
|
||||||
const livekitRoom = useLiveKit(props.userChoices, props.sfuConfig);
|
const sfuConfig = useSFUConfig();
|
||||||
|
const livekitRoom = useLiveKit(props.userChoices, sfuConfig);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
livekitRoom && (
|
livekitRoom && (
|
||||||
|
|
Loading…
Reference in a new issue