@videosdk.live/speedtest
v1.0.0
Published
Component to measure download/upload bandwidth from the browser
Readme
VideoSDK Speedtest
A lightweight, browser-side JavaScript module to measure a client's download and upload bandwidth. It performs HTTP test requests and relies on the PerformanceResourceTiming browser API to extract accurate timing results, independent of JavaScript execution overhead.
Installation
npm install @videosdk.live/speedtestUsage
import { VideoSDK } from '@videosdk.live/speedtest';
const { downloadSpeed, uploadSpeed } = await VideoSDK.getNetworkStats();
console.log(`↓ ${downloadSpeed} Mbps ↑ ${uploadSpeed} Mbps`);Browser-only. The module uses
fetch,navigator.onLine,performance.*and other browser APIs. It is not designed to run in Node.js.
API reference
VideoSDK.getNetworkStats(options?)
Runs a single quick upload + download measurement and resolves with the observed throughput.
const stats = await VideoSDK.getNetworkStats({
timeoutDuration: 30000,
baseUrl: 'api.videosdk.live'
});Options
| Option | Type | Description | Default |
| ------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | :-----------------: |
| timeoutDuration | number | Maximum time to wait for the test, in milliseconds. Falls back to the default when omitted or not an integer. | 60000 |
| baseUrl | string | Host serving the upload/download endpoints. Requests are made to https://{baseUrl}/test-upload-speed and https://{baseUrl}/test-download-speed. | api.videosdk.live |
Returns
Promise<{ downloadSpeed: number, uploadSpeed: number }> — download and upload
bandwidth in megabits per second (Mbps), each rounded to two decimals.
Rejections
The promise rejects with a descriptive string when:
- the device is offline (
navigator.onLineisfalse), - the test engine fails to start or hits a connection error, or
- the measurement does not complete within
timeoutDuration.
try {
const stats = await VideoSDK.getNetworkStats();
} catch (reason) {
console.warn('Speed test failed:', reason);
}