bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/app/app-graphql/time-sync/component.tsx
2023-09-13 13:37:40 -03:00

40 lines
852 B
TypeScript

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,
{
called,
loading,
data,
error,
},
] = useLazyQuery<GetServerTimeResponse>(GET_SERVER_TIME);
useEffect(() => {
if (!called) {
loadGetServerTime();
}
}, []);
if (error) {
return (
<div>
{JSON.stringify(error)}
</div>
);
}
useEffect(() => {
if (!loading && data) {
const time = new Date(data.currentTime[0].currentTimestamp);
setTimeSync(time.getTime() - new Date().getTime());
}
}, [data, loading]);
return null;
};
export default TimeSync;