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');
|
2024-06-06 04:41:23 +08:00
|
|
|
loadingContextInfo.setLoading(true, '4/5');
|
2024-03-07 01:28:18 +08:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-06-18 02:26:13 +08:00
|
|
|
const pathMatch = window.location.pathname.match('^(.*)/html5client/join$');
|
|
|
|
if (pathMatch == null) {
|
|
|
|
throw new Error('Failed to match BBB client URI');
|
|
|
|
}
|
|
|
|
const serverPathPrefix = pathMatch[1];
|
|
|
|
fetch(`https://${window.location.hostname}${serverPathPrefix}/bigbluebutton/api`, {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
},
|
|
|
|
}).then((resp) => resp.json())
|
|
|
|
.then((data) => {
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const sessionToken = urlParams.get('sessionToken');
|
|
|
|
const clientStartupSettings = `/clientSettings/?sessionToken=${sessionToken}`;
|
|
|
|
const url = new URL(`${data.response.graphqlApiUrl}${clientStartupSettings}`);
|
|
|
|
fetch(url, { method: 'get', credentials: 'include' })
|
|
|
|
.then((resp) => resp.json())
|
|
|
|
.then((data: Response) => {
|
|
|
|
const settings = data?.meeting_clientSettings[0].clientSettingsJson;
|
2024-05-03 21:27:26 +08:00
|
|
|
|
2024-06-18 02:26:13 +08:00
|
|
|
window.meetingClientSettings = JSON.parse(JSON.stringify(settings as unknown as MeetingClientSettings));
|
|
|
|
const Meteor = { settings: {} };
|
|
|
|
Meteor.settings = window.meetingClientSettings;
|
|
|
|
setMeetingSettings(settings as unknown as MeetingClientSettings);
|
|
|
|
setAllowToRender(true);
|
|
|
|
}).catch(() => {
|
|
|
|
loadingContextInfo.setLoading(false, '');
|
|
|
|
throw new Error('Error on requesting client settings data.');
|
|
|
|
});
|
|
|
|
}).catch((error) => {
|
2024-05-03 21:27:26 +08:00
|
|
|
loadingContextInfo.setLoading(false, '');
|
2024-06-18 02:26:13 +08:00
|
|
|
throw new Error('Error fetching GraphQL API URL: '.concat(error.message || ''));
|
2024-05-03 21:27:26 +08:00
|
|
|
});
|
|
|
|
}, []);
|
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;
|