Skip to content

Commit

Permalink
feat: add linkSpeed, rxLinkSpeed, txLinkSpeed info to wifi on android (
Browse files Browse the repository at this point in the history
…#605)

* feat: add linkSpeed, rxLinkSpeed, txLinkSpeed info to wifi mode on android. (#604)
* style(lint): commit lint auto-fixes

Co-authored-by: Mike Hardy <github@mikehardy.net>
  • Loading branch information
Wentao Lyu and mikehardy committed Jun 28, 2022
1 parent c18073a commit 8cad8b7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -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.

Expand Down
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/internal/nativeModule.web.ts
Expand Up @@ -188,6 +188,9 @@ const getCurrentState = (
ipAddress: null,
subnet: null,
frequency: null,
linkSpeed: null,
rxLinkSpeed: null,
txLinkSpeed: null,
},
};
return state;
Expand Down
3 changes: 3 additions & 0 deletions src/internal/types.ts
Expand Up @@ -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<
Expand Down

0 comments on commit 8cad8b7

Please sign in to comment.