shakebug-react-native 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DeviceInfo/index.js.flow +177 -0
- package/DeviceInfo/index.ts +1034 -0
- package/DeviceInfo/internal/asyncHookWrappers.ts +59 -0
- package/DeviceInfo/internal/devicesWithDynamicIsland.ts +30 -0
- package/DeviceInfo/internal/devicesWithNotch.ts +374 -0
- package/DeviceInfo/internal/nativeInterface.ts +28 -0
- package/DeviceInfo/internal/privateTypes.ts +231 -0
- package/DeviceInfo/internal/supported-platform-info.ts +97 -0
- package/DeviceInfo/internal/types.ts +19 -0
- package/DeviceInfo/web/index.js +223 -0
- package/GetLocals/src/NativeRNLocalize.ts +18 -0
- package/GetLocals/src/constants.ts +269 -0
- package/GetLocals/src/index.ts +56 -0
- package/GetLocals/src/module.ts +51 -0
- package/GetLocals/src/module.web.ts +148 -0
- package/GetLocals/src/types.ts +31 -0
- package/GetLocation/LocationError.ts +20 -0
- package/GetLocation/index.ts +46 -0
- package/GetLocation/utils.ts +89 -0
- package/ImageOrVedioPicker/src/index.ts +28 -0
- package/ImageOrVedioPicker/src/platforms/NativeImagePicker.ts +10 -0
- package/ImageOrVedioPicker/src/platforms/native.ts +61 -0
- package/ImageOrVedioPicker/src/platforms/web.ts +159 -0
- package/ImageOrVedioPicker/src/types.ts +74 -0
- package/NetInfo/src/__tests__/eventListenerCallbacks.spec.ts +332 -0
- package/NetInfo/src/__tests__/fetch.spec.ts +479 -0
- package/NetInfo/src/index.ts +186 -0
- package/NetInfo/src/internal/__mocks__/nativeModule.ts +13 -0
- package/NetInfo/src/internal/defaultConfiguration.ts +17 -0
- package/NetInfo/src/internal/defaultConfiguration.web.ts +17 -0
- package/NetInfo/src/internal/internetReachability.ts +180 -0
- package/NetInfo/src/internal/nativeInterface.ts +43 -0
- package/NetInfo/src/internal/nativeInterface.web.ts +27 -0
- package/NetInfo/src/internal/nativeModule.ts +15 -0
- package/NetInfo/src/internal/nativeModule.web.ts +306 -0
- package/NetInfo/src/internal/privateTypes.ts +41 -0
- package/NetInfo/src/internal/state.ts +137 -0
- package/NetInfo/src/internal/types.ts +128 -0
- package/README.md +246 -0
- package/RecordScreen/src/index.tsx +75 -0
- package/ScreenShot/src/RNViewShot.js +3 -0
- package/ScreenShot/src/RNViewShot.web.js +42 -0
- package/ScreenShot/src/index.js +308 -0
- package/Sensor/src/index.js +14 -0
- package/Sensor/src/rnsensors.js +57 -0
- package/Sensor/src/sensors.js +97 -0
- package/VideoPlayer/PlayVideo.tsx +51 -0
- package/VideoPlayer/index.js +69 -0
- package/android/README.md +14 -0
- package/android/build/generated/source/buildConfig/debug/com/shakebug/BuildConfig.java +10 -0
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml +42 -0
- package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output-metadata.json +18 -0
- package/android/build/intermediates/aar_metadata/debug/aar-metadata.properties +6 -0
- package/android/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +1 -0
- package/android/build/intermediates/compile_library_classes_jar/debug/classes.jar +0 -0
- package/android/build/intermediates/compile_r_class_jar/debug/R.jar +0 -0
- package/android/build/intermediates/compile_symbol_list/debug/R.txt +47 -0
- package/android/build/intermediates/compiled_local_resources/debug/out/xml_imagepicker_provider_paths.xml.flat +0 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +12 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +2 -0
- package/android/build/intermediates/incremental/mergeDebugShaders/merger.xml +2 -0
- package/android/build/intermediates/incremental/packageDebugAssets/merger.xml +2 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/BuildConfig.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/CustomMediaMetadataRetriever.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ImageMetadata.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ImagePickerProvider.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/Metadata.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/Options.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/RecordScreenModule$1.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/RecordScreenModule.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/Shakebug.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ShakebugPackage.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/Utility.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/Utils.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/VideoMetadata.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot$1.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot$2.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot$Formats.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot$Results.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot$ReusableByteArrayOutputStream.class +0 -0
- package/android/build/intermediates/javac/debug/classes/com/shakebug/ViewShot.class +0 -0
- package/android/build/intermediates/local_only_symbol_list/debug/R-def.txt +49 -0
- package/android/build/intermediates/manifest_merge_blame_file/debug/manifest-merger-blame-debug-report.txt +82 -0
- package/android/build/intermediates/merged_manifest/debug/AndroidManifest.xml +42 -0
- package/android/build/intermediates/navigation_json/debug/navigation.json +1 -0
- package/android/build/intermediates/packaged_res/debug/values/values.xml +25 -0
- package/android/build/intermediates/packaged_res/debug/xml/imagepicker_provider_paths.xml +4 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/BuildConfig.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/CustomMediaMetadataRetriever.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ImageMetadata.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ImagePickerProvider.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/Metadata.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/Options.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/RecordScreenModule$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/RecordScreenModule.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/Shakebug.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ShakebugPackage.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/Utility.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/Utils.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/VideoMetadata.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot$1.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot$2.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot$Formats.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot$Results.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot$ReusableByteArrayOutputStream.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/com/shakebug/ViewShot.class +0 -0
- package/android/build/intermediates/symbol_list_with_package_name/debug/package-aware-r.txt +48 -0
- package/android/build/outputs/logs/manifest-merger-debug-report.txt +97 -0
- package/android/build/tmp/compileDebugJavaWithJavac/previous-compilation-data.bin +0 -0
- package/android/build.gradle +235 -0
- package/android/src/main/AndroidManifest.xml +40 -0
- package/android/src/main/java/com/shakebug/AmazonFireDeviceConnectivityPoller.java +170 -0
- package/android/src/main/java/com/shakebug/BaseUtils.java +33 -0
- package/android/src/main/java/com/shakebug/BroadcastReceiverConnectivityReceiver.java +131 -0
- package/android/src/main/java/com/shakebug/ConnectivityReceiver.java +318 -0
- package/android/src/main/java/com/shakebug/CrashLoggerModule.java +48 -0
- package/android/src/main/java/com/shakebug/DateUtil.java +64 -0
- package/android/src/main/java/com/shakebug/DeviceType.java +18 -0
- package/android/src/main/java/com/shakebug/DeviceUtil.java +46 -0
- package/android/src/main/java/com/shakebug/DrawingView.java +90 -0
- package/android/src/main/java/com/shakebug/DrawingViewManager.java +38 -0
- package/android/src/main/java/com/shakebug/GetLocation.java +147 -0
- package/android/src/main/java/com/shakebug/ImageMetadata.java +42 -0
- package/android/src/main/java/com/shakebug/ImagePickerProvider.java +8 -0
- package/android/src/main/java/com/shakebug/Metadata.java +46 -0
- package/android/src/main/java/com/shakebug/NetInfoModule.java +79 -0
- package/android/src/main/java/com/shakebug/NetInfoUtils.java +50 -0
- package/android/src/main/java/com/shakebug/NetworkCallbackConnectivityReceiver.java +209 -0
- package/android/src/main/java/com/shakebug/Options.java +42 -0
- package/android/src/main/java/com/shakebug/RNDeviceModule.java +1036 -0
- package/android/src/main/java/com/shakebug/RNInstallReferrerClient.java +124 -0
- package/android/src/main/java/com/shakebug/RNLocalizeModule.java +79 -0
- package/android/src/main/java/com/shakebug/RNLocalizeModuleImpl.java +258 -0
- package/android/src/main/java/com/shakebug/ReactNativeGetLocationModule.java +95 -0
- package/android/src/main/java/com/shakebug/RecordScreenModule.java +202 -0
- package/android/src/main/java/com/shakebug/ScreenshotDetectorModule.java +63 -0
- package/android/src/main/java/com/shakebug/SettingsUtil.java +44 -0
- package/android/src/main/java/com/shakebug/Shakebug.java +181 -0
- package/android/src/main/java/com/shakebug/ShakebugPackage.java +75 -0
- package/android/src/main/java/com/shakebug/ShakebugSDKImagePickerModule.java +56 -0
- package/android/src/main/java/com/shakebug/ShakebugSDKImagePickerModuleImpl.java +230 -0
- package/android/src/main/java/com/shakebug/ShakebugSDKScreenShotModule.java +196 -0
- package/android/src/main/java/com/shakebug/SharedPreferencesModule.java +39 -0
- package/android/src/main/java/com/shakebug/UnitConverter.java +48 -0
- package/android/src/main/java/com/shakebug/Utility.java +29 -0
- package/android/src/main/java/com/shakebug/Utils.java +593 -0
- package/android/src/main/java/com/shakebug/VideoMetadata.java +91 -0
- package/android/src/main/java/com/shakebug/VideoPlayerModule.java +199 -0
- package/android/src/main/java/com/shakebug/VideoThumbnailModule.java +215 -0
- package/android/src/main/java/com/shakebug/VideoTrimModule.java +372 -0
- package/android/src/main/java/com/shakebug/ViewShot.java +627 -0
- package/android/src/main/java/com/shakebug/adapters/VideoTrimmerAdapter.java +54 -0
- package/android/src/main/java/com/shakebug/callback/SingleCallback.java +11 -0
- package/android/src/main/java/com/shakebug/interfaces/IVideoTrimmerView.java +5 -0
- package/android/src/main/java/com/shakebug/interfaces/VideoPlayerListner.java +5 -0
- package/android/src/main/java/com/shakebug/interfaces/VideoTrimListener.java +10 -0
- package/android/src/main/java/com/shakebug/resolver/DeviceIdResolver.java +87 -0
- package/android/src/main/java/com/shakebug/resolver/DeviceTypeResolver.java +94 -0
- package/android/src/main/java/com/shakebug/thread/BackgroundExecutor.java +246 -0
- package/android/src/main/java/com/shakebug/thread/UiThreadExecutor.java +120 -0
- package/android/src/main/java/com/shakebug/types/CellularGeneration.java +60 -0
- package/android/src/main/java/com/shakebug/types/ConnectionType.java +26 -0
- package/android/src/main/java/com/shakebug/utils/StorageUtil.java +139 -0
- package/android/src/main/java/com/shakebug/utils/VideoTrimmerUtil.java +89 -0
- package/android/src/main/java/com/shakebug/widgets/RangeSeekBarView.java +534 -0
- package/android/src/main/java/com/shakebug/widgets/SpacesItemDecoration2.java +32 -0
- package/android/src/main/java/com/shakebug/widgets/VideoPlayerView.java +429 -0
- package/android/src/main/java/com/shakebug/widgets/VideoTrimmerView.java +477 -0
- package/android/src/main/java/com/shakebug/widgets/ZVideoView.java +48 -0
- package/android/src/main/res/drawable/custom_progress.xml +16 -0
- package/android/src/main/res/drawable/custom_thumb.xml +4 -0
- package/android/src/main/res/drawable/ic_close_button.xml +10 -0
- package/android/src/main/res/drawable/ic_video_pause_black.png +0 -0
- package/android/src/main/res/drawable/ic_video_play_black.png +0 -0
- package/android/src/main/res/drawable/ic_video_thumb_handle.png +0 -0
- package/android/src/main/res/drawable/icon_seek_bar.png +0 -0
- package/android/src/main/res/layout/video_player_view.xml +121 -0
- package/android/src/main/res/layout/video_thumb_item_layout.xml +16 -0
- package/android/src/main/res/layout/video_trimmer_view.xml +148 -0
- package/android/src/main/res/values/colors.xml +17 -0
- package/android/src/main/res/values/strings.xml +14 -0
- package/android/src/main/res/xml/imagepicker_provider_paths.xml +4 -0
- package/ios/CammeraPermission/RNCameraPermission.h +16 -0
- package/ios/CammeraPermission/RNCameraPermission.m +46 -0
- package/ios/DeviceInfo/DeviceUID.h +14 -0
- package/ios/DeviceInfo/DeviceUID.m +202 -0
- package/ios/DeviceInfo/EnvironmentUtil.h +41 -0
- package/ios/DeviceInfo/EnvironmentUtil.m +56 -0
- package/ios/DeviceInfo/RNDeviceInfo.h +22 -0
- package/ios/DeviceInfo/RNDeviceInfo.m +918 -0
- package/ios/GetLocals/ShakebugSDKRNLocalize.h +21 -0
- package/ios/GetLocals/ShakebugSDKRNLocalize.m +296 -0
- package/ios/GetLocation/SettingsUtil.h +16 -0
- package/ios/GetLocation/SettingsUtil.m +21 -0
- package/ios/GetLocation/ShakebugSDKLocationModule.h +17 -0
- package/ios/GetLocation/ShakebugSDKLocationModule.m +218 -0
- package/ios/ImageOrVideoPicker/ShakebugSDKImagePickerManager.h +40 -0
- package/ios/ImageOrVideoPicker/ShakebugSDKImagePickerManager.m +588 -0
- package/ios/ImageOrVideoPicker/ShakebugSDKImagePickerUtils.h +26 -0
- package/ios/ImageOrVideoPicker/ShakebugSDKImagePickerUtils.m +194 -0
- package/ios/MicrophonePermissionManager.h +14 -0
- package/ios/MicrophonePermissionManager.m +35 -0
- package/ios/NetInfo/RNCConnectionState.h +42 -0
- package/ios/NetInfo/RNCConnectionState.m +119 -0
- package/ios/NetInfo/RNCConnectionStateWatcher.h +31 -0
- package/ios/NetInfo/RNCConnectionStateWatcher.m +136 -0
- package/ios/NetInfo/RNCNetInfo.h +13 -0
- package/ios/NetInfo/RNCNetInfo.m +269 -0
- package/ios/RecordScreen/ShakebugSDKRecordScreen.h +31 -0
- package/ios/RecordScreen/ShakebugSDKRecordScreen.m +309 -0
- package/ios/ScreenShot/ShakebugSDKRNViewShot.h +6 -0
- package/ios/ScreenShot/ShakebugSDKRNViewShot.m +186 -0
- package/ios/ScreenshotDetector/ScreenShotDetector.h +12 -0
- package/ios/ScreenshotDetector/ScreenShotDetector.m +37 -0
- package/ios/Senors/RNSensorsAccelerometer.h +22 -0
- package/ios/Senors/RNSensorsAccelerometer.m +162 -0
- package/ios/Senors/RNSensorsBarometer.h +22 -0
- package/ios/Senors/RNSensorsBarometer.m +141 -0
- package/ios/Senors/RNSensorsGravity.h +22 -0
- package/ios/Senors/RNSensorsGravity.m +165 -0
- package/ios/Senors/RNSensorsGyroscope.h +22 -0
- package/ios/Senors/RNSensorsGyroscope.m +160 -0
- package/ios/Senors/RNSensorsMagnetometer.h +22 -0
- package/ios/Senors/RNSensorsMagnetometer.m +163 -0
- package/ios/Senors/RNSensorsOrientation.h +22 -0
- package/ios/Senors/RNSensorsOrientation.m +189 -0
- package/ios/Senors/RNSensorsUtils.h +7 -0
- package/ios/Senors/RNSensorsUtils.m +9 -0
- package/ios/Shakebug.h +7 -0
- package/ios/Shakebug.m +16 -0
- package/ios/Shakebug.xcodeproj/project.pbxproj +872 -0
- package/ios/Shakebug.xcodeproj/xcshareddata/xcschemes/Shakebug.xcscheme +66 -0
- package/ios/Shakebug.xcworkspace/contents.xcworkspacedata +10 -0
- package/ios/Shakebug.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/SketchCanvas/DrawingView.h +18 -0
- package/ios/SketchCanvas/DrawingView.m +96 -0
- package/ios/SketchCanvas/DrawingViewManager.h +12 -0
- package/ios/SketchCanvas/DrawingViewManager.m +35 -0
- package/ios/Storage/SharedPreferencesModule.h +13 -0
- package/ios/Storage/SharedPreferencesModule.m +35 -0
- package/ios/Thumbnaill/VideoThumbnailManager.h +12 -0
- package/ios/Thumbnaill/VideoThumbnailManager.m +73 -0
- package/ios/TrimVideo/ShakebugSDKVideoTrim.swift +372 -0
- package/ios/TrimVideo/VideoTrim-Bridging-Header.h +10 -0
- package/ios/TrimVideo/VideoTrim.m +23 -0
- package/ios/TrimVideo/VideoTrimmer.swift +810 -0
- package/ios/TrimVideo/VideoTrimmerThumb.swift +119 -0
- package/ios/TrimVideo/VideoTrimmerViewController.swift +301 -0
- package/ios/VideoPlayer/VideoPlayerModule.h +14 -0
- package/ios/VideoPlayer/VideoPlayerModule.m +29 -0
- package/ios/VideoPlayer/VideoPlayerViewController.h +18 -0
- package/ios/VideoPlayer/VideoPlayerViewController.m +29 -0
- package/package.json +45 -0
- package/shakebug-react-native.podspec +50 -0
- package/src/APIs/AddIssue.js +70 -0
- package/src/APIs/EndSession.js +32 -0
- package/src/APIs/Event.js +39 -0
- package/src/APIs/MatchKey.js +40 -0
- package/src/APIs/StartSession.js +84 -0
- package/src/Assets/images/OpenSketch.png +0 -0
- package/src/Assets/images/Push.png +0 -0
- package/src/Assets/images/RemoveTextView.png +0 -0
- package/src/Assets/images/black.png +0 -0
- package/src/Assets/images/blue.png +0 -0
- package/src/Assets/images/borderdBlack.png +0 -0
- package/src/Assets/images/borderdBlue.png +0 -0
- package/src/Assets/images/borderdGreen.png +0 -0
- package/src/Assets/images/borderdRed.png +0 -0
- package/src/Assets/images/borderdYellow.png +0 -0
- package/src/Assets/images/clear.png +0 -0
- package/src/Assets/images/close.png +0 -0
- package/src/Assets/images/green.png +0 -0
- package/src/Assets/images/next.png +0 -0
- package/src/Assets/images/play.png +0 -0
- package/src/Assets/images/red.png +0 -0
- package/src/Assets/images/shake.png +0 -0
- package/src/Assets/images/shakebugLogo.png +0 -0
- package/src/Assets/images/stopButton.png +0 -0
- package/src/Assets/images/text_icon.png +0 -0
- package/src/Assets/images/yellow.png +0 -0
- package/src/Componanats/CustomAlert.js +80 -0
- package/src/Componanats/ErrorHandler.js +80 -0
- package/src/Componanats/GlobalStateContext.js +22 -0
- package/src/Componanats/KeyboardAvoidingWrapper.js +43 -0
- package/src/Componanats/NavigationContext.js +42 -0
- package/src/Componanats/ShakeFunction.js +562 -0
- package/src/Componanats/localization.js +482 -0
- package/src/Screens/AddDetailsScreen.js +462 -0
- package/src/Screens/FirstScreen.js +629 -0
- package/src/Screens/Shakebug.js +487 -0
- package/src/Screens/StrockView.js +20 -0
- package/src/Screens/TrimVideoScreen.js +81 -0
- package/src/Screens/TutorialScreen.js +36 -0
- package/src/index.tsx +117 -0
- package/trimVideo/src/index.tsx +141 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as PrivateTypes from './privateTypes';
|
|
11
|
+
import * as Types from './types';
|
|
12
|
+
|
|
13
|
+
interface InternetReachabilityCheckHandler {
|
|
14
|
+
promise: Promise<void>;
|
|
15
|
+
cancel: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default class InternetReachability {
|
|
19
|
+
private _configuration: Types.NetInfoConfiguration;
|
|
20
|
+
private _listener: PrivateTypes.NetInfoInternetReachabilityChangeListener;
|
|
21
|
+
private _isInternetReachable: boolean | null | undefined = undefined;
|
|
22
|
+
private _currentInternetReachabilityCheckHandler: InternetReachabilityCheckHandler | null = null;
|
|
23
|
+
private _currentTimeoutHandle: ReturnType<typeof setTimeout> | null = null;
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
configuration: Types.NetInfoConfiguration,
|
|
27
|
+
listener: PrivateTypes.NetInfoInternetReachabilityChangeListener,
|
|
28
|
+
) {
|
|
29
|
+
this._configuration = configuration;
|
|
30
|
+
this._listener = listener;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private _setIsInternetReachable = (
|
|
34
|
+
isInternetReachable: boolean | null,
|
|
35
|
+
): void => {
|
|
36
|
+
if (this._isInternetReachable === isInternetReachable) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this._isInternetReachable = isInternetReachable;
|
|
41
|
+
this._listener(this._isInternetReachable);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
private _setExpectsConnection = (expectsConnection: boolean | null): void => {
|
|
45
|
+
// Cancel any pending check
|
|
46
|
+
if (this._currentInternetReachabilityCheckHandler !== null) {
|
|
47
|
+
this._currentInternetReachabilityCheckHandler.cancel();
|
|
48
|
+
this._currentInternetReachabilityCheckHandler = null;
|
|
49
|
+
}
|
|
50
|
+
// Cancel any pending timeout
|
|
51
|
+
if (this._currentTimeoutHandle !== null) {
|
|
52
|
+
clearTimeout(this._currentTimeoutHandle);
|
|
53
|
+
this._currentTimeoutHandle = null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (expectsConnection && this._configuration.reachabilityShouldRun()) {
|
|
57
|
+
// If we expect a connection, start the process for finding if we have one
|
|
58
|
+
// Set the state to "null" if it was previously false
|
|
59
|
+
if (!this._isInternetReachable) {
|
|
60
|
+
this._setIsInternetReachable(null);
|
|
61
|
+
}
|
|
62
|
+
// Start a network request to check for internet
|
|
63
|
+
this._currentInternetReachabilityCheckHandler = this._checkInternetReachability();
|
|
64
|
+
} else {
|
|
65
|
+
// If we don't expect a connection or don't run reachability check, just change the state to "false"
|
|
66
|
+
this._setIsInternetReachable(false);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
private _checkInternetReachability = (): InternetReachabilityCheckHandler => {
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
|
|
73
|
+
const responsePromise = fetch(this._configuration.reachabilityUrl, {
|
|
74
|
+
headers: this._configuration.reachabilityHeaders,
|
|
75
|
+
method: this._configuration.reachabilityMethod,
|
|
76
|
+
cache: 'no-cache',
|
|
77
|
+
signal: controller.signal,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Create promise that will reject after the request timeout has been reached
|
|
81
|
+
let timeoutHandle: ReturnType<typeof setTimeout>;
|
|
82
|
+
const timeoutPromise = new Promise<Response>((_, reject): void => {
|
|
83
|
+
timeoutHandle = setTimeout(
|
|
84
|
+
(): void => reject('timedout'),
|
|
85
|
+
this._configuration.reachabilityRequestTimeout,
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Create promise that makes it possible to cancel a pending request through a reject
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
91
|
+
let cancel: () => void = (): void => {};
|
|
92
|
+
const cancelPromise = new Promise<Response>((_, reject): void => {
|
|
93
|
+
cancel = (): void => reject('canceled');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const promise = Promise.race([
|
|
97
|
+
responsePromise,
|
|
98
|
+
timeoutPromise,
|
|
99
|
+
cancelPromise,
|
|
100
|
+
])
|
|
101
|
+
.then(
|
|
102
|
+
(response): Promise<boolean> => {
|
|
103
|
+
return this._configuration.reachabilityTest(response);
|
|
104
|
+
},
|
|
105
|
+
)
|
|
106
|
+
.then(
|
|
107
|
+
(result): void => {
|
|
108
|
+
this._setIsInternetReachable(result);
|
|
109
|
+
const nextTimeoutInterval = this._isInternetReachable
|
|
110
|
+
? this._configuration.reachabilityLongTimeout
|
|
111
|
+
: this._configuration.reachabilityShortTimeout;
|
|
112
|
+
this._currentTimeoutHandle = setTimeout(
|
|
113
|
+
this._checkInternetReachability,
|
|
114
|
+
nextTimeoutInterval,
|
|
115
|
+
);
|
|
116
|
+
},
|
|
117
|
+
)
|
|
118
|
+
.catch(
|
|
119
|
+
(error: Error | 'timedout' | 'canceled'): void => {
|
|
120
|
+
if ('canceled' === error) {
|
|
121
|
+
controller.abort();
|
|
122
|
+
} else {
|
|
123
|
+
if ('timedout' === error) {
|
|
124
|
+
controller.abort();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
this._setIsInternetReachable(false);
|
|
128
|
+
this._currentTimeoutHandle = setTimeout(
|
|
129
|
+
this._checkInternetReachability,
|
|
130
|
+
this._configuration.reachabilityShortTimeout,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
)
|
|
135
|
+
// Clear request timeout and propagate any errors
|
|
136
|
+
.then(
|
|
137
|
+
(): void => {
|
|
138
|
+
clearTimeout(timeoutHandle);
|
|
139
|
+
},
|
|
140
|
+
(error: Error): void => {
|
|
141
|
+
clearTimeout(timeoutHandle);
|
|
142
|
+
throw error;
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
promise,
|
|
148
|
+
cancel,
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
public update = (state: PrivateTypes.NetInfoNativeModuleState): void => {
|
|
153
|
+
if (
|
|
154
|
+
typeof state.isInternetReachable === 'boolean' &&
|
|
155
|
+
this._configuration.useNativeReachability
|
|
156
|
+
) {
|
|
157
|
+
this._setIsInternetReachable(state.isInternetReachable);
|
|
158
|
+
} else {
|
|
159
|
+
this._setExpectsConnection(state.isConnected);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
public currentState = (): boolean | null | undefined => {
|
|
164
|
+
return this._isInternetReachable;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
public tearDown = (): void => {
|
|
168
|
+
// Cancel any pending check
|
|
169
|
+
if (this._currentInternetReachabilityCheckHandler !== null) {
|
|
170
|
+
this._currentInternetReachabilityCheckHandler.cancel();
|
|
171
|
+
this._currentInternetReachabilityCheckHandler = null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Cancel any pending timeout
|
|
175
|
+
if (this._currentTimeoutHandle !== null) {
|
|
176
|
+
clearTimeout(this._currentTimeoutHandle);
|
|
177
|
+
this._currentTimeoutHandle = null;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {NativeEventEmitter} from 'react-native';
|
|
11
|
+
import RNCNetInfo from './nativeModule';
|
|
12
|
+
|
|
13
|
+
// Produce an error if we don't have the native module
|
|
14
|
+
if (!RNCNetInfo) {
|
|
15
|
+
throw new Error(`@react-native-community/netinfo: NativeModule.RNCNetInfo is null. To fix this issue try these steps:
|
|
16
|
+
|
|
17
|
+
• Run \`react-native link @react-native-community/netinfo\` in the project root.
|
|
18
|
+
• Rebuild and re-run the app.
|
|
19
|
+
• If you are using CocoaPods on iOS, run \`pod install\` in the \`ios\` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.
|
|
20
|
+
• Check that the library was linked correctly when you used the link command by running through the manual installation instructions in the README.
|
|
21
|
+
* If you are getting this error while unit testing you need to mock the native module. Follow the guide in the README.
|
|
22
|
+
|
|
23
|
+
If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-netinfo`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* We export the native interface in this way to give easy shared access to it between the
|
|
28
|
+
* JavaScript code and the tests
|
|
29
|
+
*/
|
|
30
|
+
let nativeEventEmitter: NativeEventEmitter | null = null;
|
|
31
|
+
const nativeInterface = Object.assign(RNCNetInfo, {
|
|
32
|
+
get eventEmitter(): NativeEventEmitter {
|
|
33
|
+
if (!nativeEventEmitter) {
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
35
|
+
/// @ts-ignore
|
|
36
|
+
nativeEventEmitter = new NativeEventEmitter(RNCNetInfo);
|
|
37
|
+
}
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
39
|
+
/// @ts-ignore
|
|
40
|
+
return nativeEventEmitter;
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
export default nativeInterface;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {NativeEventEmitter} from 'react-native';
|
|
11
|
+
import RNCNetInfo from './nativeModule';
|
|
12
|
+
import {DEVICE_CONNECTIVITY_EVENT} from './privateTypes';
|
|
13
|
+
|
|
14
|
+
const nativeEventEmitter = new NativeEventEmitter();
|
|
15
|
+
|
|
16
|
+
// Listen to connectivity events
|
|
17
|
+
RNCNetInfo.addListener(
|
|
18
|
+
DEVICE_CONNECTIVITY_EVENT,
|
|
19
|
+
(event): void => {
|
|
20
|
+
nativeEventEmitter.emit(DEVICE_CONNECTIVITY_EVENT, event);
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
...RNCNetInfo,
|
|
26
|
+
eventEmitter: nativeEventEmitter,
|
|
27
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {NativeModules} from 'react-native';
|
|
11
|
+
import {NetInfoNativeModule} from './privateTypes';
|
|
12
|
+
|
|
13
|
+
const RNCNetInfo: NetInfoNativeModule = NativeModules.ShakebugSDKRNCNetInfo;
|
|
14
|
+
|
|
15
|
+
export default RNCNetInfo;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
DEVICE_CONNECTIVITY_EVENT,
|
|
12
|
+
NetInfoNativeModule,
|
|
13
|
+
NetInfoNativeModuleState,
|
|
14
|
+
} from './privateTypes';
|
|
15
|
+
import {
|
|
16
|
+
NetInfoBluetoothState,
|
|
17
|
+
NetInfoCellularGeneration,
|
|
18
|
+
NetInfoCellularState,
|
|
19
|
+
NetInfoEthernetState,
|
|
20
|
+
NetInfoNoConnectionState,
|
|
21
|
+
NetInfoOtherState,
|
|
22
|
+
NetInfoState,
|
|
23
|
+
NetInfoStateType,
|
|
24
|
+
NetInfoUnknownState,
|
|
25
|
+
NetInfoWifiState,
|
|
26
|
+
NetInfoWimaxState,
|
|
27
|
+
} from './types';
|
|
28
|
+
|
|
29
|
+
// See https://wicg.github.io/netinfo/#dom-connectiontype
|
|
30
|
+
type ConnectionType =
|
|
31
|
+
| 'bluetooth'
|
|
32
|
+
| 'cellular'
|
|
33
|
+
| 'ethernet'
|
|
34
|
+
| 'mixed'
|
|
35
|
+
| 'none'
|
|
36
|
+
| 'other'
|
|
37
|
+
| 'unknown'
|
|
38
|
+
| 'wifi'
|
|
39
|
+
| 'wimax';
|
|
40
|
+
|
|
41
|
+
// See https://wicg.github.io/netinfo/#dom-effectiveconnectiontype
|
|
42
|
+
type ConnectionEffectiveType = '2g' | '3g' | '4g' | 'slow-2g';
|
|
43
|
+
|
|
44
|
+
// https://wicg.github.io/netinfo/#dom-networkinformation-savedata
|
|
45
|
+
type ConnectionSaveData = boolean;
|
|
46
|
+
|
|
47
|
+
interface Events {
|
|
48
|
+
change: Event;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface Connection {
|
|
52
|
+
type: ConnectionType;
|
|
53
|
+
effectiveType: ConnectionEffectiveType;
|
|
54
|
+
saveData: ConnectionSaveData;
|
|
55
|
+
addEventListener<K extends keyof Events>(
|
|
56
|
+
type: K,
|
|
57
|
+
listener: (event: Events[K]) => void,
|
|
58
|
+
): void;
|
|
59
|
+
removeEventListener<K extends keyof Events>(
|
|
60
|
+
type: K,
|
|
61
|
+
listener: (event: Events[K]) => void,
|
|
62
|
+
): void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Create (optional) connection APIs on navigator
|
|
66
|
+
declare global {
|
|
67
|
+
interface Navigator {
|
|
68
|
+
connection?: Connection;
|
|
69
|
+
mozConnection?: Connection;
|
|
70
|
+
webkitConnection?: Connection;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Use a constant test of this form because in SSR on next.js, optional chaining is not sufficient,
|
|
74
|
+
// but this test correctly detects that window is not available and allows for conditionals before access
|
|
75
|
+
const isWindowPresent = typeof window !== 'undefined';
|
|
76
|
+
|
|
77
|
+
// Check if window exists and if the browser supports the connection API
|
|
78
|
+
const connection = (isWindowPresent && !window.hasOwnProperty('tizen') && !window.hasOwnProperty('webOS'))
|
|
79
|
+
? window.navigator.connection ||
|
|
80
|
+
window.navigator.mozConnection ||
|
|
81
|
+
window.navigator.webkitConnection
|
|
82
|
+
: undefined;
|
|
83
|
+
|
|
84
|
+
// Map browser types to native types
|
|
85
|
+
const typeMapping: Record<ConnectionType, NetInfoStateType> = {
|
|
86
|
+
bluetooth: NetInfoStateType.bluetooth,
|
|
87
|
+
cellular: NetInfoStateType.cellular,
|
|
88
|
+
ethernet: NetInfoStateType.ethernet,
|
|
89
|
+
none: NetInfoStateType.none,
|
|
90
|
+
other: NetInfoStateType.other,
|
|
91
|
+
unknown: NetInfoStateType.unknown,
|
|
92
|
+
wifi: NetInfoStateType.wifi,
|
|
93
|
+
wimax: NetInfoStateType.wimax,
|
|
94
|
+
mixed: NetInfoStateType.other,
|
|
95
|
+
};
|
|
96
|
+
const effectiveTypeMapping: Record<
|
|
97
|
+
ConnectionEffectiveType,
|
|
98
|
+
NetInfoCellularGeneration
|
|
99
|
+
> = {
|
|
100
|
+
'2g': NetInfoCellularGeneration['2g'],
|
|
101
|
+
'3g': NetInfoCellularGeneration['3g'],
|
|
102
|
+
'4g': NetInfoCellularGeneration['4g'],
|
|
103
|
+
'slow-2g': NetInfoCellularGeneration['2g'],
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Determine current state of connection
|
|
107
|
+
const getCurrentState = (
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
109
|
+
_requestedInterface?: string,
|
|
110
|
+
): Pick<NetInfoState, Exclude<keyof NetInfoState, 'isInternetReachable'>> => {
|
|
111
|
+
const isConnected = isWindowPresent ? navigator.onLine : false;
|
|
112
|
+
const baseState = {
|
|
113
|
+
isInternetReachable: null,
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// If we don't have a connection object, we return minimal information
|
|
117
|
+
if (!connection) {
|
|
118
|
+
if (isConnected) {
|
|
119
|
+
const state: NetInfoOtherState = {
|
|
120
|
+
...baseState,
|
|
121
|
+
isConnected: true,
|
|
122
|
+
type: NetInfoStateType.other,
|
|
123
|
+
details: {
|
|
124
|
+
isConnectionExpensive: false,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
return state;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const state: NetInfoNoConnectionState = {
|
|
131
|
+
...baseState,
|
|
132
|
+
isConnected: false,
|
|
133
|
+
isInternetReachable: false,
|
|
134
|
+
type: NetInfoStateType.none,
|
|
135
|
+
details: null,
|
|
136
|
+
};
|
|
137
|
+
return state;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Otherwise try to return detailed information
|
|
141
|
+
const isConnectionExpensive = connection.saveData;
|
|
142
|
+
const type: NetInfoStateType = connection.type
|
|
143
|
+
? typeMapping[connection.type]
|
|
144
|
+
: isConnected
|
|
145
|
+
? NetInfoStateType.other
|
|
146
|
+
: NetInfoStateType.unknown;
|
|
147
|
+
|
|
148
|
+
if (type === NetInfoStateType.bluetooth) {
|
|
149
|
+
const state: NetInfoBluetoothState = {
|
|
150
|
+
...baseState,
|
|
151
|
+
isConnected: true,
|
|
152
|
+
type,
|
|
153
|
+
details: {
|
|
154
|
+
isConnectionExpensive,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
return state;
|
|
158
|
+
} else if (type === NetInfoStateType.cellular) {
|
|
159
|
+
const state: NetInfoCellularState = {
|
|
160
|
+
...baseState,
|
|
161
|
+
isConnected: true,
|
|
162
|
+
type,
|
|
163
|
+
details: {
|
|
164
|
+
isConnectionExpensive,
|
|
165
|
+
cellularGeneration:
|
|
166
|
+
effectiveTypeMapping[connection.effectiveType] || null,
|
|
167
|
+
carrier: null,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
return state;
|
|
171
|
+
} else if (type === NetInfoStateType.ethernet) {
|
|
172
|
+
const state: NetInfoEthernetState = {
|
|
173
|
+
...baseState,
|
|
174
|
+
isConnected: true,
|
|
175
|
+
type,
|
|
176
|
+
details: {
|
|
177
|
+
isConnectionExpensive,
|
|
178
|
+
ipAddress: null,
|
|
179
|
+
subnet: null,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
return state;
|
|
183
|
+
} else if (type === NetInfoStateType.wifi) {
|
|
184
|
+
const state: NetInfoWifiState = {
|
|
185
|
+
...baseState,
|
|
186
|
+
isConnected: true,
|
|
187
|
+
type,
|
|
188
|
+
details: {
|
|
189
|
+
isConnectionExpensive,
|
|
190
|
+
ssid: null,
|
|
191
|
+
bssid: null,
|
|
192
|
+
strength: null,
|
|
193
|
+
ipAddress: null,
|
|
194
|
+
subnet: null,
|
|
195
|
+
frequency: null,
|
|
196
|
+
linkSpeed: null,
|
|
197
|
+
rxLinkSpeed: null,
|
|
198
|
+
txLinkSpeed: null,
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
return state;
|
|
202
|
+
} else if (type === NetInfoStateType.wimax) {
|
|
203
|
+
const state: NetInfoWimaxState = {
|
|
204
|
+
...baseState,
|
|
205
|
+
isConnected: true,
|
|
206
|
+
type,
|
|
207
|
+
details: {
|
|
208
|
+
isConnectionExpensive,
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
return state;
|
|
212
|
+
} else if (type === NetInfoStateType.none) {
|
|
213
|
+
const state: NetInfoNoConnectionState = {
|
|
214
|
+
...baseState,
|
|
215
|
+
isConnected: false,
|
|
216
|
+
isInternetReachable: false,
|
|
217
|
+
type,
|
|
218
|
+
details: null,
|
|
219
|
+
};
|
|
220
|
+
return state;
|
|
221
|
+
} else if (type === NetInfoStateType.unknown) {
|
|
222
|
+
const state: NetInfoUnknownState = {
|
|
223
|
+
...baseState,
|
|
224
|
+
isConnected,
|
|
225
|
+
isInternetReachable: null,
|
|
226
|
+
type,
|
|
227
|
+
details: null,
|
|
228
|
+
};
|
|
229
|
+
return state;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const state: NetInfoOtherState = {
|
|
233
|
+
...baseState,
|
|
234
|
+
isConnected: true,
|
|
235
|
+
type: NetInfoStateType.other,
|
|
236
|
+
details: {
|
|
237
|
+
isConnectionExpensive,
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
return state;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const handlers: ((state: NetInfoNativeModuleState) => void)[] = [];
|
|
244
|
+
const nativeHandlers: (() => void)[] = [];
|
|
245
|
+
|
|
246
|
+
const RNCNetInfo: NetInfoNativeModule = {
|
|
247
|
+
addListener(type, handler): void {
|
|
248
|
+
switch (type) {
|
|
249
|
+
case DEVICE_CONNECTIVITY_EVENT: {
|
|
250
|
+
const nativeHandler = (): void => {
|
|
251
|
+
handler(getCurrentState());
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
if (connection) {
|
|
255
|
+
connection.addEventListener('change', nativeHandler);
|
|
256
|
+
} else {
|
|
257
|
+
if (isWindowPresent) {
|
|
258
|
+
window.addEventListener('online', nativeHandler, false);
|
|
259
|
+
window.addEventListener('offline', nativeHandler, false);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Remember handlers
|
|
264
|
+
handlers.push(handler);
|
|
265
|
+
nativeHandlers.push(nativeHandler);
|
|
266
|
+
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
removeListeners(type, handler): void {
|
|
273
|
+
switch (type) {
|
|
274
|
+
case DEVICE_CONNECTIVITY_EVENT: {
|
|
275
|
+
// Get native handler
|
|
276
|
+
const index = handlers.indexOf(handler);
|
|
277
|
+
const nativeHandler = nativeHandlers[index];
|
|
278
|
+
|
|
279
|
+
if (connection) {
|
|
280
|
+
connection.removeEventListener('change', nativeHandler);
|
|
281
|
+
} else {
|
|
282
|
+
if (isWindowPresent) {
|
|
283
|
+
window.removeEventListener('online', nativeHandler);
|
|
284
|
+
window.removeEventListener('offline', nativeHandler);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Remove handlers
|
|
289
|
+
handlers.splice(index, 1);
|
|
290
|
+
nativeHandlers.splice(index, 1);
|
|
291
|
+
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
async getCurrentState(requestedInterface): Promise<NetInfoNativeModuleState> {
|
|
298
|
+
return getCurrentState(requestedInterface);
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
configure(): void {
|
|
302
|
+
return;
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
export default RNCNetInfo;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @format
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {NetInfoConfiguration, NetInfoState} from './types';
|
|
11
|
+
|
|
12
|
+
export const DEVICE_CONNECTIVITY_EVENT = 'netInfo.networkStatusDidChange';
|
|
13
|
+
|
|
14
|
+
// Certain properties are optional when sent by the native module and are handled by the JS code
|
|
15
|
+
export type NetInfoNativeModuleState = Pick<
|
|
16
|
+
NetInfoState,
|
|
17
|
+
Exclude<keyof NetInfoState, 'isInternetReachable'>
|
|
18
|
+
> & {isInternetReachable?: boolean};
|
|
19
|
+
|
|
20
|
+
export interface Events {
|
|
21
|
+
[DEVICE_CONNECTIVITY_EVENT]: NetInfoNativeModuleState;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface NetInfoNativeModule {
|
|
25
|
+
configure: (config: Partial<NetInfoConfiguration>) => void;
|
|
26
|
+
getCurrentState: (
|
|
27
|
+
requestedInterface?: string,
|
|
28
|
+
) => Promise<NetInfoNativeModuleState>;
|
|
29
|
+
addListener<K extends keyof Events>(
|
|
30
|
+
type: K,
|
|
31
|
+
listener: (event: Events[K]) => void,
|
|
32
|
+
): void;
|
|
33
|
+
removeListeners<K extends keyof Events>(
|
|
34
|
+
type: K,
|
|
35
|
+
listener: (event: Events[K]) => void,
|
|
36
|
+
): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type NetInfoInternetReachabilityChangeListener = (
|
|
40
|
+
isInternetReachable: boolean | null | undefined,
|
|
41
|
+
) => void;
|