bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/components-data/graphqlToMiniMongoAdapterManager/component.tsx

54 lines
1.4 KiB
TypeScript
Raw Normal View History

import React, {
useCallback,
useMemo,
useRef,
useState,
} from 'react';
2024-06-17 19:54:03 +08:00
import VideoStreamAdapter from '/imports/ui/components/video-provider/adapter';
interface GraphqlToMiniMongoAdapterManagerProps {
children: React.ReactNode;
}
export interface AdapterProps extends GraphqlToMiniMongoAdapterManagerProps {
onReady: (key:string) => void;
}
const GraphqlToMiniMongoAdapterManager: React.FC<GraphqlToMiniMongoAdapterManagerProps> = ({ children }) => {
const [adapterLoaded, setAdapterLoaded] = useState(false);
const loadedComponents = useRef<{
[key: string]: number;
}>({});
const adapterComponents = useRef([
2024-06-14 23:21:46 +08:00
// UserGrapQlMiniMongoAdapter,
// MeetingGrapQlMiniMongoAdapter,
VideoStreamAdapter,
]);
const onReady = useCallback((key: string) => {
loadedComponents.current[key] = 1;
if (Object.keys(loadedComponents.current).length >= adapterComponents.current.length) {
setAdapterLoaded(true);
}
}, []);
const nestAdapters = useMemo(() => {
return adapterComponents.current.reduce((acc, Component) => (
<Component onReady={onReady}>
{acc}
</Component>
), <span />);
}, []);
return (
<>
{/* screenshare loads conditionally so can't be used on lock loading */}
2024-06-14 23:21:46 +08:00
{/* <ScreenShareGraphQlMiniMongoAdapterContainer /> */}
{nestAdapters}
{adapterLoaded ? children : null}
</>
);
};
export default GraphqlToMiniMongoAdapterManager;