UNPKG

mychips-react-sdk

Version:
31 lines (29 loc) 1.26 kB
// src/services/ConnectivityService.ts // defines the ConnectivityProvider interface and a default (optional) NetInfo-based provider. /** * Default implementation that uses @react-native-community/netinfo * ONLY if it is installed in the host app. We load it dynamically to avoid hard dependency. */ export function getDefaultNetInfoProvider() { try { const mod = require('@react-native-community/netinfo'); const NetInfo = (mod === null || mod === void 0 ? void 0 : mod.default) ?? mod; // support both default and named export return { subscribe(handler) { const unsub = NetInfo.addEventListener(state => { handler(Boolean(state === null || state === void 0 ? void 0 : state.isConnected)); }); return typeof unsub === 'function' ? unsub : () => { var _unsub$remove; return unsub === null || unsub === void 0 || (_unsub$remove = unsub.remove) === null || _unsub$remove === void 0 ? void 0 : _unsub$remove.call(unsub); }; }, getCurrentStatus() { return NetInfo.fetch().then(state => Boolean(state === null || state === void 0 ? void 0 : state.isConnected)); } }; } catch { return null; } } //# sourceMappingURL=ConnectivityService.js.map