bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/app/app-graphql/time-sync/component.tsx

41 lines
884 B
TypeScript
Raw Normal View History

import { useLazyQuery } from '@apollo/client';
import React, { useEffect } from 'react';
import { GET_SERVER_TIME, GetServerTimeResponse } from './queries';
import { setTimeSync } from '/imports/ui/core/local-states/useTimeSync';
const TimeSync: React.FC = () => {
const [
loadGetServerTime,
2023-09-11 21:12:37 +08:00
{
called,
loading,
data,
error,
},
] = useLazyQuery<GetServerTimeResponse>(GET_SERVER_TIME);
useEffect(() => {
if (!called) {
loadGetServerTime();
}
}, []);
2023-09-11 21:12:37 +08:00
if (error) {
return (
<div>
{JSON.stringify(error)}
</div>
);
}
useEffect(() => {
if (!loading && data) {
2023-09-14 21:44:04 +08:00
const time = new Date(data.current_time[0].currentTimestamp);
2024-04-23 12:00:54 +08:00
const dateNow = new Date();
setTimeSync(time.getTime() - dateNow.getTime());
}
}, [data, loading]);
return null;
};
2023-08-23 03:39:16 +08:00
export default TimeSync;