> ## Documentation Index
> Fetch the complete documentation index at: https://docs.daily.co/llms.txt
> Use this file to discover all available pages before exploring further.

# testPeerToPeerCallQuality()

> Assesses WebRTC connection quality using a local video track before joining a call.

`testPeerToPeerCallQuality(options)`

✓ Prebuilt✓ Custom

Connects to Daily's TURN servers and collects metrics over the test duration to indicate connection quality. Useful for precall checks before a room is joined.

The test runs for 15 seconds by default (up to 30 seconds). The longer it runs, the more accurate the results. For in-depth network stats *during* a call, use [`getNetworkStats()`](https://docs.daily.co/reference/daily-js/instance-methods/get-network-stats).

## Parameters

**videoTrack** `MediaStreamTrack` *required*

A video track used to establish the test connection. You can obtain one from `call.participants().local.tracks.video.persistentTrack` after calling `startCamera()`.

**duration** `number` (default: 15)

How long to run the test in seconds. Maximum: `30`.

## Return value

Returns `Promise<DailyP2PCallQualityTestResults>`.

**result** `'good' | 'warning' | 'bad' | 'aborted' | 'failed'`

Overall connection quality verdict:

* `'good'` — `avgRecvPacketLoss` \< 5%, `avgRoundTripTime` \< 300ms, `avgRecvBitsPerSecond` ≥ 1,100kbps
* `'warning'` — `avgRecvPacketLoss` 5–10%, `avgRoundTripTime` 300–600ms, `avgRecvBitsPerSecond` 700kbps–1,100kbps
* `'bad'` — `avgRecvPacketLoss` ≥ 10%, `avgRoundTripTime` ≥ 600ms, `avgRecvBitsPerSecond` \< 700kbps
* `'failed'` — connection to TURN servers could not be made; `errorMsg` and `error` fields are populated
* `'aborted'` — test stopped before data gathering started

**secondsElapsed** `number`

Seconds over which data was collected.

**data** `DailyP2PCallQualityTestData`

Stats used to determine the result. All averages use an exponential moving average biased toward the most recent data.

* `maxRoundTripTime` (seconds) — maximum [`currentRoundTripTime`](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidatePairStats/currentRoundTripTime)
* `avgRoundTripTime` (seconds) — average `currentRoundTripTime`
* `avgRecvPacketLoss` (percentage) — average inbound packet loss
* `avgAvailableOutgoingBitrate` (bps) — average [`availableOutgoingBitrate`](https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidatePairStats/availableOutgoingBitrate) (not available on Firefox)
* `avgSendBitsPerSecond` (bps) — average outbound bitrate
* `avgRecvBitsPerSecond` (bps) — average inbound bitrate

**errorMsg** `string`

Human-readable error message. Only present when `result === 'failed'`.

**error** `DailyFatalErrorObject`

Structured error object. Only present when `result === 'failed'` and error details are available.

## Example

```javascript theme={null}
await call.startCamera();
const videoTrack = call.participants().local.tracks.video.persistentTrack;

const results = await call.testPeerToPeerCallQuality({ videoTrack, duration: 10 });

switch (results.result) {
  case 'aborted':
    console.log('Test aborted before data was gathered.');
    break;
  case 'failed':
    console.warn('Test failed:', results.errorMsg);
    break;
  case 'bad':
    console.warn('Poor connection. Try a different network.');
    break;
  case 'warning':
    console.warn('Connection may be unstable.');
    break;
  case 'good':
  default:
    console.log('Connection quality is good.');
}
```

## See also

> [card] Methods
>
> * [stopTestPeerToPeerCallQuality()](https://docs.daily.co/reference/daily-js/instance-methods/stop-test-peer-to-peer-call-quality.md)
> * [testCallQuality()](https://docs.daily.co/reference/daily-js/instance-methods/test-call-quality.md)
> * [testNetworkConnectivity()](https://docs.daily.co/reference/daily-js/instance-methods/test-network-connectivity.md)
> * [testWebsocketConnectivity()](https://docs.daily.co/reference/daily-js/instance-methods/test-websocket-connectivity.md)
> * [getNetworkStats()](https://docs.daily.co/reference/daily-js/instance-methods/get-network-stats.md)

> [card] Events
>
> * [test-completed](https://docs.daily.co/reference/daily-js/events/network-events.md#test-completed)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.