@capgo/capacitor-network-diagnostics 8.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/CapgoCapacitorNetworkDiagnostics.podspec +17 -0
- package/LICENSE +373 -0
- package/Package.swift +28 -0
- package/README.md +467 -0
- package/android/build.gradle +59 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/app/capgo/networkdiagnostics/NetworkDiagnostics.java +681 -0
- package/android/src/main/java/app/capgo/networkdiagnostics/NetworkDiagnosticsPlugin.java +141 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +961 -0
- package/dist/esm/definitions.d.ts +276 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +24 -0
- package/dist/esm/web.js +388 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +402 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +405 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnostics+Download.swift +71 -0
- package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnostics+PacketLoss.swift +91 -0
- package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnostics+Run.swift +163 -0
- package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnostics+Utils.swift +202 -0
- package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnostics.swift +151 -0
- package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnosticsPlugin.swift +139 -0
- package/ios/Tests/NetworkDiagnosticsPluginTests/NetworkDiagnosticsTests.swift +11 -0
- package/package.json +92 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
package app.capgo.networkdiagnostics;
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSArray;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import com.getcapacitor.Plugin;
|
|
6
|
+
import com.getcapacitor.PluginCall;
|
|
7
|
+
import com.getcapacitor.PluginMethod;
|
|
8
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
9
|
+
import java.util.concurrent.ExecutorService;
|
|
10
|
+
import java.util.concurrent.Executors;
|
|
11
|
+
|
|
12
|
+
@CapacitorPlugin(name = "NetworkDiagnostics")
|
|
13
|
+
public class NetworkDiagnosticsPlugin extends Plugin {
|
|
14
|
+
|
|
15
|
+
private final NetworkDiagnostics implementation = new NetworkDiagnostics();
|
|
16
|
+
private final ExecutorService executor = Executors.newCachedThreadPool();
|
|
17
|
+
|
|
18
|
+
@PluginMethod
|
|
19
|
+
public void getNetworkStatus(PluginCall call) {
|
|
20
|
+
executor.execute(() -> call.resolve(implementation.getNetworkStatus(getContext())));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@PluginMethod
|
|
24
|
+
public void testUrl(PluginCall call) {
|
|
25
|
+
String url = call.getString("url");
|
|
26
|
+
if (url == null || url.isEmpty()) {
|
|
27
|
+
call.reject("URL is required");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
String method = call.getString("method", "HEAD");
|
|
32
|
+
Integer timeoutMs = call.getInt("timeoutMs", 10000);
|
|
33
|
+
Boolean followRedirects = call.getBoolean("followRedirects", true);
|
|
34
|
+
|
|
35
|
+
executor.execute(() ->
|
|
36
|
+
call.resolve(
|
|
37
|
+
implementation.testUrl(url, method, timeoutMs == null ? 10000 : timeoutMs, followRedirects == null || followRedirects)
|
|
38
|
+
)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@PluginMethod
|
|
43
|
+
public void testPort(PluginCall call) {
|
|
44
|
+
String host = call.getString("host");
|
|
45
|
+
Integer port = call.getInt("port");
|
|
46
|
+
if (host == null || host.isEmpty()) {
|
|
47
|
+
call.reject("Host is required");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (port == null || port <= 0 || port > 65535) {
|
|
51
|
+
call.reject("Port must be between 1 and 65535");
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Integer timeoutMs = call.getInt("timeoutMs", 5000);
|
|
56
|
+
executor.execute(() -> call.resolve(implementation.testPort(host, port, timeoutMs == null ? 5000 : timeoutMs)));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@PluginMethod
|
|
60
|
+
public void testWebSocket(PluginCall call) {
|
|
61
|
+
String url = call.getString("url");
|
|
62
|
+
if (url == null || url.isEmpty()) {
|
|
63
|
+
call.reject("URL is required");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Integer timeoutMs = call.getInt("timeoutMs", 10000);
|
|
68
|
+
executor.execute(() -> call.resolve(implementation.testWebSocket(url, timeoutMs == null ? 10000 : timeoutMs)));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@PluginMethod
|
|
72
|
+
public void testDownloadSpeed(PluginCall call) {
|
|
73
|
+
String url = call.getString("url");
|
|
74
|
+
if (url == null || url.isEmpty()) {
|
|
75
|
+
call.reject("URL is required");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Integer maxBytes = call.getInt("maxBytes", 5 * 1024 * 1024);
|
|
80
|
+
Integer timeoutMs = call.getInt("timeoutMs", 30000);
|
|
81
|
+
executor.execute(() ->
|
|
82
|
+
call.resolve(
|
|
83
|
+
implementation.testDownloadSpeed(url, maxBytes == null ? 5 * 1024 * 1024 : maxBytes, timeoutMs == null ? 30000 : timeoutMs)
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@PluginMethod
|
|
89
|
+
public void testPacketLoss(PluginCall call) {
|
|
90
|
+
String mode = call.getString("mode", "");
|
|
91
|
+
String host = call.getString("host", "");
|
|
92
|
+
String url = call.getString("url", "");
|
|
93
|
+
Integer port = call.getInt("port", 0);
|
|
94
|
+
Integer count = call.getInt("count", 10);
|
|
95
|
+
Integer timeoutMs = call.getInt("timeoutMs", 3000);
|
|
96
|
+
Integer intervalMs = call.getInt("intervalMs", 250);
|
|
97
|
+
|
|
98
|
+
if ((host == null || host.isEmpty() || port == null || port <= 0) && (url == null || url.isEmpty())) {
|
|
99
|
+
call.reject("Either host and port, or url is required");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
executor.execute(() ->
|
|
104
|
+
call.resolve(
|
|
105
|
+
implementation.testPacketLoss(
|
|
106
|
+
mode == null ? "" : mode,
|
|
107
|
+
host == null ? "" : host,
|
|
108
|
+
port == null ? 0 : port,
|
|
109
|
+
url == null ? "" : url,
|
|
110
|
+
count == null ? 10 : count,
|
|
111
|
+
timeoutMs == null ? 3000 : timeoutMs,
|
|
112
|
+
intervalMs == null ? 250 : intervalMs
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@PluginMethod
|
|
119
|
+
public void runDiagnostics(PluginCall call) {
|
|
120
|
+
JSArray urls = call.getArray("urls", new JSArray());
|
|
121
|
+
JSArray ports = call.getArray("ports", new JSArray());
|
|
122
|
+
JSArray websockets = call.getArray("websockets", new JSArray());
|
|
123
|
+
JSObject download = call.getObject("download");
|
|
124
|
+
JSObject packetLoss = call.getObject("packetLoss");
|
|
125
|
+
|
|
126
|
+
executor.execute(() -> call.resolve(implementation.runDiagnostics(getContext(), urls, ports, websockets, download, packetLoss)));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@PluginMethod
|
|
130
|
+
public void getPluginVersion(PluginCall call) {
|
|
131
|
+
JSObject ret = new JSObject();
|
|
132
|
+
ret.put("version", implementation.getPluginVersion());
|
|
133
|
+
call.resolve(ret);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@Override
|
|
137
|
+
protected void handleOnDestroy() {
|
|
138
|
+
super.handleOnDestroy();
|
|
139
|
+
executor.shutdownNow();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
File without changes
|