Getting Started
このプラグインのインストール手順とフルマークダウンガイドまでのセットアップの案内をコピーしてください。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-network-diagnostics`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/network-diagnostics/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「インストール」のセクションCapgoのAI-Assisted Setupを使用してプラグインをインストールできます。AIツールにCapgoスキルを追加するには、以下のコマンドを実行してください。
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins次に、以下のプロンプトを使用してください。
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-network-diagnostics` plugin in my project.Manual Setupを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。
npm install @capgo/capacitor-network-diagnosticsnpx cap sync__CAPGO_KEEP_1__
「__CAPGO_KEEP_1__」セクションimport { NetworkDiagnostics } from '@capgo/capacitor-network-diagnostics';完全な診断レポートを実行
「完全な診断レポートを実行」セクションrunDiagnostics ユーザーが制限されたネットワークにいる場合のサポートレポートを収集する最速の方法は、
const report = await NetworkDiagnostics.runDiagnostics({ urls: [{ url: 'https://api.example.com/health', method: 'HEAD' }], ports: [{ host: 'api.example.com', port: 443 }], websockets: [{ url: 'wss://ws.example.com/socket' }], download: { url: 'https://speed.example.com/5mb.bin', maxBytes: 5 * 1024 * 1024, }, packetLoss: { mode: 'tcp', host: 'api.example.com', port: 443, count: 10, },});
console.log(report.status.connectionType);console.log(report.issues);現在のネットワーク状態を確認
「現在のネットワーク状態を確認」セクションconst status = await NetworkDiagnostics.getNetworkStatus();
console.log(status.connected);console.log(status.connectionType);console.log(status.internetReachable);console.log(status.captivePortal);プラットフォームによってフラグは正確に異なります。Androidは有効化されたインターネットとキャプティブポータル状態を報告します。iOSはパス状態、インターフェースタイプ、コストのかかるパス、制限されたパスを報告します。 Network.framework.
テスト API のアクセス可能性
セクション「テスト API のアクセス可能性」const result = await NetworkDiagnostics.testUrl({ url: 'https://api.example.com/health', method: 'HEAD', timeoutMs: 5000, followRedirects: true,});
if (!result.reachable) { console.warn(result.errorCode, result.errorMessage);}実際のヘルスエンドポイントから使用する。ブラウザのみのチェックは、WebView、CORS、プロキシ、またはキャプティブポータルの動作によって隠されるかもしれませんが、このプラグインはネイティブネットワーキングを使用します。
TCP ポートをテストする
セクション「TCP ポートをテストする」const port = await NetworkDiagnostics.testPort({ host: 'api.example.com', port: 443, timeoutMs: 3000,});
console.log(port.open, port.durationMs);Wi-Fi アクセスポイントが標準以外のポート、MQTT、カスタムゲートウェイ、またはプライベートバックエンドをブロックしながらでも通常のブラウジングを許可している場合に便利です。
WebSockets の接続性をテストする
セクション「WebSockets の接続性をテストする」const socket = await NetworkDiagnostics.testWebSocket({ url: 'wss://ws.example.com/socket', timeoutMs: 5000,});
console.log(socket.open, socket.statusCode);プロキシやキャプティブポータルがHTTPS ページを許可している場合でも、WebSockets のアップグレード要求をブロックする場合に使用してください。
__CAPGO_KEEP_0__のダウンロード速度を測定
ダウンロード速度の測定const speed = await NetworkDiagnostics.testDownloadSpeed({ url: 'https://speed.example.com/5mb.bin', maxBytes: 5 * 1024 * 1024, timeoutMs: 30000,});
console.log(speed.mbps);アプリが必要とするネットワークパスを反映するように、独自の静的ファイルエンドポイントを使用してください。
パケットロスの推定
パケットロスの推定const loss = await NetworkDiagnostics.testPacketLoss({ mode: 'tcp', host: 'api.example.com', port: 443, count: 10, timeoutMs: 3000, intervalMs: 250,});
console.log(loss.lossPercent);App StoreおよびPlay Storeアプリでは、App StoreおよびPlay Storeアプリでは、RAW ICMP PINGは移植性が低いため、この方法はTCPまたはHTTPプローブを繰り返してアプリケーションレベルのパケットロスを測定します。
ウェブフォールバック
ウェブフォールバック__CAPGO_KEEP_0__