mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-10-29 20:43:09 +08:00
v10.6.0-beta.0
This commit is contained in:
12
src/utils.ts
12
src/utils.ts
@@ -18,13 +18,15 @@ export const emptyModule = new EmptyModule();
|
||||
|
||||
const ping =
|
||||
Platform.OS === 'web'
|
||||
? () => Promise.resolve(true)
|
||||
? Promise.resolve
|
||||
: async (url: string) =>
|
||||
Promise.race([
|
||||
fetch(url, {
|
||||
method: 'HEAD',
|
||||
}).then(({ status }) => status === 200),
|
||||
new Promise<false>(r => setTimeout(() => r(false), 2000)),
|
||||
})
|
||||
.then(({ status }) => (status === 200 ? url : null))
|
||||
.catch(() => null),
|
||||
new Promise(r => setTimeout(() => r(null), 2000)),
|
||||
]);
|
||||
|
||||
const canUseGoogle = ping('https://www.google.com');
|
||||
@@ -33,7 +35,5 @@ export const testUrls = async (urls?: string[]) => {
|
||||
if (!urls?.length || (await canUseGoogle)) {
|
||||
return null;
|
||||
}
|
||||
return Promise.race(urls.map(url => ping(url).then(() => url))).catch(
|
||||
() => null,
|
||||
);
|
||||
return Promise.race(urls.map(ping)).catch(() => null);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user