@hoanggbao00/expo-network-traffic 0.1.0 → 0.1.1
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/README.md +111 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,35 +1,131 @@
|
|
|
1
1
|
# @hoanggbao00/expo-network-traffic
|
|
2
2
|
|
|
3
|
-
A lightweight, real-time network traffic monitor for React Native & Expo, built with the modern Expo Modules API.
|
|
3
|
+
A lightweight, real-time network traffic monitor for React Native & Expo, built with the modern Expo Modules API.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> [!IMPORTANT]
|
|
6
|
+
> Currently supports **Android only**. iOS support is not planned due OS Limitation.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
- [Documentation for the main branch](https://docs.expo.dev/versions/unversioned/sdk/network-traffic/)
|
|
8
|
+
## Features
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
- 🚀 Built with Expo Modules API (Swift/Kotlin)
|
|
11
|
+
- 📊 Real-time download and upload speed tracking
|
|
12
|
+
- 📈 Total data usage (Rx/Tx bytes)
|
|
13
|
+
- 🎣 Easy-to-use React Hook
|
|
14
|
+
- 📏 Automatic formatting (B/s, KB/s, MB/s, etc.)
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
## Installation
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
### 1. Install the package
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
Choose your preferred package manager:
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
```bash
|
|
23
|
+
# Using bun
|
|
24
|
+
bun add @hoanggbao00/expo-network-traffic
|
|
19
25
|
|
|
26
|
+
# Using npm
|
|
27
|
+
npm install @hoanggbao00/expo-network-traffic
|
|
28
|
+
|
|
29
|
+
# Using yarn
|
|
30
|
+
yarn add @hoanggbao00/expo-network-traffic
|
|
31
|
+
|
|
32
|
+
# Using pnpm
|
|
33
|
+
pnpm add @hoanggbao00/expo-network-traffic
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. Prebuild native files
|
|
37
|
+
|
|
38
|
+
Since this is a native module, you need to prebuild your project to generate the necessary native code:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx expo prebuild
|
|
20
42
|
```
|
|
21
|
-
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
The simplest way to use this library is through the `useNetworkTraffic` hook.
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import React from 'react';
|
|
50
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
51
|
+
import { useNetworkTraffic } from '@hoanggbao00/expo-network-traffic';
|
|
52
|
+
|
|
53
|
+
export default function App() {
|
|
54
|
+
const { downStr, upStr, totalDown, totalUp } = useNetworkTraffic({
|
|
55
|
+
interval: 1000, // Update every 1 second
|
|
56
|
+
enabled: true,
|
|
57
|
+
decimals: 2,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<View style={styles.container}>
|
|
62
|
+
<Text style={styles.label}>Download Speed: {downStr}</Text>
|
|
63
|
+
<Text style={styles.label}>Upload Speed: {upStr}</Text>
|
|
64
|
+
<View style={styles.divider} />
|
|
65
|
+
<Text style={styles.info}>Total Downloaded: {(totalDown / 1024 / 1024).toFixed(2)} MB</Text>
|
|
66
|
+
<Text style={styles.info}>Total Uploaded: {(totalUp / 1024 / 1024).toFixed(2)} MB</Text>
|
|
67
|
+
</View>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const styles = StyleSheet.create({
|
|
72
|
+
container: {
|
|
73
|
+
flex: 1,
|
|
74
|
+
backgroundColor: '#fff',
|
|
75
|
+
alignItems: 'center',
|
|
76
|
+
justifyContent: 'center',
|
|
77
|
+
padding: 20,
|
|
78
|
+
},
|
|
79
|
+
label: {
|
|
80
|
+
fontSize: 18,
|
|
81
|
+
fontWeight: 'bold',
|
|
82
|
+
marginVertical: 5,
|
|
83
|
+
},
|
|
84
|
+
info: {
|
|
85
|
+
fontSize: 14,
|
|
86
|
+
color: '#666',
|
|
87
|
+
marginTop: 5,
|
|
88
|
+
},
|
|
89
|
+
divider: {
|
|
90
|
+
height: 1,
|
|
91
|
+
backgroundColor: '#eee',
|
|
92
|
+
width: '100%',
|
|
93
|
+
marginVertical: 15,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
22
96
|
```
|
|
23
97
|
|
|
24
|
-
|
|
98
|
+
## API Reference
|
|
99
|
+
|
|
100
|
+
### `useNetworkTraffic(options)`
|
|
101
|
+
|
|
102
|
+
#### Options
|
|
103
|
+
|
|
104
|
+
| Property | Type | Default | Description |
|
|
105
|
+
| :--- | :--- | :--- | :--- |
|
|
106
|
+
| `interval` | `number` | `3000` | Update interval in milliseconds |
|
|
107
|
+
| `enabled` | `boolean` | `true` | Whether the monitor is active |
|
|
108
|
+
| `decimals` | `number` | `2` | Number of decimal places for formatted strings |
|
|
25
109
|
|
|
110
|
+
#### Returns (`NetworkTrafficResult`)
|
|
26
111
|
|
|
112
|
+
| Property | Type | Description |
|
|
113
|
+
| :--- | :--- | :--- |
|
|
114
|
+
| `downSpeed` | `number` | Current download speed in bytes/sec |
|
|
115
|
+
| `upSpeed` | `number` | Current upload speed in bytes/sec |
|
|
116
|
+
| `totalDown` | `number` | Total bytes received since device boot |
|
|
117
|
+
| `totalUp` | `number` | Total bytes sent since device boot |
|
|
118
|
+
| `downStr` | `string` | Formatted download speed (e.g., "1.2 MB/s") |
|
|
119
|
+
| `upStr` | `string` | Formatted upload speed (e.g., "500 KB/s") |
|
|
27
120
|
|
|
121
|
+
## Bare React Native Projects
|
|
28
122
|
|
|
29
|
-
|
|
123
|
+
If you are using a bare React Native project (not managed by Expo), you must first install the `expo` package to enable Expo Modules support:
|
|
30
124
|
|
|
31
|
-
|
|
125
|
+
1. **Install `expo`**: Follow the [official guide](https://docs.expo.dev/bare/installing-expo-modules/) to install and configure the `expo` package.
|
|
126
|
+
2. **Install this package**: `bun add @hoanggbao00/expo-network-traffic`
|
|
127
|
+
3. **Prebuild**: Run `npx expo prebuild` to configure the native projects.
|
|
32
128
|
|
|
33
|
-
|
|
129
|
+
## License
|
|
34
130
|
|
|
35
|
-
|
|
131
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hoanggbao00/expo-network-traffic",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A lightweight, real-time network traffic monitor for React Native & Expo, built with the modern Expo Modules API. (Android Only for now)",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -59,4 +59,4 @@
|
|
|
59
59
|
"access": "public",
|
|
60
60
|
"registry": "https://registry.npmjs.org/"
|
|
61
61
|
}
|
|
62
|
-
}
|
|
62
|
+
}
|