Download src/utils/networkMonitor.ts from bisheng13/nofx13: direct link, hf CLI and curl.
- Browser
- Download file 746 Bytes
-
https://huggingface.co/spaces/bisheng13/nofx13/resolve/main/src/utils/networkMonitor.ts
- Command line
-
hf download hf://spaces/bisheng13/nofx13/src/utils/networkMonitor.ts
-
curl -L -o networkMonitor.ts https://huggingface.co/spaces/bisheng13/nofx13/resolve/main/src/utils/networkMonitor.ts
746 Bytes
| export class NetworkMonitor { | |
| static async checkNetworkQuality(): Promise<number> { | |
| // 简单的网络质量检测 | |
| const startTime = performance.now() | |
| try { | |
| const response = await fetch('/api/health-check', { | |
| method: 'HEAD', | |
| cache: 'no-cache' | |
| }) | |
| const endTime = performance.now() | |
| return endTime - startTime | |
| } catch (error) { | |
| return -1 | |
| } | |
| } | |
| static getNetworkInfo() { | |
| const connection = (navigator as any).connection | |
| return connection ? { | |
| effectiveType: connection.effectiveType, | |
| downlink: connection.downlink, | |
| rtt: connection.rtt, | |
| saveData: connection.saveData | |
| } : null | |
| } | |
| static isOnline(): boolean { | |
| return navigator.onLine | |
| } | |
| } |