verdnatura-chat/app/lib/services/getServerTimeSync.ts

17 lines
374 B
TypeScript
Raw Normal View History

2022-02-28 18:00:47 +00:00
import RNFetchBlob from 'rn-fetch-blob';
export const getServerTimeSync = async (server: string) => {
try {
const response = await Promise.race([
RNFetchBlob.fetch('GET', `${server}/_timesync`),
new Promise<undefined>(res => setTimeout(res, 2000))
]);
if (response?.data) {
return parseInt(response.data);
}
return null;
} catch {
return null;
}
};