2024-03-07 01:28:18 +08:00
|
|
|
import React, { useContext, useEffect } from 'react';
|
|
|
|
import { setMeetingSettings } from '../../core/local-states/useMeetingSettings';
|
|
|
|
import MeetingClientSettings from '../../Types/meetingClientSettings';
|
2024-05-29 21:26:11 +08:00
|
|
|
import MeetingClient from '/client/meetingClient';
|
2024-03-07 01:28:18 +08:00
|
|
|
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
|
|
|
|
2024-05-03 21:27:26 +08:00
|
|
|
interface Response {
|
|
|
|
meeting_clientSettings: Array<{
|
|
|
|
clientSettingsJson: MeetingClientSettings,
|
|
|
|
}>
|
|
|
|
}
|
|
|
|
|
2024-03-07 01:28:18 +08:00
|
|
|
declare global {
|
|
|
|
interface Window {
|
|
|
|
meetingClientSettings: MeetingClientSettings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const SettingsLoader: React.FC = () => {
|
|
|
|
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(() => {
|
2024-05-03 21:27:26 +08:00
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const sessionToken = urlParams.get('sessionToken');
|
|
|
|
const clientStartupSettings = `/api/rest/clientSettings/?sessionToken=${sessionToken}`;
|
|
|
|
const url = new URL(`${window.location.origin}${clientStartupSettings}`);
|
|
|
|
fetch(url, { method: 'get' })
|
|
|
|
.then((resp) => resp.json())
|
|
|
|
.then((data: Response) => {
|
|
|
|
const settings = data?.meeting_clientSettings[0].clientSettingsJson;
|
|
|
|
|
2024-03-07 01:28:18 +08:00
|
|
|
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);
|
2024-05-03 21:27:26 +08:00
|
|
|
}).catch(() => {
|
|
|
|
loadingContextInfo.setLoading(false, '');
|
|
|
|
throw new Error('Error on requesting client settings data.');
|
|
|
|
});
|
|
|
|
// }
|
|
|
|
}, []);
|
2024-03-07 01:28:18 +08:00
|
|
|
return (
|
|
|
|
(allowToRender)
|
|
|
|
? (
|
|
|
|
<CustomUsersSettings>
|
2024-05-29 21:26:11 +08:00
|
|
|
<MeetingClient />
|
2024-03-07 01:28:18 +08:00
|
|
|
</CustomUsersSettings>
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SettingsLoader;
|