// Metro module 1461 (f1462). import _createClass from "./_createClass"; import _classCallCheck from "./_classCallCheck"; const InternetReachability = function InternetReachability(a0, a1) { _classCallCheck(this, InternetReachability); this._isInternetReachable = void 0; this._currentInternetReachabilityCheckHandler = null; this._currentTimeoutHandle = null; this._setIsInternetReachable = (a0) => { if (this._isInternetReachable !== a0) { this._isInternetReachable = a0; this._listener(this._isInternetReachable); } }; this._setExpectsConnection = (a0) => { if (this._currentInternetReachabilityCheckHandler !== null) { this._currentInternetReachabilityCheckHandler.cancel(); this._currentInternetReachabilityCheckHandler = null; } if (this._currentTimeoutHandle !== null) { clearTimeout(this._currentTimeoutHandle); this._currentTimeoutHandle = null; } if (a0 && this._configuration.reachabilityShouldRun()) { if (!this._isInternetReachable) { this._setIsInternetReachable(null); } this._currentInternetReachabilityCheckHandler = this._checkInternetReachability(); } else { this._setIsInternetReachable(false); } }; this._checkInternetReachability = () => { let c24412_0, cancel2; const abortController = new AbortController(); let c24412_1 = abortController; const r6 = fetch; const r11 = r6(this._configuration.reachabilityUrl, { headers: this._configuration.reachabilityHeaders, method: this._configuration.reachabilityMethod, cache: "no-cache", signal: abortController.signal }); const promise = new Promise((resolve, c28886_0) => { c24412_0 = setTimeout(() => c28886_0("timedout"), this._configuration.reachabilityRequestTimeout); }); cancel2 = () => {}; return { promise: Promise.race([r11, promise, new Promise((resolve, c28887_0) => { cancel2 = () => c28887_0("canceled"); })]).then((result) => this._configuration.reachabilityTest(result)).then((result) => { this._setIsInternetReachable(result); const _isInternetReachable = this._isInternetReachable; const _configuration = this._configuration; this._currentTimeoutHandle = setTimeout(this._checkInternetReachability, _isInternetReachable ? _configuration.reachabilityLongTimeout : _configuration.reachabilityShortTimeout); }).catch((error) => { if (error === "canceled") { c24412_1.abort(); } else { if (error === "timedout") { c24412_1.abort(); } this._setIsInternetReachable(false); this._currentTimeoutHandle = setTimeout(this._checkInternetReachability, this._configuration.reachabilityShortTimeout); } }).then(() => { clearTimeout(c24412_0); }, (a0) => { clearTimeout(c24412_0); throw a0; }), cancel: cancel2 }; }; this.update = (a0) => { if (typeof a0.isInternetReachable === "boolean") { if (this._configuration.useNativeReachability) { this._setIsInternetReachable(a0.isInternetReachable); } else { this._setExpectsConnection(a0.isConnected); } } else { this._setExpectsConnection(a0.isConnected); } }; this.currentState = () => this._isInternetReachable; this.tearDown = () => { if (this._currentInternetReachabilityCheckHandler !== null) { this._currentInternetReachabilityCheckHandler.cancel(); this._currentInternetReachabilityCheckHandler = null; } if (this._currentTimeoutHandle !== null) { clearTimeout(this._currentTimeoutHandle); this._currentTimeoutHandle = null; } }; this._configuration = a0; this._listener = a1; }; export default _createClass(InternetReachability);