mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-10-29 20:43:09 +08:00
v10.5.2
This commit is contained in:
18
src/utils.ts
18
src/utils.ts
@@ -1,14 +1,18 @@
|
||||
import { Platform } from 'react-native';
|
||||
export function log(...args: any[]) {
|
||||
console.log('pushy: ', ...args);
|
||||
}
|
||||
|
||||
const ping = async (url: string) =>
|
||||
Promise.race([
|
||||
fetch(url, {
|
||||
method: 'HEAD',
|
||||
}).then(({ status }) => status === 200),
|
||||
new Promise<false>(r => setTimeout(() => r(false), 2000)),
|
||||
]);
|
||||
const ping =
|
||||
Platform.OS === 'web'
|
||||
? () => Promise.resolve(true)
|
||||
: async (url: string) =>
|
||||
Promise.race([
|
||||
fetch(url, {
|
||||
method: 'HEAD',
|
||||
}).then(({ status }) => status === 200),
|
||||
new Promise<false>(r => setTimeout(() => r(false), 2000)),
|
||||
]);
|
||||
|
||||
const canUseGoogle = ping('https://www.google.com');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user