community-cordova-plugin-wifi 1.0.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/.idea/community-cordova-plugin-cpu.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +171 -0
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/RELEASENOTES.md +4 -0
- package/package.json +18 -0
- package/plugin.xml +67 -0
- package/src/android/IpInfoUtils.java +154 -0
- package/src/android/PingTask.java +56 -0
- package/src/android/WifiDetailsUtils.java +78 -0
- package/src/android/WifiPlugin.java +236 -0
- package/src/android/WifiUtils.java +268 -0
- package/src/ios/WifiPlugin.h +21 -0
- package/src/ios/WifiPlugin.m +345 -0
- package/types/index.d.ts +98 -0
- package/www/plugin.js +101 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
7
|
+
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
+
</content>
|
|
9
|
+
<orderEntry type="inheritedJdk" />
|
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
+
</component>
|
|
12
|
+
</module>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/community-cordova-plugin-cpu.iml" filepath="$PROJECT_DIR$/.idea/community-cordova-plugin-cpu.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
package/.idea/vcs.xml
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="AutoImportSettings">
|
|
4
|
+
<option name="autoReloadType" value="SELECTIVE" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="ChangeListManager">
|
|
7
|
+
<list default="true" id="5a269414-5baa-4c38-b2f3-50c21d305b88" name="Changes" comment="update plugin">
|
|
8
|
+
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
|
9
|
+
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
|
10
|
+
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
|
|
11
|
+
<change beforePath="$PROJECT_DIR$/src/android/CpuPlugin.java" beforeDir="false" />
|
|
12
|
+
<change beforePath="$PROJECT_DIR$/src/android/IpInfoUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/android/IpInfoUtils.java" afterDir="false" />
|
|
13
|
+
<change beforePath="$PROJECT_DIR$/src/android/WifiDetailsUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/android/WifiDetailsUtils.java" afterDir="false" />
|
|
14
|
+
<change beforePath="$PROJECT_DIR$/src/android/WifiUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/android/WifiUtils.java" afterDir="false" />
|
|
15
|
+
<change beforePath="$PROJECT_DIR$/src/ios/CpuPlugin.h" beforeDir="false" />
|
|
16
|
+
<change beforePath="$PROJECT_DIR$/src/ios/CpuPlugin.m" beforeDir="false" />
|
|
17
|
+
<change beforePath="$PROJECT_DIR$/types/index.d.ts" beforeDir="false" afterPath="$PROJECT_DIR$/types/index.d.ts" afterDir="false" />
|
|
18
|
+
<change beforePath="$PROJECT_DIR$/www/plugin.js" beforeDir="false" afterPath="$PROJECT_DIR$/www/plugin.js" afterDir="false" />
|
|
19
|
+
</list>
|
|
20
|
+
<option name="SHOW_DIALOG" value="false" />
|
|
21
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
22
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
23
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
24
|
+
</component>
|
|
25
|
+
<component name="Git.Settings">
|
|
26
|
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
27
|
+
</component>
|
|
28
|
+
<component name="GitHubPullRequestSearchHistory">{
|
|
29
|
+
"lastFilter": {
|
|
30
|
+
"state": "OPEN",
|
|
31
|
+
"assignee": "EYALIN"
|
|
32
|
+
}
|
|
33
|
+
}</component>
|
|
34
|
+
<component name="GithubPullRequestsUISettings">
|
|
35
|
+
<option name="selectedUrlAndAccountId">
|
|
36
|
+
<UrlAndAccount>
|
|
37
|
+
<option name="accountId" value="554cb47e-af38-4ebf-8263-4816fa246779" />
|
|
38
|
+
<option name="url" value="https://github.com/EYALIN/community-cordova-plugin-cpu.git" />
|
|
39
|
+
</UrlAndAccount>
|
|
40
|
+
</option>
|
|
41
|
+
</component>
|
|
42
|
+
<component name="MarkdownSettingsMigration">
|
|
43
|
+
<option name="stateVersion" value="1" />
|
|
44
|
+
</component>
|
|
45
|
+
<component name="ProjectColorInfo">{
|
|
46
|
+
"associatedIndex": 1
|
|
47
|
+
}</component>
|
|
48
|
+
<component name="ProjectId" id="2V3XjevBz8TNHSRUbFy8xKWpnmV" />
|
|
49
|
+
<component name="ProjectViewState">
|
|
50
|
+
<option name="autoscrollFromSource" value="true" />
|
|
51
|
+
<option name="hideEmptyMiddlePackages" value="true" />
|
|
52
|
+
<option name="showLibraryContents" value="true" />
|
|
53
|
+
</component>
|
|
54
|
+
<component name="PropertiesComponent">{
|
|
55
|
+
"keyToString": {
|
|
56
|
+
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
|
57
|
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
58
|
+
"WebServerToolWindowFactoryState": "false",
|
|
59
|
+
"git-widget-placeholder": "main",
|
|
60
|
+
"last_opened_file_path": "/Volumes/Development/Git/forked/community-cordova-plugin-wifi/src/android",
|
|
61
|
+
"node.js.detected.package.eslint": "true",
|
|
62
|
+
"node.js.detected.package.tslint": "true",
|
|
63
|
+
"node.js.selected.package.eslint": "(autodetect)",
|
|
64
|
+
"node.js.selected.package.tslint": "(autodetect)",
|
|
65
|
+
"nodejs_package_manager_path": "npm",
|
|
66
|
+
"settings.editor.selected.configurable": "preferences.lookFeel",
|
|
67
|
+
"ts.external.directory.path": "/Applications/WebStorm.app/Contents/plugins/javascript-impl/jsLanguageServicesImpl/external",
|
|
68
|
+
"vue.rearranger.settings.migration": "true"
|
|
69
|
+
}
|
|
70
|
+
}</component>
|
|
71
|
+
<component name="RecentsManager">
|
|
72
|
+
<key name="CopyFile.RECENT_KEYS">
|
|
73
|
+
<recent name="$PROJECT_DIR$/src/android" />
|
|
74
|
+
</key>
|
|
75
|
+
<key name="MoveFile.RECENT_KEYS">
|
|
76
|
+
<recent name="$PROJECT_DIR$/src/ios" />
|
|
77
|
+
<recent name="$PROJECT_DIR$/src" />
|
|
78
|
+
</key>
|
|
79
|
+
</component>
|
|
80
|
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
81
|
+
<component name="TaskManager">
|
|
82
|
+
<task active="true" id="Default" summary="Default task">
|
|
83
|
+
<changelist id="5a269414-5baa-4c38-b2f3-50c21d305b88" name="Changes" comment="" />
|
|
84
|
+
<created>1694065873471</created>
|
|
85
|
+
<option name="number" value="Default" />
|
|
86
|
+
<option name="presentableId" value="Default" />
|
|
87
|
+
<updated>1694065873471</updated>
|
|
88
|
+
<workItem from="1694065874545" duration="2544000" />
|
|
89
|
+
<workItem from="1694096923102" duration="7155000" />
|
|
90
|
+
<workItem from="1694674927377" duration="5790000" />
|
|
91
|
+
<workItem from="1695444377955" duration="2093000" />
|
|
92
|
+
<workItem from="1697977836525" duration="1232000" />
|
|
93
|
+
<workItem from="1700879084997" duration="1517000" />
|
|
94
|
+
<workItem from="1703786483609" duration="991000" />
|
|
95
|
+
<workItem from="1703818528645" duration="3425000" />
|
|
96
|
+
<workItem from="1703822230230" duration="44262000" />
|
|
97
|
+
<workItem from="1708181011949" duration="10604000" />
|
|
98
|
+
<workItem from="1708240272493" duration="19053000" />
|
|
99
|
+
<workItem from="1709102390279" duration="5116000" />
|
|
100
|
+
<workItem from="1709959064513" duration="6440000" />
|
|
101
|
+
</task>
|
|
102
|
+
<task id="LOCAL-00001" summary="update plugin">
|
|
103
|
+
<option name="closed" value="true" />
|
|
104
|
+
<created>1694066156591</created>
|
|
105
|
+
<option name="number" value="00001" />
|
|
106
|
+
<option name="presentableId" value="LOCAL-00001" />
|
|
107
|
+
<option name="project" value="LOCAL" />
|
|
108
|
+
<updated>1694066156591</updated>
|
|
109
|
+
</task>
|
|
110
|
+
<task id="LOCAL-00002" summary="update plugin">
|
|
111
|
+
<option name="closed" value="true" />
|
|
112
|
+
<created>1694067087785</created>
|
|
113
|
+
<option name="number" value="00002" />
|
|
114
|
+
<option name="presentableId" value="LOCAL-00002" />
|
|
115
|
+
<option name="project" value="LOCAL" />
|
|
116
|
+
<updated>1694067087785</updated>
|
|
117
|
+
</task>
|
|
118
|
+
<task id="LOCAL-00003" summary="update plugin">
|
|
119
|
+
<option name="closed" value="true" />
|
|
120
|
+
<created>1695446707323</created>
|
|
121
|
+
<option name="number" value="00003" />
|
|
122
|
+
<option name="presentableId" value="LOCAL-00003" />
|
|
123
|
+
<option name="project" value="LOCAL" />
|
|
124
|
+
<updated>1695446707323</updated>
|
|
125
|
+
</task>
|
|
126
|
+
<task id="LOCAL-00004" summary="update plugin">
|
|
127
|
+
<option name="closed" value="true" />
|
|
128
|
+
<created>1704549829774</created>
|
|
129
|
+
<option name="number" value="00004" />
|
|
130
|
+
<option name="presentableId" value="LOCAL-00004" />
|
|
131
|
+
<option name="project" value="LOCAL" />
|
|
132
|
+
<updated>1704549829774</updated>
|
|
133
|
+
</task>
|
|
134
|
+
<task id="LOCAL-00005" summary="update plugin">
|
|
135
|
+
<option name="closed" value="true" />
|
|
136
|
+
<created>1708805859165</created>
|
|
137
|
+
<option name="number" value="00005" />
|
|
138
|
+
<option name="presentableId" value="LOCAL-00005" />
|
|
139
|
+
<option name="project" value="LOCAL" />
|
|
140
|
+
<updated>1708805859165</updated>
|
|
141
|
+
</task>
|
|
142
|
+
<task id="LOCAL-00006" summary="update plugin">
|
|
143
|
+
<option name="closed" value="true" />
|
|
144
|
+
<created>1709190191610</created>
|
|
145
|
+
<option name="number" value="00006" />
|
|
146
|
+
<option name="presentableId" value="LOCAL-00006" />
|
|
147
|
+
<option name="project" value="LOCAL" />
|
|
148
|
+
<updated>1709190191610</updated>
|
|
149
|
+
</task>
|
|
150
|
+
<option name="localTasksCounter" value="7" />
|
|
151
|
+
<servers />
|
|
152
|
+
</component>
|
|
153
|
+
<component name="TypeScriptGeneratedFilesManager">
|
|
154
|
+
<option name="version" value="3" />
|
|
155
|
+
</component>
|
|
156
|
+
<component name="Vcs.Log.Tabs.Properties">
|
|
157
|
+
<option name="TAB_STATES">
|
|
158
|
+
<map>
|
|
159
|
+
<entry key="MAIN">
|
|
160
|
+
<value>
|
|
161
|
+
<State />
|
|
162
|
+
</value>
|
|
163
|
+
</entry>
|
|
164
|
+
</map>
|
|
165
|
+
</option>
|
|
166
|
+
</component>
|
|
167
|
+
<component name="VcsManagerConfiguration">
|
|
168
|
+
<MESSAGE value="update plugin" />
|
|
169
|
+
<option name="LAST_COMMIT_MESSAGE" value="update plugin" />
|
|
170
|
+
</component>
|
|
171
|
+
</project>
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 EYALIN
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Community Cordova Plugin WiFi
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
The Community Cordova Plugin WiFi offers extensive WiFi management functionalities for Cordova applications on Android and iOS platforms. While Android devices benefit from a wide range of WiFi management capabilities, iOS support focuses on network information retrieval due to platform restrictions.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
I dedicate a considerable amount of my free time to developing and maintaining many cordova plugins for the community ([See the list with all my maintained plugins][community_plugins]).
|
|
8
|
+
To help ensure this plugin is kept updated,
|
|
9
|
+
new features are added and bugfixes are implemented quickly,
|
|
10
|
+
please donate a couple of dollars (or a little more if you can stretch) as this will help me to afford to dedicate time to its maintenance.
|
|
11
|
+
Please consider donating if you're using this plugin in an app that makes you money,
|
|
12
|
+
or if you're asking for new features or priority bug fixes. Thank you!
|
|
13
|
+
|
|
14
|
+
[](https://github.com/sponsors/eyalin)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- Scan for available WiFi networks (Android)
|
|
20
|
+
- Connect to or disconnect from a WiFi network (Android)
|
|
21
|
+
- Check WiFi status and toggle WiFi (Android)
|
|
22
|
+
- Retrieve current network information
|
|
23
|
+
- Check internet connectivity
|
|
24
|
+
- Ping network addresses (Android)
|
|
25
|
+
- Obtain WiFi signal strength and other network details
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
cordova plugin add community-cordova-plugin-wifi
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## API Reference and Examples
|
|
34
|
+
|
|
35
|
+
### isConnectedToInternet
|
|
36
|
+
|
|
37
|
+
**Platform Support:** Android, iOS
|
|
38
|
+
|
|
39
|
+
Checks if there is an active internet connection.
|
|
40
|
+
|
|
41
|
+
#### Example
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
WifiPlugin.isConnectedToInternet().then(isConnected => {
|
|
45
|
+
console.log("Internet connectivity status:", isConnected);
|
|
46
|
+
}).catch(error => {
|
|
47
|
+
console.error("Error:", error);
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Response:**
|
|
52
|
+
|
|
53
|
+
- `isConnected` (boolean): True if the device is connected to the internet.
|
|
54
|
+
|
|
55
|
+
### getWifiList (Android Only)
|
|
56
|
+
|
|
57
|
+
Scans for available WiFi networks.
|
|
58
|
+
|
|
59
|
+
**Platform Support:** Android
|
|
60
|
+
|
|
61
|
+
#### Example
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
WifiPlugin.getWifiList().then(wifiList => {
|
|
65
|
+
console.log("WiFi networks:", wifiList);
|
|
66
|
+
}).catch(error => {
|
|
67
|
+
console.error("Error:", error);
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Response Fields:**
|
|
72
|
+
|
|
73
|
+
Each object in the `wifiList` array contains:
|
|
74
|
+
- `SSID` (string): Network name.
|
|
75
|
+
- `BSSID` (string): Access point MAC address.
|
|
76
|
+
- `capabilities` (string): Supported protocols and authentication methods.
|
|
77
|
+
- `frequency` (number): Channel frequency in MHz.
|
|
78
|
+
- `level` (number): Signal strength in dBm.
|
|
79
|
+
- `security` (string): Security protocols in use.
|
|
80
|
+
|
|
81
|
+
### getAllWifiDetails
|
|
82
|
+
|
|
83
|
+
Retrieves comprehensive WiFi network details.
|
|
84
|
+
|
|
85
|
+
**Platform Support:** Android, iOS (Limited details on iOS)
|
|
86
|
+
|
|
87
|
+
#### Example
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
WifiPlugin.getAllWifiDetails().then(details => {
|
|
91
|
+
console.log("WiFi Details:", details);
|
|
92
|
+
}).catch(error => {
|
|
93
|
+
console.error("Error:", error);
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Response Fields:**
|
|
98
|
+
|
|
99
|
+
- `ssid` (string): Current network SSID.
|
|
100
|
+
- `bssid` (string): Network BSSID.
|
|
101
|
+
- `ip` (string): Device IP address in the network.
|
|
102
|
+
- `mac` (string, Android only): Device MAC address.
|
|
103
|
+
- `signalStrength` (number, Android only): WiFi signal strength.
|
|
104
|
+
- Additional network details may include `networkid`, `linkspeed`, `rssi`, etc., with availability varying between platforms.
|
|
105
|
+
|
|
106
|
+
### isWifiEnabled (Android Only)
|
|
107
|
+
|
|
108
|
+
Checks if WiFi is enabled on the device.
|
|
109
|
+
|
|
110
|
+
**Platform Support:** Android
|
|
111
|
+
|
|
112
|
+
#### Example
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
WifiPlugin.isWifiEnabled().then(isEnabled => {
|
|
116
|
+
console.log("WiFi Enabled:", isEnabled);
|
|
117
|
+
}).catch(error => {
|
|
118
|
+
console.error("Error:", error);
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Response:**
|
|
123
|
+
|
|
124
|
+
- `isEnabled` (boolean): True if WiFi is enabled.
|
|
125
|
+
|
|
126
|
+
### connectToNetwork (Android Only)
|
|
127
|
+
|
|
128
|
+
Connects to a specified WiFi network.
|
|
129
|
+
|
|
130
|
+
**Platform Support:** Android
|
|
131
|
+
|
|
132
|
+
#### Example
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
WifiPlugin.connectToNetwork("SSID", "password").then(() => {
|
|
136
|
+
console.log("Connected successfully.");
|
|
137
|
+
}).catch(error => {
|
|
138
|
+
console.error("Error:", error);
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
No additional response fields.
|
|
143
|
+
|
|
144
|
+
## Platform Support
|
|
145
|
+
|
|
146
|
+
This plugin supports Android and iOS. Note that iOS functionalities are limited to retrieving network information due to platform restrictions.
|
|
147
|
+
|
|
148
|
+
## Permissions
|
|
149
|
+
|
|
150
|
+
Ensure your application requests the necessary permissions. Android requires permissions for accessing WiFi state, location, and changing WiFi connectivity. iOS may require location permissions for accessing network information.
|
|
151
|
+
|
|
152
|
+
## Contributing
|
|
153
|
+
|
|
154
|
+
Contributions are welcome! Feel free to submit pull requests or open issues on the [GitHub repository](https://github.com/EYALIN/community-cordova-plugin-wifi).
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
[community_plugins]: https://github.com/EYALIN?tab=repositories&q=community&type=&language=&sort=
|
package/RELEASENOTES.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "community-cordova-plugin-wifi",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"types": "./types/index.d.ts",
|
|
5
|
+
"readme": "README.md",
|
|
6
|
+
"repository": "EYALIN/community-cordova-plugin-wifi/tree/master",
|
|
7
|
+
"homepage": "https://github.com/EYALIN/community-cordova-plugin-wifi/tree/master",
|
|
8
|
+
"funding": "https://github.com/sponsors/EYALIN",
|
|
9
|
+
"bugs": "https://github.com/EYALIN/community-cordova-plugin-wifi/issues",
|
|
10
|
+
"cordova": {
|
|
11
|
+
"id": "community-cordova-plugin-wifi",
|
|
12
|
+
"platforms": [
|
|
13
|
+
"android",
|
|
14
|
+
"ios"
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"description": "A plugin for full detail for wifi"
|
|
18
|
+
}
|
package/plugin.xml
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
|
|
3
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
4
|
+
id="community-cordova-plugin-wifi"
|
|
5
|
+
version="1.0.0">
|
|
6
|
+
<name>Cordova Plugin RAM</name>
|
|
7
|
+
<description></description>
|
|
8
|
+
<license>MIT</license>
|
|
9
|
+
<keywords></keywords>
|
|
10
|
+
<repo>https://github.com/eyalin/community-cordova-plugin-wifi.git</repo>
|
|
11
|
+
<issue>https://github.com/eyalin/community-cordova-plugin-wifi/issues</issue>
|
|
12
|
+
|
|
13
|
+
<!-- android -->
|
|
14
|
+
<platform name="android">
|
|
15
|
+
<config-file target="AndroidManifest.xml" parent="/*">
|
|
16
|
+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
|
17
|
+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
|
18
|
+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
|
19
|
+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
|
20
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
|
21
|
+
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
|
|
22
|
+
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
|
|
23
|
+
<uses-permission android:name="android.permission.INTERNET"/>
|
|
24
|
+
</config-file>
|
|
25
|
+
<js-module src="www/plugin.js" name="WifiPlugin">
|
|
26
|
+
<runs/>
|
|
27
|
+
|
|
28
|
+
<!-- This is the window variable name you want, like window.WifiPlugin -->
|
|
29
|
+
<clobbers target="WifiPlugin" />
|
|
30
|
+
</js-module>
|
|
31
|
+
<config-file target="res/xml/config.xml" parent="/*">
|
|
32
|
+
<feature name="WifiPlugin">
|
|
33
|
+
<param name="android-package" value="wifiplugin.WifiPlugin" />
|
|
34
|
+
<param name="onload" value="true" />
|
|
35
|
+
</feature>
|
|
36
|
+
</config-file>
|
|
37
|
+
|
|
38
|
+
<source-file src="src/android/WifiPlugin.java" target-dir="src/android" />
|
|
39
|
+
<source-file src="src/android/IpInfoUtils.java" target-dir="src/android" />
|
|
40
|
+
<source-file src="src/android/PingTask.java" target-dir="src/android" />
|
|
41
|
+
<source-file src="src/android/WifiDetailsUtils.java" target-dir="src/android" />
|
|
42
|
+
<source-file src="src/android/WifiUtils.java" target-dir="src/android" />
|
|
43
|
+
</platform>
|
|
44
|
+
|
|
45
|
+
<!-- ios -->
|
|
46
|
+
<platform name="ios">
|
|
47
|
+
<js-module src="www/plugin.js" name="plugin">
|
|
48
|
+
<runs/>
|
|
49
|
+
<clobbers target="WifiPlugin" />
|
|
50
|
+
</js-module>
|
|
51
|
+
<config-file target="config.xml" parent="/*">
|
|
52
|
+
<feature name="WifiPlugin">
|
|
53
|
+
<param name="ios-package" value="WifiPlugin" onload="true" />
|
|
54
|
+
</feature>
|
|
55
|
+
</config-file>
|
|
56
|
+
|
|
57
|
+
<config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
|
|
58
|
+
<string>Your location is used to access WiFi information.</string>
|
|
59
|
+
</config-file>
|
|
60
|
+
<config-file target="*-Info.plist" parent="NSLocationAlwaysAndWhenInUseUsageDescription">
|
|
61
|
+
<string>Your location is used to access WiFi information even when the app is in the background.</string>
|
|
62
|
+
</config-file>
|
|
63
|
+
|
|
64
|
+
<header-file src="src/ios/WifiPlugin.h" />
|
|
65
|
+
<source-file src="src/ios/WifiPlugin.m" />
|
|
66
|
+
</platform>
|
|
67
|
+
</plugin>
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
package wifiplugin;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.location.Address;
|
|
5
|
+
import android.location.Geocoder;
|
|
6
|
+
import android.location.Location;
|
|
7
|
+
import android.location.LocationManager;
|
|
8
|
+
import android.net.ConnectivityManager;
|
|
9
|
+
import android.net.DhcpInfo;
|
|
10
|
+
import android.net.Network;
|
|
11
|
+
import android.net.NetworkInfo;
|
|
12
|
+
import android.net.wifi.WifiInfo;
|
|
13
|
+
import android.net.wifi.WifiManager;
|
|
14
|
+
import android.text.format.Formatter;
|
|
15
|
+
import org.apache.cordova.CallbackContext;
|
|
16
|
+
import org.apache.cordova.CordovaInterface;
|
|
17
|
+
import org.apache.cordova.PluginResult;
|
|
18
|
+
import org.json.JSONArray;
|
|
19
|
+
import org.json.JSONException;
|
|
20
|
+
import org.json.JSONObject;
|
|
21
|
+
|
|
22
|
+
import java.io.IOException;
|
|
23
|
+
import java.util.ArrayList;
|
|
24
|
+
import java.util.List;
|
|
25
|
+
import java.util.Locale;
|
|
26
|
+
import java.util.TimeZone;
|
|
27
|
+
|
|
28
|
+
public class IpInfoUtils {
|
|
29
|
+
private static final String TAG = "CommunityWifiPlugin->IpInfoUtils";
|
|
30
|
+
|
|
31
|
+
public static void getIpInfo(CordovaInterface cordova, CallbackContext callbackContext) {
|
|
32
|
+
cordova.getThreadPool().execute(() -> {
|
|
33
|
+
try {
|
|
34
|
+
ConnectivityManager connectivityManager = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
35
|
+
WifiManager wifiManager = (WifiManager) cordova.getActivity().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
|
36
|
+
LocationManager locationManager = (LocationManager) cordova.getActivity().getSystemService(Context.LOCATION_SERVICE);
|
|
37
|
+
|
|
38
|
+
if (connectivityManager != null && wifiManager != null && locationManager != null) {
|
|
39
|
+
Network[] networks = connectivityManager.getAllNetworks();
|
|
40
|
+
JSONArray ipInfoArray = new JSONArray();
|
|
41
|
+
JSONObject ipInfoObject = new JSONObject();
|
|
42
|
+
initializeIpInfoObject(ipInfoObject);
|
|
43
|
+
|
|
44
|
+
if (networks.length > 0) {
|
|
45
|
+
for (Network network : networks) {
|
|
46
|
+
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(network);
|
|
47
|
+
|
|
48
|
+
if (networkInfo != null && networkInfo.isConnected() && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
|
|
49
|
+
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
50
|
+
DhcpInfo dhcpInfo = wifiManager.getDhcpInfo(); // Get DHCP info for DNS details
|
|
51
|
+
|
|
52
|
+
ipInfoObject.put("type", networkInfo.getTypeName());
|
|
53
|
+
ipInfoObject.put("signal", wifiInfo.getRssi());
|
|
54
|
+
ipInfoObject.put("speed", wifiInfo.getLinkSpeed());
|
|
55
|
+
ipInfoObject.put("ssid", wifiInfo.getSSID());
|
|
56
|
+
ipInfoObject.put("internalip", Formatter.formatIpAddress(wifiInfo.getIpAddress()));
|
|
57
|
+
ipInfoObject.put("macaddress", wifiInfo.getMacAddress());
|
|
58
|
+
ipInfoObject.put("networkid", wifiInfo.getNetworkId());
|
|
59
|
+
ipInfoObject.put("frequency", wifiInfo.getFrequency());
|
|
60
|
+
ipInfoObject.put("bssid", wifiInfo.getBSSID());
|
|
61
|
+
ipInfoObject.put("timezone", TimeZone.getDefault().getID());
|
|
62
|
+
ipInfoObject.put("dns1", Formatter.formatIpAddress(dhcpInfo.dns1)); // Add DNS1
|
|
63
|
+
ipInfoObject.put("dns2", Formatter.formatIpAddress(dhcpInfo.dns2)); // Add DNS2
|
|
64
|
+
fillLocationInfo(ipInfoObject, locationManager, cordova);
|
|
65
|
+
ipInfoArray.put(ipInfoObject);
|
|
66
|
+
ipInfoObject = new JSONObject();
|
|
67
|
+
initializeIpInfoObject(ipInfoObject);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
72
|
+
DhcpInfo dhcpInfo = wifiManager.getDhcpInfo(); // Get DHCP info for DNS details
|
|
73
|
+
ipInfoObject.put("type", "Not Connected");
|
|
74
|
+
ipInfoObject.put("signal", wifiInfo.getRssi());
|
|
75
|
+
ipInfoObject.put("speed", wifiInfo.getLinkSpeed());
|
|
76
|
+
ipInfoObject.put("ssid", wifiInfo.getSSID());
|
|
77
|
+
ipInfoObject.put("internalip", Formatter.formatIpAddress(wifiInfo.getIpAddress()));
|
|
78
|
+
ipInfoObject.put("macaddress", wifiInfo.getMacAddress());
|
|
79
|
+
ipInfoObject.put("networkid", wifiInfo.getNetworkId());
|
|
80
|
+
ipInfoObject.put("frequency", wifiInfo.getFrequency());
|
|
81
|
+
ipInfoObject.put("bssid", wifiInfo.getBSSID());
|
|
82
|
+
ipInfoObject.put("timezone", TimeZone.getDefault().getID());
|
|
83
|
+
ipInfoObject.put("dns1", Formatter.formatIpAddress(dhcpInfo.dns1)); // Add DNS1
|
|
84
|
+
ipInfoObject.put("dns2", Formatter.formatIpAddress(dhcpInfo.dns2)); // Add DNS2
|
|
85
|
+
fillLocationInfo(ipInfoObject, locationManager, cordova);
|
|
86
|
+
ipInfoArray.put(ipInfoObject);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
PluginResult result = new PluginResult(PluginResult.Status.OK, ipInfoArray);
|
|
90
|
+
callbackContext.sendPluginResult(result);
|
|
91
|
+
} else {
|
|
92
|
+
callbackContext.error("Required managers are null");
|
|
93
|
+
}
|
|
94
|
+
} catch (Exception e) {
|
|
95
|
+
callbackContext.error("Error getting IP information: " + e.getMessage());
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private static void initializeIpInfoObject(JSONObject ipInfoObject) {
|
|
101
|
+
try {
|
|
102
|
+
ipInfoObject.put("networkType", "UNKNOWN");
|
|
103
|
+
ipInfoObject.put("signal", -1);
|
|
104
|
+
ipInfoObject.put("speed", "UNKNOWN");
|
|
105
|
+
ipInfoObject.put("ssid", "UNKNOWN");
|
|
106
|
+
ipInfoObject.put("internalip", "UNKNOWN");
|
|
107
|
+
ipInfoObject.put("macaddress", "UNKNOWN");
|
|
108
|
+
ipInfoObject.put("frequency", -1);
|
|
109
|
+
ipInfoObject.put("bssid", "UNKNOWN");
|
|
110
|
+
ipInfoObject.put("dns1", "UNKNOWN");
|
|
111
|
+
ipInfoObject.put("dns2", "UNKNOWN");
|
|
112
|
+
ipInfoObject.put("timezone", "UNKNOWN");
|
|
113
|
+
ipInfoObject.put("latitude", -1);
|
|
114
|
+
ipInfoObject.put("longitude", -1);
|
|
115
|
+
ipInfoObject.put("city", "UNKNOWN");
|
|
116
|
+
ipInfoObject.put("street", "UNKNOWN");
|
|
117
|
+
ipInfoObject.put("country", "UNKNOWN");
|
|
118
|
+
ipInfoObject.put("region", "UNKNOWN");
|
|
119
|
+
ipInfoObject.put("zipcode", -1);
|
|
120
|
+
ipInfoObject.put("state", "UNKNOWN");
|
|
121
|
+
} catch (JSONException e) {
|
|
122
|
+
e.printStackTrace();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private static void fillLocationInfo(JSONObject ipInfoObject, LocationManager locationManager, CordovaInterface cordova) throws IOException, JSONException {
|
|
127
|
+
Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
|
128
|
+
if (location != null) {
|
|
129
|
+
ipInfoObject.put("latitude", location.getLatitude());
|
|
130
|
+
ipInfoObject.put("longitude", location.getLongitude());
|
|
131
|
+
List<Address> addresses = new ArrayList<>();
|
|
132
|
+
if (isNetworkAvailable(cordova.getActivity())) {
|
|
133
|
+
Geocoder geocoder = new Geocoder(cordova.getActivity(), Locale.getDefault());
|
|
134
|
+
addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!addresses.isEmpty()) {
|
|
138
|
+
Address address = addresses.get(0);
|
|
139
|
+
ipInfoObject.put("city", address.getLocality());
|
|
140
|
+
ipInfoObject.put("street", address.getThoroughfare());
|
|
141
|
+
ipInfoObject.put("country", address.getCountryName());
|
|
142
|
+
ipInfoObject.put("region", address.getSubAdminArea());
|
|
143
|
+
ipInfoObject.put("zipcode", address.getPostalCode());
|
|
144
|
+
ipInfoObject.put("state", address.getAdminArea());
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public static boolean isNetworkAvailable(Context context) {
|
|
150
|
+
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
151
|
+
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
|
152
|
+
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
|
|
153
|
+
}
|
|
154
|
+
}
|