@capgo/capacitor-wifi 8.0.6 → 8.1.2

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 CHANGED
@@ -92,6 +92,7 @@ connect(options: ConnectOptions) => Promise<void>
92
92
 
93
93
  Connect to a Wi-Fi network.
94
94
  On Android, this creates a temporary connection that doesn't route traffic through the network by default.
95
+ Set autoRouteTraffic to true to bind app traffic to the connected network (useful for local/device-hosted APs).
95
96
  For a persistent connection on Android, use addNetwork() instead.
96
97
  On iOS, this creates a persistent connection.
97
98
 
@@ -323,11 +324,12 @@ Options for adding a network
323
324
 
324
325
  Options for connecting to a network
325
326
 
326
- | Prop | Type | Description | Default | Since |
327
- | ------------------ | -------------------- | --------------------------------------------------------- | ------------------ | ----- |
328
- | **`ssid`** | <code>string</code> | The SSID of the network to connect to | | 7.0.0 |
329
- | **`password`** | <code>string</code> | The password for the network (optional for open networks) | | 7.0.0 |
330
- | **`isHiddenSsid`** | <code>boolean</code> | Whether the network is hidden (Android only) | <code>false</code> | 7.0.0 |
327
+ | Prop | Type | Description | Default | Since |
328
+ | ---------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
329
+ | **`ssid`** | <code>string</code> | The SSID of the network to connect to | | 7.0.0 |
330
+ | **`password`** | <code>string</code> | The password for the network (optional for open networks) | | 7.0.0 |
331
+ | **`isHiddenSsid`** | <code>boolean</code> | Whether the network is hidden (Android only) | <code>false</code> | 7.0.0 |
332
+ | **`autoRouteTraffic`** | <code>boolean</code> | Whether to automatically route app traffic through the connected Wi-Fi network (Android only) When enabled, it binds the app process to the connected network using ConnectivityManager.bindProcessToNetwork() This is useful for connecting to local/device-hosted APs (e.g., ESP32, IoT devices) that don't have internet access. | <code>false</code> | 7.0.0 |
331
333
 
332
334
 
333
335
  #### DisconnectOptions
@@ -44,12 +44,14 @@ import java.util.List;
44
44
  )
45
45
  public class CapacitorWifiPlugin extends Plugin {
46
46
 
47
- private final String pluginVersion = "8.0.6";
47
+ private final String pluginVersion = "8.1.2";
48
48
 
49
49
  private WifiManager wifiManager;
50
50
  private ConnectivityManager connectivityManager;
51
51
  private BroadcastReceiver scanResultsReceiver;
52
52
  private ConnectivityManager.NetworkCallback networkCallback;
53
+ private Network boundNetwork; // Store the network we bound to for unbinding
54
+ private final Object boundNetworkLock = new Object(); // Lock for thread-safe access to boundNetwork
53
55
 
54
56
  @Override
55
57
  public void load() {
@@ -201,6 +203,7 @@ public class CapacitorWifiPlugin extends Plugin {
201
203
 
202
204
  String password = call.getString("password");
203
205
  Boolean isHiddenSsid = call.getBoolean("isHiddenSsid", false);
206
+ Boolean autoRouteTraffic = call.getBoolean("autoRouteTraffic", false);
204
207
 
205
208
  try {
206
209
  WifiNetworkSpecifier.Builder specifierBuilder = new WifiNetworkSpecifier.Builder().setSsid(ssid);
@@ -215,16 +218,44 @@ public class CapacitorWifiPlugin extends Plugin {
215
218
 
216
219
  NetworkSpecifier specifier = specifierBuilder.build();
217
220
 
218
- NetworkRequest request = new NetworkRequest.Builder()
221
+ NetworkRequest.Builder requestBuilder = new NetworkRequest.Builder()
219
222
  .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
220
- .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
221
- .setNetworkSpecifier(specifier)
222
- .build();
223
+ .setNetworkSpecifier(specifier);
224
+
225
+ // Only remove internet capability if autoRouteTraffic is false
226
+ // If autoRouteTraffic is true, we want Android to consider this network valid for routing
227
+ if (autoRouteTraffic == null || !autoRouteTraffic) {
228
+ requestBuilder.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
229
+ }
230
+
231
+ NetworkRequest request = requestBuilder.build();
223
232
 
224
233
  networkCallback = new ConnectivityManager.NetworkCallback() {
225
234
  @Override
226
235
  public void onAvailable(@NonNull Network network) {
227
236
  super.onAvailable(network);
237
+
238
+ // Bind process to network if autoRouteTraffic is enabled
239
+ if (autoRouteTraffic != null && autoRouteTraffic) {
240
+ try {
241
+ synchronized (boundNetworkLock) {
242
+ // Unbind from previous network if any
243
+ if (boundNetwork != null) {
244
+ connectivityManager.bindProcessToNetwork(null);
245
+ }
246
+
247
+ // Bind to the new network
248
+ boolean bound = connectivityManager.bindProcessToNetwork(network);
249
+ if (bound) {
250
+ boundNetwork = network;
251
+ }
252
+ }
253
+ } catch (Exception e) {
254
+ // Log error but don't fail the connection
255
+ android.util.Log.e("CapacitorWifi", "Failed to bind process to network: " + e.getMessage());
256
+ }
257
+ }
258
+
228
259
  call.resolve();
229
260
  }
230
261
 
@@ -255,6 +286,7 @@ public class CapacitorWifiPlugin extends Plugin {
255
286
 
256
287
  String password = call.getString("password");
257
288
  Boolean isHiddenSsid = call.getBoolean("isHiddenSsid", false);
289
+ Boolean autoRouteTraffic = call.getBoolean("autoRouteTraffic", false);
258
290
 
259
291
  try {
260
292
  WifiConfiguration wifiConfig = new WifiConfiguration();
@@ -294,6 +326,35 @@ public class CapacitorWifiPlugin extends Plugin {
294
326
  return;
295
327
  }
296
328
 
329
+ // Bind process to network if autoRouteTraffic is enabled
330
+ if (autoRouteTraffic != null && autoRouteTraffic) {
331
+ // Use handler to bind asynchronously after connection is established
332
+ new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(
333
+ () -> {
334
+ try {
335
+ synchronized (boundNetworkLock) {
336
+ // Unbind from previous network if any
337
+ if (boundNetwork != null) {
338
+ connectivityManager.bindProcessToNetwork(null);
339
+ }
340
+
341
+ Network activeNetwork = connectivityManager.getActiveNetwork();
342
+ if (activeNetwork != null) {
343
+ boolean bound = connectivityManager.bindProcessToNetwork(activeNetwork);
344
+ if (bound) {
345
+ boundNetwork = activeNetwork;
346
+ }
347
+ }
348
+ }
349
+ } catch (Exception e) {
350
+ // Log error but don't fail the connection
351
+ android.util.Log.e("CapacitorWifi", "Failed to bind process to network: " + e.getMessage());
352
+ }
353
+ },
354
+ 500
355
+ );
356
+ }
357
+
297
358
  call.resolve();
298
359
  } catch (Exception e) {
299
360
  call.reject("Failed to connect: " + e.getMessage(), e);
@@ -303,6 +364,15 @@ public class CapacitorWifiPlugin extends Plugin {
303
364
  @PluginMethod
304
365
  public void disconnect(PluginCall call) {
305
366
  try {
367
+ // Unbind from network if we were bound
368
+ synchronized (boundNetworkLock) {
369
+ if (boundNetwork != null) {
370
+ connectivityManager.bindProcessToNetwork(null);
371
+ boundNetwork = null;
372
+ android.util.Log.d("CapacitorWifi", "Unbound process from network");
373
+ }
374
+ }
375
+
306
376
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
307
377
  if (networkCallback != null) {
308
378
  connectivityManager.unregisterNetworkCallback(networkCallback);
@@ -358,19 +428,11 @@ public class CapacitorWifiPlugin extends Plugin {
358
428
  try {
359
429
  String ipAddress = null;
360
430
 
361
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
362
- Network network = connectivityManager.getActiveNetwork();
363
- if (network != null) {
364
- NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
365
- if (capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
366
- ipAddress = getWifiIpAddress();
367
- }
368
- }
369
- } else {
370
- WifiInfo wifiInfo = wifiManager.getConnectionInfo();
371
- if (wifiInfo != null) {
372
- int ip = wifiInfo.getIpAddress();
373
- ipAddress = String.format("%d.%d.%d.%d", (ip & 0xff), ((ip >> 8) & 0xff), ((ip >> 16) & 0xff), ((ip >> 24) & 0xff));
431
+ Network network = connectivityManager.getActiveNetwork();
432
+ if (network != null) {
433
+ NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
434
+ if (capabilities != null && capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
435
+ ipAddress = getWifiIpAddress();
374
436
  }
375
437
  }
376
438
 
package/dist/docs.json CHANGED
@@ -79,10 +79,10 @@
79
79
  },
80
80
  {
81
81
  "name": "example",
82
- "text": "```typescript\nawait CapacitorWifi.connect({\n ssid: 'MyNetwork',\n password: 'mypassword'\n});\n```"
82
+ "text": "```typescript\nawait CapacitorWifi.connect({\n ssid: 'MyNetwork',\n password: 'mypassword',\n autoRouteTraffic: true // Android only: route app traffic through this network\n});\n```"
83
83
  }
84
84
  ],
85
- "docs": "Connect to a Wi-Fi network.\nOn Android, this creates a temporary connection that doesn't route traffic through the network by default.\nFor a persistent connection on Android, use addNetwork() instead.\nOn iOS, this creates a persistent connection.",
85
+ "docs": "Connect to a Wi-Fi network.\nOn Android, this creates a temporary connection that doesn't route traffic through the network by default.\nSet autoRouteTraffic to true to bind app traffic to the connected network (useful for local/device-hosted APs).\nFor a persistent connection on Android, use addNetwork() instead.\nOn iOS, this creates a persistent connection.",
86
86
  "complexTypes": [
87
87
  "ConnectOptions"
88
88
  ],
@@ -589,6 +589,22 @@
589
589
  "docs": "Whether the network is hidden (Android only)",
590
590
  "complexTypes": [],
591
591
  "type": "boolean | undefined"
592
+ },
593
+ {
594
+ "name": "autoRouteTraffic",
595
+ "tags": [
596
+ {
597
+ "text": "7.0.0",
598
+ "name": "since"
599
+ },
600
+ {
601
+ "text": "false",
602
+ "name": "default"
603
+ }
604
+ ],
605
+ "docs": "Whether to automatically route app traffic through the connected Wi-Fi network (Android only)\nWhen enabled, it binds the app process to the connected network using ConnectivityManager.bindProcessToNetwork()\nThis is useful for connecting to local/device-hosted APs (e.g., ESP32, IoT devices) that don't have internet access.",
606
+ "complexTypes": [],
607
+ "type": "boolean | undefined"
592
608
  }
593
609
  ]
594
610
  },
@@ -28,6 +28,7 @@ export interface CapacitorWifiPlugin {
28
28
  /**
29
29
  * Connect to a Wi-Fi network.
30
30
  * On Android, this creates a temporary connection that doesn't route traffic through the network by default.
31
+ * Set autoRouteTraffic to true to bind app traffic to the connected network (useful for local/device-hosted APs).
31
32
  * For a persistent connection on Android, use addNetwork() instead.
32
33
  * On iOS, this creates a persistent connection.
33
34
  *
@@ -39,7 +40,8 @@ export interface CapacitorWifiPlugin {
39
40
  * ```typescript
40
41
  * await CapacitorWifi.connect({
41
42
  * ssid: 'MyNetwork',
42
- * password: 'mypassword'
43
+ * password: 'mypassword',
44
+ * autoRouteTraffic: true // Android only: route app traffic through this network
43
45
  * });
44
46
  * ```
45
47
  */
@@ -282,6 +284,15 @@ export interface ConnectOptions {
282
284
  * @default false
283
285
  */
284
286
  isHiddenSsid?: boolean;
287
+ /**
288
+ * Whether to automatically route app traffic through the connected Wi-Fi network (Android only)
289
+ * When enabled, it binds the app process to the connected network using ConnectivityManager.bindProcessToNetwork()
290
+ * This is useful for connecting to local/device-hosted APs (e.g., ESP32, IoT devices) that don't have internet access.
291
+ *
292
+ * @since 7.0.0
293
+ * @default false
294
+ */
295
+ autoRouteTraffic?: boolean;
285
296
  }
286
297
  /**
287
298
  * Options for disconnecting from a network
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAocA;;;;GAIG;AACH,MAAM,CAAN,IAAY,mBA6EX;AA7ED,WAAY,mBAAmB;IAC7B;;;;OAIG;IACH,6DAAQ,CAAA;IAER;;;;OAIG;IACH,2DAAO,CAAA;IAEP;;;;OAIG;IACH,qEAAY,CAAA;IAEZ;;;;OAIG;IACH,2DAAO,CAAA;IAEP;;;;OAIG;IACH,2DAAO,CAAA;IAEP;;;;OAIG;IACH,mFAAmB,CAAA;IAEnB;;;;OAIG;IACH,mGAA2B,CAAA;IAE3B;;;;OAIG;IACH,uEAAa,CAAA;IAEb;;;;OAIG;IACH,2DAAO,CAAA;IAEP;;;;OAIG;IACH,qEAAY,CAAA;IAEZ;;;;OAIG;IACH,wEAAc,CAAA;AAChB,CAAC,EA7EW,mBAAmB,KAAnB,mBAAmB,QA6E9B","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * WiFi plugin for managing device WiFi connectivity\n *\n * @since 7.0.0\n */\nexport interface CapacitorWifiPlugin {\n /**\n * Show a system dialog to add a Wi-Fi network to the device.\n * On Android SDK 30+, this opens the system Wi-Fi settings with the network pre-filled.\n * On iOS, this connects to the network directly.\n *\n * @param options - Network configuration options\n * @returns Promise that resolves when the network is added\n * @throws Error if adding the network fails\n * @since 7.0.0\n * @example\n * ```typescript\n * await CapacitorWifi.addNetwork({\n * ssid: 'MyNetwork',\n * password: 'mypassword',\n * isHiddenSsid: false,\n * securityType: NetworkSecurityType.WPA2_PSK\n * });\n * ```\n */\n addNetwork(options: AddNetworkOptions): Promise<void>;\n\n /**\n * Connect to a Wi-Fi network.\n * On Android, this creates a temporary connection that doesn't route traffic through the network by default.\n * For a persistent connection on Android, use addNetwork() instead.\n * On iOS, this creates a persistent connection.\n *\n * @param options - Connection options\n * @returns Promise that resolves when connected\n * @throws Error if connection fails\n * @since 7.0.0\n * @example\n * ```typescript\n * await CapacitorWifi.connect({\n * ssid: 'MyNetwork',\n * password: 'mypassword'\n * });\n * ```\n */\n connect(options: ConnectOptions): Promise<void>;\n\n /**\n * Disconnect from the current Wi-Fi network.\n * On iOS, only disconnects from networks that were added via this plugin.\n *\n * @param options - Optional disconnect options\n * @returns Promise that resolves when disconnected\n * @throws Error if disconnection fails\n * @since 7.0.0\n * @example\n * ```typescript\n * await CapacitorWifi.disconnect();\n * ```\n */\n disconnect(options?: DisconnectOptions): Promise<void>;\n\n /**\n * Get a list of available Wi-Fi networks from the last scan.\n * Only available on Android.\n *\n * @returns Promise that resolves with the list of networks\n * @throws Error if getting networks fails or on unsupported platform\n * @since 7.0.0\n * @example\n * ```typescript\n * const { networks } = await CapacitorWifi.getAvailableNetworks();\n * networks.forEach(network => {\n * console.log(`SSID: ${network.ssid}, Signal: ${network.rssi} dBm`);\n * });\n * ```\n */\n getAvailableNetworks(): Promise<GetAvailableNetworksResult>;\n\n /**\n * Get the device's current IP address.\n * Available on both Android and iOS.\n *\n * @returns Promise that resolves with the IP address\n * @throws Error if getting IP address fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const { ipAddress } = await CapacitorWifi.getIpAddress();\n * console.log('IP Address:', ipAddress);\n * ```\n */\n getIpAddress(): Promise<GetIpAddressResult>;\n\n /**\n * Get the received signal strength indicator (RSSI) of the current network in dBm.\n * Only available on Android.\n *\n * @returns Promise that resolves with the RSSI value\n * @throws Error if getting RSSI fails or on unsupported platform\n * @since 7.0.0\n * @example\n * ```typescript\n * const { rssi } = await CapacitorWifi.getRssi();\n * console.log('Signal strength:', rssi, 'dBm');\n * ```\n */\n getRssi(): Promise<GetRssiResult>;\n\n /**\n * Get the service set identifier (SSID) of the current network.\n * Available on both Android and iOS.\n *\n * @returns Promise that resolves with the SSID\n * @throws Error if getting SSID fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const { ssid } = await CapacitorWifi.getSsid();\n * console.log('Connected to:', ssid);\n * ```\n */\n getSsid(): Promise<GetSsidResult>;\n\n /**\n * Check if Wi-Fi is enabled on the device.\n * Only available on Android.\n *\n * @returns Promise that resolves with the Wi-Fi enabled status\n * @throws Error if checking status fails or on unsupported platform\n * @since 7.0.0\n * @example\n * ```typescript\n * const { enabled } = await CapacitorWifi.isEnabled();\n * console.log('WiFi is', enabled ? 'enabled' : 'disabled');\n * ```\n */\n isEnabled(): Promise<IsEnabledResult>;\n\n /**\n * Start scanning for Wi-Fi networks.\n * Only available on Android.\n * Results are delivered via the 'networksScanned' event listener.\n * Note: May fail due to system throttling or hardware issues.\n *\n * @returns Promise that resolves when scan starts\n * @throws Error if scan fails or on unsupported platform\n * @since 7.0.0\n * @example\n * ```typescript\n * await CapacitorWifi.addListener('networksScanned', () => {\n * console.log('Scan completed');\n * });\n * await CapacitorWifi.startScan();\n * ```\n */\n startScan(): Promise<void>;\n\n /**\n * Check the current permission status for location access.\n * Location permission is required for Wi-Fi operations on both platforms.\n *\n * @returns Promise that resolves with the permission status\n * @throws Error if checking permissions fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const status = await CapacitorWifi.checkPermissions();\n * console.log('Location permission:', status.location);\n * ```\n */\n checkPermissions(): Promise<PermissionStatus>;\n\n /**\n * Request location permissions from the user.\n * Location permission is required for Wi-Fi operations on both platforms.\n *\n * @param options - Optional permission request options\n * @returns Promise that resolves with the updated permission status\n * @throws Error if requesting permissions fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const status = await CapacitorWifi.requestPermissions();\n * if (status.location === 'granted') {\n * console.log('Permission granted');\n * }\n * ```\n */\n requestPermissions(options?: RequestPermissionsOptions): Promise<PermissionStatus>;\n\n /**\n * Add a listener for the 'networksScanned' event.\n * Only available on Android.\n * This event is fired when Wi-Fi scan results are available.\n *\n * @param eventName - The event name ('networksScanned')\n * @param listenerFunc - The callback function to execute\n * @returns Promise that resolves with a listener handle\n * @since 7.0.0\n * @example\n * ```typescript\n * const listener = await CapacitorWifi.addListener('networksScanned', async () => {\n * const { networks } = await CapacitorWifi.getAvailableNetworks();\n * console.log('Found networks:', networks);\n * });\n * ```\n */\n addListener(eventName: 'networksScanned', listenerFunc: () => void): Promise<PluginListenerHandle>;\n\n /**\n * Remove all listeners for this plugin.\n *\n * @returns Promise that resolves when all listeners are removed\n * @since 7.0.0\n * @example\n * ```typescript\n * await CapacitorWifi.removeAllListeners();\n * ```\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Get the native plugin version.\n *\n * @returns Promise that resolves with the plugin version\n * @throws Error if getting the version fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const { version } = await CapacitorWifi.getPluginVersion();\n * console.log('Plugin version:', version);\n * ```\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n\n/**\n * Options for adding a network\n *\n * @since 7.0.0\n */\nexport interface AddNetworkOptions {\n /**\n * The SSID of the network to add\n *\n * @since 7.0.0\n */\n ssid: string;\n\n /**\n * The password for the network (optional for open networks)\n *\n * @since 7.0.0\n */\n password?: string;\n\n /**\n * Whether the network is hidden (Android only)\n *\n * @since 7.0.0\n * @default false\n */\n isHiddenSsid?: boolean;\n\n /**\n * The security type of the network (Android only)\n *\n * @since 7.0.0\n * @default NetworkSecurityType.WPA2_PSK\n */\n securityType?: NetworkSecurityType;\n}\n\n/**\n * Options for connecting to a network\n *\n * @since 7.0.0\n */\nexport interface ConnectOptions {\n /**\n * The SSID of the network to connect to\n *\n * @since 7.0.0\n */\n ssid: string;\n\n /**\n * The password for the network (optional for open networks)\n *\n * @since 7.0.0\n */\n password?: string;\n\n /**\n * Whether the network is hidden (Android only)\n *\n * @since 7.0.0\n * @default false\n */\n isHiddenSsid?: boolean;\n}\n\n/**\n * Options for disconnecting from a network\n *\n * @since 7.0.0\n */\nexport interface DisconnectOptions {\n /**\n * The SSID of the network to disconnect from (optional)\n *\n * @since 7.0.0\n */\n ssid?: string;\n}\n\n/**\n * Result from getAvailableNetworks()\n *\n * @since 7.0.0\n */\nexport interface GetAvailableNetworksResult {\n /**\n * List of available networks\n *\n * @since 7.0.0\n */\n networks: Network[];\n}\n\n/**\n * Represents a Wi-Fi network\n *\n * @since 7.0.0\n */\nexport interface Network {\n /**\n * The SSID of the network\n *\n * @since 7.0.0\n */\n ssid: string;\n\n /**\n * The signal strength in dBm\n *\n * @since 7.0.0\n */\n rssi: number;\n\n /**\n * The security types supported by this network (Android SDK 33+ only)\n *\n * @since 7.0.0\n */\n securityTypes?: NetworkSecurityType[];\n}\n\n/**\n * Result from getIpAddress()\n *\n * @since 7.0.0\n */\nexport interface GetIpAddressResult {\n /**\n * The device's IP address\n *\n * @since 7.0.0\n */\n ipAddress: string;\n}\n\n/**\n * Result from getRssi()\n *\n * @since 7.0.0\n */\nexport interface GetRssiResult {\n /**\n * The signal strength in dBm\n *\n * @since 7.0.0\n */\n rssi: number;\n}\n\n/**\n * Result from getSsid()\n *\n * @since 7.0.0\n */\nexport interface GetSsidResult {\n /**\n * The SSID of the current network\n *\n * @since 7.0.0\n */\n ssid: string;\n}\n\n/**\n * Result from isEnabled()\n *\n * @since 7.0.0\n */\nexport interface IsEnabledResult {\n /**\n * Whether Wi-Fi is enabled\n *\n * @since 7.0.0\n */\n enabled: boolean;\n}\n\n/**\n * Permission status\n *\n * @since 7.0.0\n */\nexport interface PermissionStatus {\n /**\n * Location permission state\n *\n * @since 7.0.0\n */\n location: PermissionState;\n}\n\n/**\n * Possible permission states\n *\n * @since 7.0.0\n */\nexport type PermissionState = 'granted' | 'denied' | 'prompt';\n\n/**\n * Options for requesting permissions\n *\n * @since 7.0.0\n */\nexport interface RequestPermissionsOptions {\n /**\n * Permissions to request\n *\n * @since 7.0.0\n */\n permissions?: 'location'[];\n}\n\n/**\n * Network security types\n *\n * @since 7.0.0\n */\nexport enum NetworkSecurityType {\n /**\n * Open network with no security\n *\n * @since 7.0.0\n */\n OPEN = 0,\n\n /**\n * WEP security\n *\n * @since 7.0.0\n */\n WEP = 1,\n\n /**\n * WPA/WPA2 Personal (PSK)\n *\n * @since 7.0.0\n */\n WPA2_PSK = 2,\n\n /**\n * WPA/WPA2/WPA3 Enterprise (EAP)\n *\n * @since 7.0.0\n */\n EAP = 3,\n\n /**\n * WPA3 Personal (SAE)\n *\n * @since 7.0.0\n */\n SAE = 4,\n\n /**\n * WPA3 Enterprise\n *\n * @since 7.0.0\n */\n WPA3_ENTERPRISE = 5,\n\n /**\n * WPA3 Enterprise 192-bit mode\n *\n * @since 7.0.0\n */\n WPA3_ENTERPRISE_192_BIT = 6,\n\n /**\n * Passpoint network\n *\n * @since 7.0.0\n */\n PASSPOINT = 7,\n\n /**\n * Enhanced Open (OWE)\n *\n * @since 7.0.0\n */\n OWE = 8,\n\n /**\n * WAPI PSK\n *\n * @since 7.0.0\n */\n WAPI_PSK = 9,\n\n /**\n * WAPI Certificate\n *\n * @since 7.0.0\n */\n WAPI_CERT = 10,\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAgdA;;;;GAIG;AACH,MAAM,CAAN,IAAY,mBA6EX;AA7ED,WAAY,mBAAmB;IAC7B;;;;OAIG;IACH,6DAAQ,CAAA;IAER;;;;OAIG;IACH,2DAAO,CAAA;IAEP;;;;OAIG;IACH,qEAAY,CAAA;IAEZ;;;;OAIG;IACH,2DAAO,CAAA;IAEP;;;;OAIG;IACH,2DAAO,CAAA;IAEP;;;;OAIG;IACH,mFAAmB,CAAA;IAEnB;;;;OAIG;IACH,mGAA2B,CAAA;IAE3B;;;;OAIG;IACH,uEAAa,CAAA;IAEb;;;;OAIG;IACH,2DAAO,CAAA;IAEP;;;;OAIG;IACH,qEAAY,CAAA;IAEZ;;;;OAIG;IACH,wEAAc,CAAA;AAChB,CAAC,EA7EW,mBAAmB,KAAnB,mBAAmB,QA6E9B","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * WiFi plugin for managing device WiFi connectivity\n *\n * @since 7.0.0\n */\nexport interface CapacitorWifiPlugin {\n /**\n * Show a system dialog to add a Wi-Fi network to the device.\n * On Android SDK 30+, this opens the system Wi-Fi settings with the network pre-filled.\n * On iOS, this connects to the network directly.\n *\n * @param options - Network configuration options\n * @returns Promise that resolves when the network is added\n * @throws Error if adding the network fails\n * @since 7.0.0\n * @example\n * ```typescript\n * await CapacitorWifi.addNetwork({\n * ssid: 'MyNetwork',\n * password: 'mypassword',\n * isHiddenSsid: false,\n * securityType: NetworkSecurityType.WPA2_PSK\n * });\n * ```\n */\n addNetwork(options: AddNetworkOptions): Promise<void>;\n\n /**\n * Connect to a Wi-Fi network.\n * On Android, this creates a temporary connection that doesn't route traffic through the network by default.\n * Set autoRouteTraffic to true to bind app traffic to the connected network (useful for local/device-hosted APs).\n * For a persistent connection on Android, use addNetwork() instead.\n * On iOS, this creates a persistent connection.\n *\n * @param options - Connection options\n * @returns Promise that resolves when connected\n * @throws Error if connection fails\n * @since 7.0.0\n * @example\n * ```typescript\n * await CapacitorWifi.connect({\n * ssid: 'MyNetwork',\n * password: 'mypassword',\n * autoRouteTraffic: true // Android only: route app traffic through this network\n * });\n * ```\n */\n connect(options: ConnectOptions): Promise<void>;\n\n /**\n * Disconnect from the current Wi-Fi network.\n * On iOS, only disconnects from networks that were added via this plugin.\n *\n * @param options - Optional disconnect options\n * @returns Promise that resolves when disconnected\n * @throws Error if disconnection fails\n * @since 7.0.0\n * @example\n * ```typescript\n * await CapacitorWifi.disconnect();\n * ```\n */\n disconnect(options?: DisconnectOptions): Promise<void>;\n\n /**\n * Get a list of available Wi-Fi networks from the last scan.\n * Only available on Android.\n *\n * @returns Promise that resolves with the list of networks\n * @throws Error if getting networks fails or on unsupported platform\n * @since 7.0.0\n * @example\n * ```typescript\n * const { networks } = await CapacitorWifi.getAvailableNetworks();\n * networks.forEach(network => {\n * console.log(`SSID: ${network.ssid}, Signal: ${network.rssi} dBm`);\n * });\n * ```\n */\n getAvailableNetworks(): Promise<GetAvailableNetworksResult>;\n\n /**\n * Get the device's current IP address.\n * Available on both Android and iOS.\n *\n * @returns Promise that resolves with the IP address\n * @throws Error if getting IP address fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const { ipAddress } = await CapacitorWifi.getIpAddress();\n * console.log('IP Address:', ipAddress);\n * ```\n */\n getIpAddress(): Promise<GetIpAddressResult>;\n\n /**\n * Get the received signal strength indicator (RSSI) of the current network in dBm.\n * Only available on Android.\n *\n * @returns Promise that resolves with the RSSI value\n * @throws Error if getting RSSI fails or on unsupported platform\n * @since 7.0.0\n * @example\n * ```typescript\n * const { rssi } = await CapacitorWifi.getRssi();\n * console.log('Signal strength:', rssi, 'dBm');\n * ```\n */\n getRssi(): Promise<GetRssiResult>;\n\n /**\n * Get the service set identifier (SSID) of the current network.\n * Available on both Android and iOS.\n *\n * @returns Promise that resolves with the SSID\n * @throws Error if getting SSID fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const { ssid } = await CapacitorWifi.getSsid();\n * console.log('Connected to:', ssid);\n * ```\n */\n getSsid(): Promise<GetSsidResult>;\n\n /**\n * Check if Wi-Fi is enabled on the device.\n * Only available on Android.\n *\n * @returns Promise that resolves with the Wi-Fi enabled status\n * @throws Error if checking status fails or on unsupported platform\n * @since 7.0.0\n * @example\n * ```typescript\n * const { enabled } = await CapacitorWifi.isEnabled();\n * console.log('WiFi is', enabled ? 'enabled' : 'disabled');\n * ```\n */\n isEnabled(): Promise<IsEnabledResult>;\n\n /**\n * Start scanning for Wi-Fi networks.\n * Only available on Android.\n * Results are delivered via the 'networksScanned' event listener.\n * Note: May fail due to system throttling or hardware issues.\n *\n * @returns Promise that resolves when scan starts\n * @throws Error if scan fails or on unsupported platform\n * @since 7.0.0\n * @example\n * ```typescript\n * await CapacitorWifi.addListener('networksScanned', () => {\n * console.log('Scan completed');\n * });\n * await CapacitorWifi.startScan();\n * ```\n */\n startScan(): Promise<void>;\n\n /**\n * Check the current permission status for location access.\n * Location permission is required for Wi-Fi operations on both platforms.\n *\n * @returns Promise that resolves with the permission status\n * @throws Error if checking permissions fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const status = await CapacitorWifi.checkPermissions();\n * console.log('Location permission:', status.location);\n * ```\n */\n checkPermissions(): Promise<PermissionStatus>;\n\n /**\n * Request location permissions from the user.\n * Location permission is required for Wi-Fi operations on both platforms.\n *\n * @param options - Optional permission request options\n * @returns Promise that resolves with the updated permission status\n * @throws Error if requesting permissions fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const status = await CapacitorWifi.requestPermissions();\n * if (status.location === 'granted') {\n * console.log('Permission granted');\n * }\n * ```\n */\n requestPermissions(options?: RequestPermissionsOptions): Promise<PermissionStatus>;\n\n /**\n * Add a listener for the 'networksScanned' event.\n * Only available on Android.\n * This event is fired when Wi-Fi scan results are available.\n *\n * @param eventName - The event name ('networksScanned')\n * @param listenerFunc - The callback function to execute\n * @returns Promise that resolves with a listener handle\n * @since 7.0.0\n * @example\n * ```typescript\n * const listener = await CapacitorWifi.addListener('networksScanned', async () => {\n * const { networks } = await CapacitorWifi.getAvailableNetworks();\n * console.log('Found networks:', networks);\n * });\n * ```\n */\n addListener(eventName: 'networksScanned', listenerFunc: () => void): Promise<PluginListenerHandle>;\n\n /**\n * Remove all listeners for this plugin.\n *\n * @returns Promise that resolves when all listeners are removed\n * @since 7.0.0\n * @example\n * ```typescript\n * await CapacitorWifi.removeAllListeners();\n * ```\n */\n removeAllListeners(): Promise<void>;\n\n /**\n * Get the native plugin version.\n *\n * @returns Promise that resolves with the plugin version\n * @throws Error if getting the version fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const { version } = await CapacitorWifi.getPluginVersion();\n * console.log('Plugin version:', version);\n * ```\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n\n/**\n * Options for adding a network\n *\n * @since 7.0.0\n */\nexport interface AddNetworkOptions {\n /**\n * The SSID of the network to add\n *\n * @since 7.0.0\n */\n ssid: string;\n\n /**\n * The password for the network (optional for open networks)\n *\n * @since 7.0.0\n */\n password?: string;\n\n /**\n * Whether the network is hidden (Android only)\n *\n * @since 7.0.0\n * @default false\n */\n isHiddenSsid?: boolean;\n\n /**\n * The security type of the network (Android only)\n *\n * @since 7.0.0\n * @default NetworkSecurityType.WPA2_PSK\n */\n securityType?: NetworkSecurityType;\n}\n\n/**\n * Options for connecting to a network\n *\n * @since 7.0.0\n */\nexport interface ConnectOptions {\n /**\n * The SSID of the network to connect to\n *\n * @since 7.0.0\n */\n ssid: string;\n\n /**\n * The password for the network (optional for open networks)\n *\n * @since 7.0.0\n */\n password?: string;\n\n /**\n * Whether the network is hidden (Android only)\n *\n * @since 7.0.0\n * @default false\n */\n isHiddenSsid?: boolean;\n\n /**\n * Whether to automatically route app traffic through the connected Wi-Fi network (Android only)\n * When enabled, it binds the app process to the connected network using ConnectivityManager.bindProcessToNetwork()\n * This is useful for connecting to local/device-hosted APs (e.g., ESP32, IoT devices) that don't have internet access.\n *\n * @since 7.0.0\n * @default false\n */\n autoRouteTraffic?: boolean;\n}\n\n/**\n * Options for disconnecting from a network\n *\n * @since 7.0.0\n */\nexport interface DisconnectOptions {\n /**\n * The SSID of the network to disconnect from (optional)\n *\n * @since 7.0.0\n */\n ssid?: string;\n}\n\n/**\n * Result from getAvailableNetworks()\n *\n * @since 7.0.0\n */\nexport interface GetAvailableNetworksResult {\n /**\n * List of available networks\n *\n * @since 7.0.0\n */\n networks: Network[];\n}\n\n/**\n * Represents a Wi-Fi network\n *\n * @since 7.0.0\n */\nexport interface Network {\n /**\n * The SSID of the network\n *\n * @since 7.0.0\n */\n ssid: string;\n\n /**\n * The signal strength in dBm\n *\n * @since 7.0.0\n */\n rssi: number;\n\n /**\n * The security types supported by this network (Android SDK 33+ only)\n *\n * @since 7.0.0\n */\n securityTypes?: NetworkSecurityType[];\n}\n\n/**\n * Result from getIpAddress()\n *\n * @since 7.0.0\n */\nexport interface GetIpAddressResult {\n /**\n * The device's IP address\n *\n * @since 7.0.0\n */\n ipAddress: string;\n}\n\n/**\n * Result from getRssi()\n *\n * @since 7.0.0\n */\nexport interface GetRssiResult {\n /**\n * The signal strength in dBm\n *\n * @since 7.0.0\n */\n rssi: number;\n}\n\n/**\n * Result from getSsid()\n *\n * @since 7.0.0\n */\nexport interface GetSsidResult {\n /**\n * The SSID of the current network\n *\n * @since 7.0.0\n */\n ssid: string;\n}\n\n/**\n * Result from isEnabled()\n *\n * @since 7.0.0\n */\nexport interface IsEnabledResult {\n /**\n * Whether Wi-Fi is enabled\n *\n * @since 7.0.0\n */\n enabled: boolean;\n}\n\n/**\n * Permission status\n *\n * @since 7.0.0\n */\nexport interface PermissionStatus {\n /**\n * Location permission state\n *\n * @since 7.0.0\n */\n location: PermissionState;\n}\n\n/**\n * Possible permission states\n *\n * @since 7.0.0\n */\nexport type PermissionState = 'granted' | 'denied' | 'prompt';\n\n/**\n * Options for requesting permissions\n *\n * @since 7.0.0\n */\nexport interface RequestPermissionsOptions {\n /**\n * Permissions to request\n *\n * @since 7.0.0\n */\n permissions?: 'location'[];\n}\n\n/**\n * Network security types\n *\n * @since 7.0.0\n */\nexport enum NetworkSecurityType {\n /**\n * Open network with no security\n *\n * @since 7.0.0\n */\n OPEN = 0,\n\n /**\n * WEP security\n *\n * @since 7.0.0\n */\n WEP = 1,\n\n /**\n * WPA/WPA2 Personal (PSK)\n *\n * @since 7.0.0\n */\n WPA2_PSK = 2,\n\n /**\n * WPA/WPA2/WPA3 Enterprise (EAP)\n *\n * @since 7.0.0\n */\n EAP = 3,\n\n /**\n * WPA3 Personal (SAE)\n *\n * @since 7.0.0\n */\n SAE = 4,\n\n /**\n * WPA3 Enterprise\n *\n * @since 7.0.0\n */\n WPA3_ENTERPRISE = 5,\n\n /**\n * WPA3 Enterprise 192-bit mode\n *\n * @since 7.0.0\n */\n WPA3_ENTERPRISE_192_BIT = 6,\n\n /**\n * Passpoint network\n *\n * @since 7.0.0\n */\n PASSPOINT = 7,\n\n /**\n * Enhanced Open (OWE)\n *\n * @since 7.0.0\n */\n OWE = 8,\n\n /**\n * WAPI PSK\n *\n * @since 7.0.0\n */\n WAPI_PSK = 9,\n\n /**\n * WAPI Certificate\n *\n * @since 7.0.0\n */\n WAPI_CERT = 10,\n}\n"]}
@@ -6,7 +6,7 @@ import CoreLocation
6
6
 
7
7
  @objc(CapacitorWifiPlugin)
8
8
  public class CapacitorWifiPlugin: CAPPlugin, CAPBridgedPlugin {
9
- private let pluginVersion: String = "8.0.6"
9
+ private let pluginVersion: String = "8.1.2"
10
10
  public let identifier = "CapacitorWifiPlugin"
11
11
  public let jsName = "CapacitorWifi"
12
12
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-wifi",
3
- "version": "8.0.6",
3
+ "version": "8.1.2",
4
4
  "description": "Manage WiFi connectivity for your Capacitor app",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",