1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-11-02 14:23:10 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
sunnylqm
2024-07-27 21:59:25 +08:00
parent 7229f8847a
commit a564770597
5 changed files with 74 additions and 36 deletions

View File

@@ -1,3 +1,5 @@
import { Platform } from "react-native";
export function logger(...args: any[]) {
console.log('Pushy: ', ...args);
}
@@ -7,3 +9,24 @@ export function assertRelease() {
throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
}
}
const ping =
Platform.OS === 'web'
? Promise.resolve
: async (url: string) =>
Promise.race([
fetch(url, {
method: 'HEAD',
})
.then(({ status }) => (status === 200 ? url : null))
.catch(() => null),
new Promise(r => setTimeout(() => r(null), 2000)),
]);
export const testUrls = async (urls?: string[]) => {
if (!urls?.length) {
return null;
}
return Promise.race(urls.map(ping)).catch(() => null);
};