2024-03-07 01:28:18 +08:00
|
|
|
import React, { useContext, useEffect } from 'react';
|
|
|
|
import { useQuery } from '@apollo/client';
|
|
|
|
import { getBigBlueButtonSettings, getBigBlueButtonSettingsResponse } from './queries';
|
|
|
|
import { setMeetingSettings } from '../../core/local-states/useMeetingSettings';
|
|
|
|
import MeetingClientSettings from '../../Types/meetingClientSettings';
|
|
|
|
import ClientStartup from '/client/clientStartup';
|
|
|
|
import { LoadingContext } from '../common/loading-screen/loading-screen-HOC/component';
|
|
|
|
import CustomUsersSettings from '../join-handler/custom-users-settings/component';
|
2024-03-22 03:41:32 +08:00
|
|
|
import logger from '/imports/startup/client/logger';
|
2024-03-07 01:28:18 +08:00
|
|
|
|
|
|
|
declare global {
|
|
|
|
interface Window {
|
|
|
|
meetingClientSettings: MeetingClientSettings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const SettingsLoader: React.FC = () => {
|
|
|
|
const { loading, error, data } = useQuery<getBigBlueButtonSettingsResponse>(getBigBlueButtonSettings);
|
|
|
|
const [allowToRender, setAllowToRender] = React.useState(false);
|
|
|
|
const loadingContextInfo = useContext(LoadingContext);
|
|
|
|
useEffect(() => {
|
2024-03-22 03:41:32 +08:00
|
|
|
logger.info('Fetching settings');
|
|
|
|
loadingContextInfo.setLoading(true, '3/4');
|
2024-03-07 01:28:18 +08:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!loading && !error) {
|
|
|
|
const settings = data?.meeting[0].clientSettings.clientSettingsJson;
|
|
|
|
if (settings && Object.keys(settings).length > 0) {
|
|
|
|
window.meetingClientSettings = JSON.parse(JSON.stringify(settings as unknown as MeetingClientSettings));
|
2024-03-22 03:41:32 +08:00
|
|
|
const Meteor = { settings: {} };
|
|
|
|
Meteor.settings = window.meetingClientSettings;
|
2024-03-07 01:28:18 +08:00
|
|
|
setMeetingSettings(settings as unknown as MeetingClientSettings);
|
|
|
|
setAllowToRender(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [loading]);
|
|
|
|
if (loading) return null;
|
|
|
|
if (error) {
|
|
|
|
loadingContextInfo.setLoading(false, '');
|
|
|
|
throw new Error('Error on requesting meeting settings data: ', error);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
(allowToRender)
|
|
|
|
? (
|
|
|
|
<CustomUsersSettings>
|
|
|
|
<ClientStartup />
|
|
|
|
</CustomUsersSettings>
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SettingsLoader;
|