@capgo/capacitor-wifi 8.1.0 → 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.
|
@@ -44,7 +44,7 @@ import java.util.List;
|
|
|
44
44
|
)
|
|
45
45
|
public class CapacitorWifiPlugin extends Plugin {
|
|
46
46
|
|
|
47
|
-
private final String pluginVersion = "8.1.
|
|
47
|
+
private final String pluginVersion = "8.1.2";
|
|
48
48
|
|
|
49
49
|
private WifiManager wifiManager;
|
|
50
50
|
private ConnectivityManager connectivityManager;
|
|
@@ -238,18 +238,16 @@ public class CapacitorWifiPlugin extends Plugin {
|
|
|
238
238
|
// Bind process to network if autoRouteTraffic is enabled
|
|
239
239
|
if (autoRouteTraffic != null && autoRouteTraffic) {
|
|
240
240
|
try {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
241
|
+
synchronized (boundNetworkLock) {
|
|
242
|
+
// Unbind from previous network if any
|
|
243
|
+
if (boundNetwork != null) {
|
|
244
|
+
connectivityManager.bindProcessToNetwork(null);
|
|
245
|
+
}
|
|
247
246
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
247
|
+
// Bind to the new network
|
|
248
|
+
boolean bound = connectivityManager.bindProcessToNetwork(network);
|
|
249
|
+
if (bound) {
|
|
250
|
+
boundNetwork = network;
|
|
253
251
|
}
|
|
254
252
|
}
|
|
255
253
|
} catch (Exception e) {
|
|
@@ -330,33 +328,31 @@ public class CapacitorWifiPlugin extends Plugin {
|
|
|
330
328
|
|
|
331
329
|
// Bind process to network if autoRouteTraffic is enabled
|
|
332
330
|
if (autoRouteTraffic != null && autoRouteTraffic) {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
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
|
+
}
|
|
343
340
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
341
|
+
Network activeNetwork = connectivityManager.getActiveNetwork();
|
|
342
|
+
if (activeNetwork != null) {
|
|
343
|
+
boolean bound = connectivityManager.bindProcessToNetwork(activeNetwork);
|
|
344
|
+
if (bound) {
|
|
345
|
+
boundNetwork = activeNetwork;
|
|
350
346
|
}
|
|
351
347
|
}
|
|
352
|
-
} catch (Exception e) {
|
|
353
|
-
// Log error but don't fail the connection
|
|
354
|
-
android.util.Log.e("CapacitorWifi", "Failed to bind process to network: " + e.getMessage());
|
|
355
348
|
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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
|
+
);
|
|
360
356
|
}
|
|
361
357
|
|
|
362
358
|
call.resolve();
|
|
@@ -370,7 +366,7 @@ public class CapacitorWifiPlugin extends Plugin {
|
|
|
370
366
|
try {
|
|
371
367
|
// Unbind from network if we were bound
|
|
372
368
|
synchronized (boundNetworkLock) {
|
|
373
|
-
if (boundNetwork != null
|
|
369
|
+
if (boundNetwork != null) {
|
|
374
370
|
connectivityManager.bindProcessToNetwork(null);
|
|
375
371
|
boundNetwork = null;
|
|
376
372
|
android.util.Log.d("CapacitorWifi", "Unbound process from network");
|
|
@@ -432,19 +428,11 @@ public class CapacitorWifiPlugin extends Plugin {
|
|
|
432
428
|
try {
|
|
433
429
|
String ipAddress = null;
|
|
434
430
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
ipAddress = getWifiIpAddress();
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
} else {
|
|
444
|
-
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
445
|
-
if (wifiInfo != null) {
|
|
446
|
-
int ip = wifiInfo.getIpAddress();
|
|
447
|
-
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();
|
|
448
436
|
}
|
|
449
437
|
}
|
|
450
438
|
|
|
@@ -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.1.
|
|
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] = [
|