1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-10-29 20:43:09 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

v10.6.0-beta.0

This commit is contained in:
sunnylqm
2024-06-11 10:44:18 +08:00
parent 6244bb9af2
commit e63fa0fdb6
7 changed files with 48 additions and 23 deletions

View File

@@ -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);
};