diff --git a/README.md b/README.md index 91bec14f..7bbe2f75 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,10 @@ The `details` value depends on the `type` value. | `ipAddress` | Android, iOS, macOS, Windows | `string` | The external IP address. Can be in IPv4 or IPv6 format. May not be present if it cannot be determined. | | `subnet` | Android, iOS, macOS | `string` | The subnet mask in IPv4 format. May not be present if it cannot be determined. | | `frequency` | Android, Windows* | `number` | Network frequency. Example: For 2.4 GHz networks, the method will return 2457. May not be present if it cannot be determined. | +| `linkSpeed` | Android | `number` | The link speed in Mbps. | +| `rxLinkSpeed` | Android | `number` | The current receive link speed in Mbps. (Android Q / API level 29 and above) | +| `txLinkSpeed` | Android | `number` | The current transmit link speed in Mbps. (Android Q / API level 29 and above) | + `*` Requires `wiFiControl` capability in appxmanifest. Without it, these values will be null. diff --git a/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java b/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java index a3e07a63..7966b61c 100644 --- a/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java +++ b/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java @@ -268,6 +268,37 @@ private WritableMap createDetailsMap(@Nonnull String detailsInterface) { } catch (Exception e) { // Ignore errors } + + // Get the link speed + try { + int linkSpeed = + wifiInfo.getLinkSpeed(); + details.putInt("linkSpeed", linkSpeed); + } catch (Exception e) { + // Ignore errors + } + + // Get the current receive link speed in Mbps + try { + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { + int rxLinkSpeed = + wifiInfo.getRxLinkSpeedMbps(); + details.putInt("rxLinkSpeed", rxLinkSpeed); + } + } catch (Exception e) { + // Ignore errors + } + + // Get the current transmit link speed in Mbps + try { + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { + int txLinkSpeed = + wifiInfo.getTxLinkSpeedMbps(); + details.putInt("txLinkSpeed", txLinkSpeed); + } + } catch (Exception e) { + // Ignore errors + } } } break; diff --git a/src/internal/nativeModule.web.ts b/src/internal/nativeModule.web.ts index 09ac9bef..3eaf0120 100644 --- a/src/internal/nativeModule.web.ts +++ b/src/internal/nativeModule.web.ts @@ -188,6 +188,9 @@ const getCurrentState = ( ipAddress: null, subnet: null, frequency: null, + linkSpeed: null, + rxLinkSpeed: null, + txLinkSpeed: null, }, }; return state; diff --git a/src/internal/types.ts b/src/internal/types.ts index 75bd0c67..61074cce 100644 --- a/src/internal/types.ts +++ b/src/internal/types.ts @@ -80,6 +80,9 @@ export type NetInfoWifiState = NetInfoConnectedState< ipAddress: string | null; subnet: string | null; frequency: number | null; + linkSpeed: number | null; + rxLinkSpeed: number | null; + txLinkSpeed: number | null; } >; export type NetInfoBluetoothState = NetInfoConnectedState<