2024-03-07 01:28:18 +08:00
|
|
|
import React, { useEffect } from 'react';
|
2024-03-14 21:20:45 +08:00
|
|
|
import { Session } from 'meteor/session';
|
2024-03-07 01:28:18 +08:00
|
|
|
import { ErrorScreen } from '../../error-screen/component';
|
|
|
|
import LoadingScreen from '../../common/loading-screen/component';
|
|
|
|
|
|
|
|
const connectionTimeout = 60000;
|
|
|
|
|
|
|
|
interface Response {
|
|
|
|
meeting_clientSettings: Array<{
|
|
|
|
askForFeedbackOnLogout: boolean,
|
|
|
|
allowDefaultLogoutUrl: boolean,
|
|
|
|
learningDashboardBase: string,
|
|
|
|
fallbackLocale: string,
|
|
|
|
fallbackOnEmptyString: boolean,
|
2024-05-01 23:15:11 +08:00
|
|
|
mediaTag: string,
|
2024-03-07 01:28:18 +08:00
|
|
|
clientLog: {
|
|
|
|
server: {
|
|
|
|
level: string,
|
|
|
|
enabled: boolean
|
|
|
|
},
|
|
|
|
console: {
|
|
|
|
level: string,
|
|
|
|
enabled: true
|
|
|
|
},
|
|
|
|
external: {
|
|
|
|
url: string,
|
|
|
|
level: string,
|
|
|
|
logTag: string,
|
|
|
|
method: string,
|
|
|
|
enabled: boolean,
|
|
|
|
flushOnClose: boolean,
|
|
|
|
throttleInterval: number,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}>
|
|
|
|
}
|
|
|
|
|
|
|
|
interface StartupDataFetchProps {
|
|
|
|
children: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
const StartupDataFetch: React.FC<StartupDataFetchProps> = ({
|
|
|
|
children,
|
|
|
|
}) => {
|
|
|
|
const [settingsFetched, setSettingsFetched] = React.useState<boolean>(false);
|
|
|
|
const [error, setError] = React.useState<string>('');
|
|
|
|
const timeoutRef = React.useRef<ReturnType<typeof setTimeout>>();
|
|
|
|
const [loading, setLoading] = React.useState<boolean>(false);
|
|
|
|
useEffect(() => {
|
|
|
|
setLoading(true);
|
|
|
|
timeoutRef.current = setTimeout(() => {
|
|
|
|
setError('Timeout on fetching startup data');
|
|
|
|
setLoading(false);
|
|
|
|
}, connectionTimeout);
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
const sessionToken = urlParams.get('sessionToken');
|
|
|
|
|
|
|
|
if (!sessionToken) {
|
|
|
|
setError('Missing session token');
|
|
|
|
setLoading(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const clientStartupSettings = '/api/rest/clientStartupSettings/';
|
|
|
|
const url = new URL(`${window.location.origin}${clientStartupSettings}`);
|
|
|
|
const headers = new Headers({ 'X-Session-Token': sessionToken, 'Content-Type': 'application/json' });
|
|
|
|
fetch(url, { method: 'get', headers })
|
|
|
|
.then((resp) => resp.json())
|
|
|
|
.then((data: Response) => {
|
|
|
|
const settings = data.meeting_clientSettings[0];
|
2024-03-27 01:02:38 +08:00
|
|
|
sessionStorage.setItem('clientStartupSettings', JSON.stringify(settings || {}));
|
2024-03-07 01:28:18 +08:00
|
|
|
setSettingsFetched(true);
|
|
|
|
clearTimeout(timeoutRef.current);
|
|
|
|
setLoading(false);
|
2024-03-14 21:07:58 +08:00
|
|
|
}).catch(() => {
|
|
|
|
Session.set('errorMessageDescription', 'meeting_ended');
|
|
|
|
setError('Error fetching startup data');
|
|
|
|
setLoading(false);
|
2024-03-07 01:28:18 +08:00
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{settingsFetched ? children : null}
|
|
|
|
{error
|
|
|
|
? (
|
|
|
|
<ErrorScreen
|
|
|
|
endedReason={error}
|
2024-03-14 21:38:56 +08:00
|
|
|
code={403}
|
2024-03-07 01:28:18 +08:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
: null}
|
|
|
|
{loading
|
|
|
|
? (
|
|
|
|
<LoadingScreen>
|
|
|
|
<div style={{ display: 'none' }}>
|
|
|
|
Loading...
|
|
|
|
</div>
|
|
|
|
</LoadingScreen>
|
|
|
|
)
|
|
|
|
: null}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default StartupDataFetch;
|