2024-07-16 21:40:13 +08:00
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
import { setMeetingSettings } from '/imports/ui/core/local-states/useMeetingSettings';
|
|
|
|
import MeetingClientSettings from '/imports/ui/Types/meetingClientSettings';
|
|
|
|
import { ErrorScreen } from '/imports/ui/components/error-screen/component';
|
|
|
|
import LoadingScreen from '/imports/ui/components/common/loading-screen/component';
|
|
|
|
import Session from '/imports/ui/services/storage/in-memory';
|
2024-07-19 22:27:48 +08:00
|
|
|
import BBBWeb from '/imports/api/bbb-web-api';
|
2024-07-16 21:40:13 +08:00
|
|
|
|
|
|
|
const connectionTimeout = 60000;
|
2024-03-07 01:28:18 +08:00
|
|
|
|
2024-05-03 21:27:26 +08:00
|
|
|
interface Response {
|
|
|
|
meeting_clientSettings: Array<{
|
|
|
|
clientSettingsJson: MeetingClientSettings,
|
2024-07-16 21:40:13 +08:00
|
|
|
}>;
|
2024-05-03 21:27:26 +08:00
|
|
|
}
|
|
|
|
|
2024-03-07 01:28:18 +08:00
|
|
|
declare global {
|
|
|
|
interface Window {
|
|
|
|
meetingClientSettings: MeetingClientSettings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-16 21:40:13 +08:00
|
|
|
interface SettingsLoaderProps {
|
|
|
|
children: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SettingsLoader: React.FC<SettingsLoaderProps> = (props) => {
|
|
|
|
const { children } = props;
|
|
|
|
const [settingsFetched, setSettingsFetched] = React.useState(false);
|
|
|
|
const [error, setError] = React.useState<string | null>(null);
|
|
|
|
const [loading, setLoading] = React.useState<boolean>(false);
|
|
|
|
const timeoutRef = React.useRef<ReturnType<typeof setTimeout>>();
|
2024-03-07 01:28:18 +08:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-07-16 21:40:13 +08:00
|
|
|
setLoading(true);
|
|
|
|
|
|
|
|
const controller = new AbortController();
|
|
|
|
timeoutRef.current = setTimeout(() => {
|
|
|
|
controller.abort();
|
|
|
|
setError('Timeout fetching client settings');
|
|
|
|
setLoading(false);
|
|
|
|
}, connectionTimeout);
|
|
|
|
|
|
|
|
const clientSessionUUID = uuid();
|
|
|
|
sessionStorage.setItem('clientSessionUUID', clientSessionUUID);
|
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const sessionToken = urlParams.get('sessionToken');
|
|
|
|
|
|
|
|
if (!sessionToken) {
|
|
|
|
setLoading(false);
|
|
|
|
setError('Missing session token');
|
|
|
|
return;
|
2024-06-18 02:26:13 +08:00
|
|
|
}
|
2024-07-16 21:40:13 +08:00
|
|
|
|
2024-07-19 22:27:48 +08:00
|
|
|
BBBWeb.index(controller.signal)
|
|
|
|
.then(({ data }) => {
|
|
|
|
const url = new URL(`${data.graphqlApiUrl}/clientSettings`);
|
2024-07-11 05:30:01 +08:00
|
|
|
fetch(url, {
|
|
|
|
method: 'get',
|
|
|
|
credentials: 'include',
|
|
|
|
headers: {
|
2024-07-13 03:44:40 +08:00
|
|
|
'x-session-token': sessionToken ?? '',
|
2024-07-11 05:30:01 +08:00
|
|
|
},
|
2024-07-16 21:40:13 +08:00
|
|
|
signal: controller.signal,
|
2024-07-11 05:30:01 +08:00
|
|
|
})
|
2024-06-18 02:26:13 +08:00
|
|
|
.then((resp) => resp.json())
|
|
|
|
.then((data: Response) => {
|
2024-07-16 21:40:13 +08:00
|
|
|
clearTimeout(timeoutRef.current);
|
2024-06-18 02:26:13 +08:00
|
|
|
const settings = data?.meeting_clientSettings[0].clientSettingsJson;
|
2024-07-16 21:40:13 +08:00
|
|
|
window.meetingClientSettings = JSON.parse(JSON.stringify(settings));
|
|
|
|
setMeetingSettings(settings);
|
|
|
|
setLoading(false);
|
|
|
|
setSettingsFetched(true);
|
2024-06-18 02:26:13 +08:00
|
|
|
}).catch(() => {
|
2024-07-16 21:40:13 +08:00
|
|
|
setLoading(false);
|
|
|
|
setError('Error fetching client settings');
|
|
|
|
Session.setItem('errorMessageDescription', 'meeting_ended');
|
2024-06-18 02:26:13 +08:00
|
|
|
});
|
|
|
|
}).catch((error) => {
|
2024-07-16 21:40:13 +08:00
|
|
|
setLoading(false);
|
|
|
|
setError('Error fetching GraphQL URL: '.concat(error.message || ''));
|
2024-05-03 21:27:26 +08:00
|
|
|
});
|
|
|
|
}, []);
|
2024-07-16 21:40:13 +08:00
|
|
|
|
2024-03-07 01:28:18 +08:00
|
|
|
return (
|
2024-07-16 21:40:13 +08:00
|
|
|
<>
|
|
|
|
{settingsFetched ? children : null}
|
|
|
|
{error ? (
|
|
|
|
<ErrorScreen
|
|
|
|
endedReason={error}
|
|
|
|
code={403}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
{loading ? (
|
|
|
|
<LoadingScreen>
|
|
|
|
<div style={{ display: 'none' }}>
|
|
|
|
Loading...
|
|
|
|
</div>
|
|
|
|
</LoadingScreen>
|
|
|
|
) : null}
|
|
|
|
</>
|
2024-03-07 01:28:18 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SettingsLoader;
|