@aws-amplify/core
Version:
Core category of aws-amplify
1 lines • 2.6 kB
Source Map (JSON)
{"version":3,"file":"Reachability.native.mjs","sources":["../../../src/Reachability/Reachability.native.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Observable } from 'rxjs';\nimport { ConsoleLogger } from '../Logger';\nconst logger = new ConsoleLogger('Reachability', 'DEBUG');\nexport class Reachability {\n networkMonitor(netInfo) {\n /**\n * Here netinfo refers to @react-native-community/netinfo\n * This is needed in React Native to enable network detection\n * We do not import it in Core so that Apps that do not use DataStore\n * Do not need to install and link this dependency\n * When using Reachability in React Native, pass NetInfo as a param to networkMonitor\n */\n if (!(netInfo && netInfo.addEventListener)) {\n throw new Error('NetInfo must be passed to networkMonitor to enable reachability in React Native');\n }\n return new Observable(observer => {\n logger.log('subscribing to reachability in React Native');\n const unsubscribe = netInfo.addEventListener(({ isInternetReachable }) => {\n // `isInternetReachable` can sometimes be `null` initially, so we want\n // to make sure it is a boolean first before sending it to the observer.\n if (typeof isInternetReachable === 'boolean') {\n const online = isInternetReachable;\n logger.log('Notifying reachability change', online);\n observer.next({ online });\n }\n });\n return () => {\n unsubscribe();\n };\n });\n }\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;AACnD,MAAM,YAAY,CAAC;AAC1B,IAAI,cAAc,CAAC,OAAO,EAAE;AAC5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,IAAI,EAAE,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC,EAAE;AACpD,YAAY,MAAM,IAAI,KAAK,CAAC,iFAAiF,CAAC,CAAC;AAC/G,SAAS;AACT,QAAQ,OAAO,IAAI,UAAU,CAAC,QAAQ,IAAI;AAC1C,YAAY,MAAM,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;AACtE,YAAY,MAAM,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,mBAAmB,EAAE,KAAK;AACtF;AACA;AACA,gBAAgB,IAAI,OAAO,mBAAmB,KAAK,SAAS,EAAE;AAC9D,oBAAoB,MAAM,MAAM,GAAG,mBAAmB,CAAC;AACvD,oBAAoB,MAAM,CAAC,GAAG,CAAC,+BAA+B,EAAE,MAAM,CAAC,CAAC;AACxE,oBAAoB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAC9C,iBAAiB;AACjB,aAAa,CAAC,CAAC;AACf,YAAY,OAAO,MAAM;AACzB,gBAAgB,WAAW,EAAE,CAAC;AAC9B,aAAa,CAAC;AACd,SAAS,CAAC,CAAC;AACX,KAAK;AACL;;;;"}