@react-native-community/netinfo
Advanced tools
+84
-47
@@ -21,2 +21,3 @@ /** | ||
| #import <CoreTelephony/CTTelephonyNetworkInfo.h> | ||
| #import <NetworkExtension/NetworkExtension.h> | ||
| #endif | ||
@@ -96,4 +97,7 @@ #import <SystemConfiguration/CaptiveNetwork.h> | ||
| if (self.isObserving) { | ||
| NSDictionary *dictionary = [self currentDictionaryFromUpdateState:state withInterface:NULL]; | ||
| [self sendEventWithName:@"netInfo.networkStatusDidChange" body:dictionary]; | ||
| [self currentDictionaryFromUpdateState:state | ||
| withInterface:NULL | ||
| completion:^(NSDictionary *dictionary) { | ||
| [self sendEventWithName:@"netInfo.networkStatusDidChange" body:dictionary]; | ||
| }]; | ||
| } | ||
@@ -108,3 +112,7 @@ } | ||
| RNCConnectionState *state = [self.connectionStateWatcher currentState]; | ||
| resolve([self currentDictionaryFromUpdateState:state withInterface:requestedInterface]); | ||
| [self currentDictionaryFromUpdateState:state | ||
| withInterface:requestedInterface | ||
| completion:^(NSDictionary *dictionary) { | ||
| resolve(dictionary); | ||
| }]; | ||
| } | ||
@@ -121,19 +129,26 @@ | ||
| // Converts the state into a dictionary to send over the bridge | ||
| - (NSDictionary *)currentDictionaryFromUpdateState:(RNCConnectionState *)state withInterface:(nullable NSString *)requestedInterface | ||
| - (void)currentDictionaryFromUpdateState:(RNCConnectionState *)state | ||
| withInterface:(nullable NSString *)requestedInterface | ||
| completion:(void (^)(NSDictionary *dictionary))completion | ||
| { | ||
| NSString *selectedInterface = requestedInterface ?: state.type; | ||
| NSMutableDictionary *details = [self detailsFromInterface:selectedInterface withState:state]; | ||
| bool connected = [state.type isEqualToString:selectedInterface] && state.connected; | ||
| if (connected) { | ||
| details[@"isConnectionExpensive"] = @(state.expensive); | ||
| } | ||
| return @{ | ||
| @"type": selectedInterface, | ||
| @"isConnected": @(connected), | ||
| @"details": details ?: NSNull.null | ||
| }; | ||
| [self detailsFromInterface:selectedInterface withState:state completion:^(NSMutableDictionary *details) { | ||
| if (connected) { | ||
| details[@"isConnectionExpensive"] = @(state.expensive); | ||
| } | ||
| NSDictionary *result = @{ | ||
| @"type": selectedInterface, | ||
| @"isConnected": @(connected), | ||
| @"details": details ?: NSNull.null | ||
| }; | ||
| completion(result); | ||
| }]; | ||
| } | ||
| - (NSMutableDictionary *)detailsFromInterface:(nonnull NSString *)requestedInterface withState:(RNCConnectionState *)state | ||
| - (void)detailsFromInterface:(nonnull NSString *)requestedInterface | ||
| withState:(RNCConnectionState *)state | ||
| completion:(void (^)(NSMutableDictionary *details))completion | ||
| { | ||
@@ -153,8 +168,23 @@ NSMutableDictionary *details = [NSMutableDictionary new]; | ||
| if (self.config && self.config[@"shouldFetchWiFiSSID"]) { | ||
| details[@"ssid"] = [self ssid] ?: NSNull.null; | ||
| details[@"bssid"] = [self bssid] ?: NSNull.null; | ||
| __weak __typeof(self) weakSelf = self; | ||
| [self ssid:^(NSString * _Nullable ssid) { | ||
| __strong __typeof(weakSelf) strongSelf = weakSelf; | ||
| if (strongSelf == nil) { | ||
| completion(details); | ||
| return; | ||
| } | ||
| details[@"ssid"] = ssid ?: NSNull.null; | ||
| [self bssid:^(NSString * _Nullable bssid) { | ||
| details[@"bssid"] = bssid ?: NSNull.null; | ||
| completion(details); | ||
| }]; | ||
| }]; | ||
| return; | ||
| } | ||
| #endif | ||
| } | ||
| return details; | ||
| completion(details); | ||
| } | ||
@@ -246,36 +276,43 @@ | ||
| #if !TARGET_OS_TV && !TARGET_OS_OSX && !TARGET_OS_MACCATALYST | ||
| - (NSString *)ssid | ||
| - (void)ssid:(void (^)(NSString * _Nullable))completion | ||
| { | ||
| NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces()); | ||
| NSDictionary *SSIDInfo; | ||
| NSString *SSID = NULL; | ||
| for (NSString *interfaceName in interfaceNames) { | ||
| // CNCopyCurrentNetworkInfo is deprecated for iOS 13+, need to override & use fetchCurrentWithCompletionHandler | ||
| SSIDInfo = CFBridgingRelease(CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName)); | ||
| if (SSIDInfo.count > 0) { | ||
| SSID = SSIDInfo[@"SSID"]; | ||
| if ([SSID isEqualToString:@"Wi-Fi"] || [SSID isEqualToString:@"WLAN"]){ | ||
| SSID = NULL; | ||
| __weak __typeof(self) weakSelf = self; | ||
| [NEHotspotNetwork fetchCurrentWithCompletionHandler:^(NEHotspotNetwork * _Nullable currentNetwork) { | ||
| __strong __typeof(weakSelf) strongSelf = weakSelf; | ||
| if(strongSelf == nil){ | ||
| completion(nil); | ||
| return; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| return SSID; | ||
| NSString *SSID = nil; | ||
| if (currentNetwork != nil) { | ||
| NSString *networkSSID = currentNetwork.SSID; | ||
| if (networkSSID != nil && | ||
| ![networkSSID isEqualToString:@"Wi-Fi"] && | ||
| ![networkSSID isEqualToString:@"WLAN"]) { | ||
| SSID = networkSSID; | ||
| } | ||
| } | ||
| completion(SSID); | ||
| }]; | ||
| } | ||
| - (NSString *)bssid | ||
| - (void)bssid:(void (^)(NSString * _Nullable))completion | ||
| { | ||
| NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces()); | ||
| NSDictionary *networkDetails; | ||
| NSString *BSSID = NULL; | ||
| for (NSString *interfaceName in interfaceNames) { | ||
| // CNCopyCurrentNetworkInfo is deprecated for iOS 13+, need to override & use fetchCurrentWithCompletionHandler | ||
| networkDetails = CFBridgingRelease(CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName)); | ||
| if (networkDetails.count > 0) | ||
| { | ||
| BSSID = networkDetails[(NSString *) kCNNetworkInfoKeyBSSID]; | ||
| break; | ||
| } | ||
| } | ||
| return BSSID; | ||
| __weak __typeof(self) weakSelf = self; | ||
| [NEHotspotNetwork fetchCurrentWithCompletionHandler:^(NEHotspotNetwork * _Nullable currentNetwork) { | ||
| __strong __typeof(weakSelf) strongSelf = weakSelf; | ||
| if(strongSelf == nil){ | ||
| completion(nil); | ||
| return; | ||
| } | ||
| NSString *BSSID = nil; | ||
| if (currentNetwork != nil) { | ||
| BSSID = currentNetwork.BSSID; | ||
| } | ||
| completion(BSSID); | ||
| }]; | ||
| } | ||
@@ -282,0 +319,0 @@ #endif |
@@ -17,9 +17,10 @@ "use strict"; | ||
| // React Native sets `__turboModuleProxy` on global when TurboModules are enabled. | ||
| // Currently, this is the recommended way to detect TurboModules. | ||
| // https://reactnative.dev/docs/the-new-architecture/backward-compatibility-turbomodules#unify-the-javascript-specs | ||
| // React Native sets `__turboModuleProxy` on global when TurboModules are enabled for | ||
| // react-native versions < 0.77. After that, they unified access and no longer set | ||
| // `__turboModuleProxy` so it fails as a test. However, our native module name | ||
| // stays the same, so we can just blindly load using unified loading in RN >= 77 | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| const isTurboModuleEnabled = global.__turboModuleProxy != null; | ||
| const RNCNetInfo = isTurboModuleEnabled ? | ||
| const legacyTurboModuleAccess = global.__turboModuleProxy != null; | ||
| const RNCNetInfo = legacyTurboModuleAccess ? | ||
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
@@ -26,0 +27,0 @@ require('./NativeRNCNetInfo').default : _reactNative.NativeModules.RNCNetInfo; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"names":["_reactNative","require","isTurboModuleEnabled","global","__turboModuleProxy","RNCNetInfo","default","NativeModules","_default","exports"],"sources":["nativeModule.ts"],"sourcesContent":["/**\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @format\n */\n\nimport {NativeModules} from 'react-native';\nimport {NetInfoNativeModule} from './privateTypes';\n\n// React Native sets `__turboModuleProxy` on global when TurboModules are enabled.\n// Currently, this is the recommended way to detect TurboModules.\n// https://reactnative.dev/docs/the-new-architecture/backward-compatibility-turbomodules#unify-the-javascript-specs\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nconst isTurboModuleEnabled = global.__turboModuleProxy != null;\n\nconst RNCNetInfo: NetInfoNativeModule = isTurboModuleEnabled\n ? // eslint-disable-next-line @typescript-eslint/no-var-requires\n require('./NativeRNCNetInfo').default\n : NativeModules.RNCNetInfo;\n\nexport default RNCNetInfo;\n"],"mappings":";;;;;;AASA,IAAAA,YAAA,GAAAC,OAAA;AATA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,UAA+B,GAAGH,oBAAoB;AACxD;AACAD,OAAO,CAAC,oBAAoB,CAAC,CAACK,OAAO,GACrCC,0BAAa,CAACF,UAAU;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAAH,OAAA,GAEdD,UAAU"} | ||
| {"version":3,"names":["_reactNative","require","legacyTurboModuleAccess","global","__turboModuleProxy","RNCNetInfo","default","NativeModules","_default","exports"],"sources":["nativeModule.ts"],"sourcesContent":["/**\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @format\n */\n\nimport {NativeModules} from 'react-native';\nimport {NetInfoNativeModule} from './privateTypes';\n\n// React Native sets `__turboModuleProxy` on global when TurboModules are enabled for\n// react-native versions < 0.77. After that, they unified access and no longer set\n// `__turboModuleProxy` so it fails as a test. However, our native module name\n// stays the same, so we can just blindly load using unified loading in RN >= 77\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nconst legacyTurboModuleAccess = global.__turboModuleProxy != null;\n\nconst RNCNetInfo: NetInfoNativeModule = legacyTurboModuleAccess\n ? // eslint-disable-next-line @typescript-eslint/no-var-requires\n require('./NativeRNCNetInfo').default\n : NativeModules.RNCNetInfo;\n\nexport default RNCNetInfo;\n"],"mappings":";;;;;;AASA,IAAAA,YAAA,GAAAC,OAAA;AATA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,uBAAuB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAEjE,MAAMC,UAA+B,GAAGH,uBAAuB;AAC3D;AACAD,OAAO,CAAC,oBAAoB,CAAC,CAACK,OAAO,GACrCC,0BAAa,CAACF,UAAU;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAAH,OAAA,GAEdD,UAAU"} |
@@ -11,9 +11,10 @@ /** | ||
| import { NativeModules } from 'react-native'; | ||
| // React Native sets `__turboModuleProxy` on global when TurboModules are enabled. | ||
| // Currently, this is the recommended way to detect TurboModules. | ||
| // https://reactnative.dev/docs/the-new-architecture/backward-compatibility-turbomodules#unify-the-javascript-specs | ||
| // React Native sets `__turboModuleProxy` on global when TurboModules are enabled for | ||
| // react-native versions < 0.77. After that, they unified access and no longer set | ||
| // `__turboModuleProxy` so it fails as a test. However, our native module name | ||
| // stays the same, so we can just blindly load using unified loading in RN >= 77 | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| const isTurboModuleEnabled = global.__turboModuleProxy != null; | ||
| const RNCNetInfo = isTurboModuleEnabled ? | ||
| const legacyTurboModuleAccess = global.__turboModuleProxy != null; | ||
| const RNCNetInfo = legacyTurboModuleAccess ? | ||
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
@@ -20,0 +21,0 @@ require('./NativeRNCNetInfo').default : NativeModules.RNCNetInfo; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"names":["NativeModules","isTurboModuleEnabled","global","__turboModuleProxy","RNCNetInfo","require","default"],"sources":["nativeModule.ts"],"sourcesContent":["/**\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @format\n */\n\nimport {NativeModules} from 'react-native';\nimport {NetInfoNativeModule} from './privateTypes';\n\n// React Native sets `__turboModuleProxy` on global when TurboModules are enabled.\n// Currently, this is the recommended way to detect TurboModules.\n// https://reactnative.dev/docs/the-new-architecture/backward-compatibility-turbomodules#unify-the-javascript-specs\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nconst isTurboModuleEnabled = global.__turboModuleProxy != null;\n\nconst RNCNetInfo: NetInfoNativeModule = isTurboModuleEnabled\n ? // eslint-disable-next-line @typescript-eslint/no-var-requires\n require('./NativeRNCNetInfo').default\n : NativeModules.RNCNetInfo;\n\nexport default RNCNetInfo;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAQA,aAAa,QAAO,cAAc;AAG1C;AACA;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,UAA+B,GAAGH,oBAAoB;AACxD;AACAI,OAAO,CAAC,oBAAoB,CAAC,CAACC,OAAO,GACrCN,aAAa,CAACI,UAAU;AAE5B,eAAeA,UAAU"} | ||
| {"version":3,"names":["NativeModules","legacyTurboModuleAccess","global","__turboModuleProxy","RNCNetInfo","require","default"],"sources":["nativeModule.ts"],"sourcesContent":["/**\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * @format\n */\n\nimport {NativeModules} from 'react-native';\nimport {NetInfoNativeModule} from './privateTypes';\n\n// React Native sets `__turboModuleProxy` on global when TurboModules are enabled for\n// react-native versions < 0.77. After that, they unified access and no longer set\n// `__turboModuleProxy` so it fails as a test. However, our native module name\n// stays the same, so we can just blindly load using unified loading in RN >= 77\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nconst legacyTurboModuleAccess = global.__turboModuleProxy != null;\n\nconst RNCNetInfo: NetInfoNativeModule = legacyTurboModuleAccess\n ? // eslint-disable-next-line @typescript-eslint/no-var-requires\n require('./NativeRNCNetInfo').default\n : NativeModules.RNCNetInfo;\n\nexport default RNCNetInfo;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAQA,aAAa,QAAO,cAAc;AAG1C;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,uBAAuB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAEjE,MAAMC,UAA+B,GAAGH,uBAAuB;AAC3D;AACAI,OAAO,CAAC,oBAAoB,CAAC,CAACC,OAAO,GACrCN,aAAa,CAACI,UAAU;AAE5B,eAAeA,UAAU"} |
+1
-1
| { | ||
| "name": "@react-native-community/netinfo", | ||
| "version": "11.5.2", | ||
| "version": "12.0.0", | ||
| "description": "React Native Network Info API for iOS & Android", | ||
@@ -5,0 +5,0 @@ "react-native": "src/index.ts", |
@@ -13,10 +13,11 @@ /** | ||
| // React Native sets `__turboModuleProxy` on global when TurboModules are enabled. | ||
| // Currently, this is the recommended way to detect TurboModules. | ||
| // https://reactnative.dev/docs/the-new-architecture/backward-compatibility-turbomodules#unify-the-javascript-specs | ||
| // React Native sets `__turboModuleProxy` on global when TurboModules are enabled for | ||
| // react-native versions < 0.77. After that, they unified access and no longer set | ||
| // `__turboModuleProxy` so it fails as a test. However, our native module name | ||
| // stays the same, so we can just blindly load using unified loading in RN >= 77 | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| const isTurboModuleEnabled = global.__turboModuleProxy != null; | ||
| const legacyTurboModuleAccess = global.__turboModuleProxy != null; | ||
| const RNCNetInfo: NetInfoNativeModule = isTurboModuleEnabled | ||
| const RNCNetInfo: NetInfoNativeModule = legacyTurboModuleAccess | ||
| ? // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
@@ -23,0 +24,0 @@ require('./NativeRNCNetInfo').default |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
516095
0.32%5011
0.06%