mychips-react-sdk
Version:
MyChips Offerwall
37 lines (34 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getDefaultNetInfoProvider = getDefaultNetInfoProvider;
// 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.
*/
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