@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.
Files changed (31) hide show
  1. package/CapgoCapacitorNetworkDiagnostics.podspec +17 -0
  2. package/LICENSE +373 -0
  3. package/Package.swift +28 -0
  4. package/README.md +467 -0
  5. package/android/build.gradle +59 -0
  6. package/android/src/main/AndroidManifest.xml +4 -0
  7. package/android/src/main/java/app/capgo/networkdiagnostics/NetworkDiagnostics.java +681 -0
  8. package/android/src/main/java/app/capgo/networkdiagnostics/NetworkDiagnosticsPlugin.java +141 -0
  9. package/android/src/main/res/.gitkeep +0 -0
  10. package/dist/docs.json +961 -0
  11. package/dist/esm/definitions.d.ts +276 -0
  12. package/dist/esm/definitions.js +2 -0
  13. package/dist/esm/definitions.js.map +1 -0
  14. package/dist/esm/index.d.ts +4 -0
  15. package/dist/esm/index.js +7 -0
  16. package/dist/esm/index.js.map +1 -0
  17. package/dist/esm/web.d.ts +24 -0
  18. package/dist/esm/web.js +388 -0
  19. package/dist/esm/web.js.map +1 -0
  20. package/dist/plugin.cjs.js +402 -0
  21. package/dist/plugin.cjs.js.map +1 -0
  22. package/dist/plugin.js +405 -0
  23. package/dist/plugin.js.map +1 -0
  24. package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnostics+Download.swift +71 -0
  25. package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnostics+PacketLoss.swift +91 -0
  26. package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnostics+Run.swift +163 -0
  27. package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnostics+Utils.swift +202 -0
  28. package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnostics.swift +151 -0
  29. package/ios/Sources/NetworkDiagnosticsPlugin/NetworkDiagnosticsPlugin.swift +139 -0
  30. package/ios/Tests/NetworkDiagnosticsPluginTests/NetworkDiagnosticsTests.swift +11 -0
  31. package/package.json +92 -0
@@ -0,0 +1,276 @@
1
+ export type ConnectionType = 'none' | 'wifi' | 'cellular' | 'ethernet' | 'vpn' | 'other' | 'unknown';
2
+ export type UrlTestMethod = 'HEAD' | 'GET';
3
+ export type PacketLossMode = 'tcp' | 'http';
4
+ /**
5
+ * Current native network state.
6
+ */
7
+ export interface NetworkStatusResult {
8
+ /**
9
+ * True when the platform reports an active network path.
10
+ */
11
+ connected: boolean;
12
+ /**
13
+ * Best-effort active transport type.
14
+ */
15
+ connectionType: ConnectionType;
16
+ /**
17
+ * True when the OS marks the network as internet-capable or validated.
18
+ */
19
+ internetReachable: boolean;
20
+ /**
21
+ * True for metered or expensive network paths.
22
+ */
23
+ expensive?: boolean;
24
+ /**
25
+ * True when the OS reports a low-data or constrained network path.
26
+ */
27
+ constrained?: boolean;
28
+ /**
29
+ * True when Android reports captive portal capability.
30
+ */
31
+ captivePortal?: boolean;
32
+ /**
33
+ * Native platform details useful for debugging.
34
+ */
35
+ details?: Record<string, string | number | boolean>;
36
+ }
37
+ /**
38
+ * Options for native HTTP URL reachability checks.
39
+ */
40
+ export interface UrlTestOptions {
41
+ /**
42
+ * HTTP or HTTPS URL to test.
43
+ */
44
+ url: string;
45
+ /**
46
+ * HTTP method. Defaults to `HEAD`.
47
+ */
48
+ method?: UrlTestMethod;
49
+ /**
50
+ * Request timeout in milliseconds. Defaults to `10000`.
51
+ */
52
+ timeoutMs?: number;
53
+ /**
54
+ * Follow redirects. Defaults to `true`.
55
+ */
56
+ followRedirects?: boolean;
57
+ }
58
+ /**
59
+ * Native HTTP URL reachability result.
60
+ */
61
+ export interface UrlTestResult {
62
+ url: string;
63
+ method: UrlTestMethod;
64
+ ok: boolean;
65
+ reachable: boolean;
66
+ durationMs: number;
67
+ statusCode?: number;
68
+ finalUrl?: string;
69
+ errorCode?: string;
70
+ errorMessage?: string;
71
+ }
72
+ /**
73
+ * Options for native TCP port checks.
74
+ */
75
+ export interface PortTestOptions {
76
+ /**
77
+ * Hostname or IP address.
78
+ */
79
+ host: string;
80
+ /**
81
+ * TCP port to open.
82
+ */
83
+ port: number;
84
+ /**
85
+ * Socket timeout in milliseconds. Defaults to `5000`.
86
+ */
87
+ timeoutMs?: number;
88
+ }
89
+ /**
90
+ * Native TCP port check result.
91
+ */
92
+ export interface PortTestResult {
93
+ host: string;
94
+ port: number;
95
+ open: boolean;
96
+ durationMs: number;
97
+ errorCode?: string;
98
+ errorMessage?: string;
99
+ }
100
+ /**
101
+ * Options for native WebSocket handshake checks.
102
+ */
103
+ export interface WebSocketTestOptions {
104
+ /**
105
+ * `ws://` or `wss://` URL to test.
106
+ */
107
+ url: string;
108
+ /**
109
+ * Handshake timeout in milliseconds. Defaults to `10000`.
110
+ */
111
+ timeoutMs?: number;
112
+ }
113
+ /**
114
+ * Native WebSocket handshake result.
115
+ */
116
+ export interface WebSocketTestResult {
117
+ url: string;
118
+ open: boolean;
119
+ durationMs: number;
120
+ protocol?: string;
121
+ statusCode?: number;
122
+ errorCode?: string;
123
+ errorMessage?: string;
124
+ }
125
+ /**
126
+ * Options for native download speed measurement.
127
+ */
128
+ export interface DownloadSpeedTestOptions {
129
+ /**
130
+ * HTTP or HTTPS URL returning a downloadable body.
131
+ */
132
+ url: string;
133
+ /**
134
+ * Maximum bytes to read before stopping. Defaults to `5242880` (5 MiB).
135
+ */
136
+ maxBytes?: number;
137
+ /**
138
+ * Request timeout in milliseconds. Defaults to `30000`.
139
+ */
140
+ timeoutMs?: number;
141
+ }
142
+ /**
143
+ * Native download speed measurement result.
144
+ */
145
+ export interface DownloadSpeedTestResult {
146
+ url: string;
147
+ ok: boolean;
148
+ durationMs: number;
149
+ bytesDownloaded: number;
150
+ bytesPerSecond: number;
151
+ mbps: number;
152
+ statusCode?: number;
153
+ errorCode?: string;
154
+ errorMessage?: string;
155
+ }
156
+ /**
157
+ * Options for packet loss measurement.
158
+ *
159
+ * Native apps cannot rely on raw ICMP ping on both iOS and Android, so this
160
+ * method measures application-level loss with repeated TCP connects or HTTP
161
+ * requests.
162
+ */
163
+ export interface PacketLossTestOptions {
164
+ /**
165
+ * Probe mode. Defaults to `tcp` when host/port is provided, otherwise `http`.
166
+ */
167
+ mode?: PacketLossMode;
168
+ /**
169
+ * Hostname or IP address for TCP probes.
170
+ */
171
+ host?: string;
172
+ /**
173
+ * TCP port for TCP probes.
174
+ */
175
+ port?: number;
176
+ /**
177
+ * HTTP or HTTPS URL for HTTP probes.
178
+ */
179
+ url?: string;
180
+ /**
181
+ * Number of probes to send. Defaults to `10`.
182
+ */
183
+ count?: number;
184
+ /**
185
+ * Per-probe timeout in milliseconds. Defaults to `3000`.
186
+ */
187
+ timeoutMs?: number;
188
+ /**
189
+ * Delay between probes in milliseconds. Defaults to `250`.
190
+ */
191
+ intervalMs?: number;
192
+ }
193
+ /**
194
+ * Application-level packet loss result.
195
+ */
196
+ export interface PacketLossTestResult {
197
+ mode: PacketLossMode;
198
+ target: string;
199
+ sent: number;
200
+ received: number;
201
+ lost: number;
202
+ lossPercent: number;
203
+ averageLatencyMs?: number;
204
+ minLatencyMs?: number;
205
+ maxLatencyMs?: number;
206
+ errorCode?: string;
207
+ errorMessage?: string;
208
+ }
209
+ /**
210
+ * Options for a combined native network diagnostic run.
211
+ */
212
+ export interface RunDiagnosticsOptions {
213
+ urls?: UrlTestOptions[];
214
+ ports?: PortTestOptions[];
215
+ websockets?: WebSocketTestOptions[];
216
+ download?: DownloadSpeedTestOptions;
217
+ packetLoss?: PacketLossTestOptions;
218
+ }
219
+ /**
220
+ * Combined native network diagnostic result.
221
+ */
222
+ export interface RunDiagnosticsResult {
223
+ status: NetworkStatusResult;
224
+ urls: UrlTestResult[];
225
+ ports: PortTestResult[];
226
+ websockets: WebSocketTestResult[];
227
+ issues: string[];
228
+ download?: DownloadSpeedTestResult;
229
+ packetLoss?: PacketLossTestResult;
230
+ }
231
+ /**
232
+ * Plugin version payload.
233
+ */
234
+ export interface PluginVersionResult {
235
+ /**
236
+ * Version identifier returned by the platform implementation.
237
+ */
238
+ version: string;
239
+ }
240
+ /**
241
+ * Native network diagnostics API.
242
+ */
243
+ export interface NetworkDiagnosticsPlugin {
244
+ /**
245
+ * Read the current native connection type and platform network flags.
246
+ */
247
+ getNetworkStatus(): Promise<NetworkStatusResult>;
248
+ /**
249
+ * Test whether an HTTP or HTTPS URL can be reached from native networking.
250
+ */
251
+ testUrl(options: UrlTestOptions): Promise<UrlTestResult>;
252
+ /**
253
+ * Test whether a TCP host:port can be opened from native networking.
254
+ */
255
+ testPort(options: PortTestOptions): Promise<PortTestResult>;
256
+ /**
257
+ * Test whether a WebSocket URL can complete its native handshake.
258
+ */
259
+ testWebSocket(options: WebSocketTestOptions): Promise<WebSocketTestResult>;
260
+ /**
261
+ * Measure download throughput from a native HTTP request.
262
+ */
263
+ testDownloadSpeed(options: DownloadSpeedTestOptions): Promise<DownloadSpeedTestResult>;
264
+ /**
265
+ * Estimate application-level packet loss with repeated TCP or HTTP probes.
266
+ */
267
+ testPacketLoss(options: PacketLossTestOptions): Promise<PacketLossTestResult>;
268
+ /**
269
+ * Run several diagnostics and return a compact issue list.
270
+ */
271
+ runDiagnostics(options?: RunDiagnosticsOptions): Promise<RunDiagnosticsResult>;
272
+ /**
273
+ * Returns the platform implementation version marker.
274
+ */
275
+ getPluginVersion(): Promise<PluginVersionResult>;
276
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export type ConnectionType = 'none' | 'wifi' | 'cellular' | 'ethernet' | 'vpn' | 'other' | 'unknown';\n\nexport type UrlTestMethod = 'HEAD' | 'GET';\n\nexport type PacketLossMode = 'tcp' | 'http';\n\n/**\n * Current native network state.\n */\nexport interface NetworkStatusResult {\n /**\n * True when the platform reports an active network path.\n */\n connected: boolean;\n\n /**\n * Best-effort active transport type.\n */\n connectionType: ConnectionType;\n\n /**\n * True when the OS marks the network as internet-capable or validated.\n */\n internetReachable: boolean;\n\n /**\n * True for metered or expensive network paths.\n */\n expensive?: boolean;\n\n /**\n * True when the OS reports a low-data or constrained network path.\n */\n constrained?: boolean;\n\n /**\n * True when Android reports captive portal capability.\n */\n captivePortal?: boolean;\n\n /**\n * Native platform details useful for debugging.\n */\n details?: Record<string, string | number | boolean>;\n}\n\n/**\n * Options for native HTTP URL reachability checks.\n */\nexport interface UrlTestOptions {\n /**\n * HTTP or HTTPS URL to test.\n */\n url: string;\n\n /**\n * HTTP method. Defaults to `HEAD`.\n */\n method?: UrlTestMethod;\n\n /**\n * Request timeout in milliseconds. Defaults to `10000`.\n */\n timeoutMs?: number;\n\n /**\n * Follow redirects. Defaults to `true`.\n */\n followRedirects?: boolean;\n}\n\n/**\n * Native HTTP URL reachability result.\n */\nexport interface UrlTestResult {\n url: string;\n method: UrlTestMethod;\n ok: boolean;\n reachable: boolean;\n durationMs: number;\n statusCode?: number;\n finalUrl?: string;\n errorCode?: string;\n errorMessage?: string;\n}\n\n/**\n * Options for native TCP port checks.\n */\nexport interface PortTestOptions {\n /**\n * Hostname or IP address.\n */\n host: string;\n\n /**\n * TCP port to open.\n */\n port: number;\n\n /**\n * Socket timeout in milliseconds. Defaults to `5000`.\n */\n timeoutMs?: number;\n}\n\n/**\n * Native TCP port check result.\n */\nexport interface PortTestResult {\n host: string;\n port: number;\n open: boolean;\n durationMs: number;\n errorCode?: string;\n errorMessage?: string;\n}\n\n/**\n * Options for native WebSocket handshake checks.\n */\nexport interface WebSocketTestOptions {\n /**\n * `ws://` or `wss://` URL to test.\n */\n url: string;\n\n /**\n * Handshake timeout in milliseconds. Defaults to `10000`.\n */\n timeoutMs?: number;\n}\n\n/**\n * Native WebSocket handshake result.\n */\nexport interface WebSocketTestResult {\n url: string;\n open: boolean;\n durationMs: number;\n protocol?: string;\n statusCode?: number;\n errorCode?: string;\n errorMessage?: string;\n}\n\n/**\n * Options for native download speed measurement.\n */\nexport interface DownloadSpeedTestOptions {\n /**\n * HTTP or HTTPS URL returning a downloadable body.\n */\n url: string;\n\n /**\n * Maximum bytes to read before stopping. Defaults to `5242880` (5 MiB).\n */\n maxBytes?: number;\n\n /**\n * Request timeout in milliseconds. Defaults to `30000`.\n */\n timeoutMs?: number;\n}\n\n/**\n * Native download speed measurement result.\n */\nexport interface DownloadSpeedTestResult {\n url: string;\n ok: boolean;\n durationMs: number;\n bytesDownloaded: number;\n bytesPerSecond: number;\n mbps: number;\n statusCode?: number;\n errorCode?: string;\n errorMessage?: string;\n}\n\n/**\n * Options for packet loss measurement.\n *\n * Native apps cannot rely on raw ICMP ping on both iOS and Android, so this\n * method measures application-level loss with repeated TCP connects or HTTP\n * requests.\n */\nexport interface PacketLossTestOptions {\n /**\n * Probe mode. Defaults to `tcp` when host/port is provided, otherwise `http`.\n */\n mode?: PacketLossMode;\n\n /**\n * Hostname or IP address for TCP probes.\n */\n host?: string;\n\n /**\n * TCP port for TCP probes.\n */\n port?: number;\n\n /**\n * HTTP or HTTPS URL for HTTP probes.\n */\n url?: string;\n\n /**\n * Number of probes to send. Defaults to `10`.\n */\n count?: number;\n\n /**\n * Per-probe timeout in milliseconds. Defaults to `3000`.\n */\n timeoutMs?: number;\n\n /**\n * Delay between probes in milliseconds. Defaults to `250`.\n */\n intervalMs?: number;\n}\n\n/**\n * Application-level packet loss result.\n */\nexport interface PacketLossTestResult {\n mode: PacketLossMode;\n target: string;\n sent: number;\n received: number;\n lost: number;\n lossPercent: number;\n averageLatencyMs?: number;\n minLatencyMs?: number;\n maxLatencyMs?: number;\n errorCode?: string;\n errorMessage?: string;\n}\n\n/**\n * Options for a combined native network diagnostic run.\n */\nexport interface RunDiagnosticsOptions {\n urls?: UrlTestOptions[];\n ports?: PortTestOptions[];\n websockets?: WebSocketTestOptions[];\n download?: DownloadSpeedTestOptions;\n packetLoss?: PacketLossTestOptions;\n}\n\n/**\n * Combined native network diagnostic result.\n */\nexport interface RunDiagnosticsResult {\n status: NetworkStatusResult;\n urls: UrlTestResult[];\n ports: PortTestResult[];\n websockets: WebSocketTestResult[];\n issues: string[];\n download?: DownloadSpeedTestResult;\n packetLoss?: PacketLossTestResult;\n}\n\n/**\n * Plugin version payload.\n */\nexport interface PluginVersionResult {\n /**\n * Version identifier returned by the platform implementation.\n */\n version: string;\n}\n\n/**\n * Native network diagnostics API.\n */\nexport interface NetworkDiagnosticsPlugin {\n /**\n * Read the current native connection type and platform network flags.\n */\n getNetworkStatus(): Promise<NetworkStatusResult>;\n\n /**\n * Test whether an HTTP or HTTPS URL can be reached from native networking.\n */\n testUrl(options: UrlTestOptions): Promise<UrlTestResult>;\n\n /**\n * Test whether a TCP host:port can be opened from native networking.\n */\n testPort(options: PortTestOptions): Promise<PortTestResult>;\n\n /**\n * Test whether a WebSocket URL can complete its native handshake.\n */\n testWebSocket(options: WebSocketTestOptions): Promise<WebSocketTestResult>;\n\n /**\n * Measure download throughput from a native HTTP request.\n */\n testDownloadSpeed(options: DownloadSpeedTestOptions): Promise<DownloadSpeedTestResult>;\n\n /**\n * Estimate application-level packet loss with repeated TCP or HTTP probes.\n */\n testPacketLoss(options: PacketLossTestOptions): Promise<PacketLossTestResult>;\n\n /**\n * Run several diagnostics and return a compact issue list.\n */\n runDiagnostics(options?: RunDiagnosticsOptions): Promise<RunDiagnosticsResult>;\n\n /**\n * Returns the platform implementation version marker.\n */\n getPluginVersion(): Promise<PluginVersionResult>;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { NetworkDiagnosticsPlugin } from './definitions';
2
+ declare const NetworkDiagnostics: NetworkDiagnosticsPlugin;
3
+ export * from './definitions';
4
+ export { NetworkDiagnostics };
@@ -0,0 +1,7 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const NetworkDiagnostics = registerPlugin('NetworkDiagnostics', {
3
+ web: () => import('./web').then((m) => new m.NetworkDiagnosticsWeb()),
4
+ });
5
+ export * from './definitions';
6
+ export { NetworkDiagnostics };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,kBAAkB,GAAG,cAAc,CAA2B,oBAAoB,EAAE;IACxF,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;CACtE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { NetworkDiagnosticsPlugin } from './definitions';\n\nconst NetworkDiagnostics = registerPlugin<NetworkDiagnosticsPlugin>('NetworkDiagnostics', {\n web: () => import('./web').then((m) => new m.NetworkDiagnosticsWeb()),\n});\n\nexport * from './definitions';\nexport { NetworkDiagnostics };\n"]}
@@ -0,0 +1,24 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { DownloadSpeedTestOptions, DownloadSpeedTestResult, NetworkDiagnosticsPlugin, NetworkStatusResult, PacketLossTestOptions, PacketLossTestResult, PluginVersionResult, PortTestOptions, PortTestResult, RunDiagnosticsOptions, RunDiagnosticsResult, UrlTestOptions, UrlTestResult, WebSocketTestOptions, WebSocketTestResult } from './definitions';
3
+ export declare class NetworkDiagnosticsWeb extends WebPlugin implements NetworkDiagnosticsPlugin {
4
+ getNetworkStatus(): Promise<NetworkStatusResult>;
5
+ testUrl(options: UrlTestOptions): Promise<UrlTestResult>;
6
+ testPort(options: PortTestOptions): Promise<PortTestResult>;
7
+ testWebSocket(options: WebSocketTestOptions): Promise<WebSocketTestResult>;
8
+ testDownloadSpeed(options: DownloadSpeedTestOptions): Promise<DownloadSpeedTestResult>;
9
+ testPacketLoss(options: PacketLossTestOptions): Promise<PacketLossTestResult>;
10
+ runDiagnostics(options?: RunDiagnosticsOptions): Promise<RunDiagnosticsResult>;
11
+ getPluginVersion(): Promise<PluginVersionResult>;
12
+ private buildIssues;
13
+ private elapsed;
14
+ private errorCode;
15
+ private errorMessage;
16
+ private mapConnectionType;
17
+ private normalizeMethod;
18
+ private packetLossMode;
19
+ private packetLossResult;
20
+ private packetLossTarget;
21
+ private positiveNumber;
22
+ private sleep;
23
+ private timeout;
24
+ }