# Pre-call tests (/en/realtime-media/interactive-live-streaming/build/optimize-quality-and-connection/pre-call-tests/web)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

In video calling implementations that demand high communication quality, pre-call detection helps identify and troubleshoot issues beforehand, ensuring seamless real-time interaction.

      
  
      
  
      
  
      
    This page shows you how to use Video SDK to run pre-call tests to identify and troubleshoot communication quality issues in your app.

    ## Understand the tech [#understand-the-tech-3]

    Pre-call testing typically covers two aspects:

    * **Equipment quality test**

      Device quality testing involves testing whether the local microphone, speaker, and camera are working properly.

    * **Network quality analysis**

      The quality of the last mile network affects the smoothness and clarity of the audio and video that the user sends and receives. Last mile refers to the last leg of communication network between the edge server of the Agora SDRTN® and the end-user devices. Network quality analysis enables you to get feedback on the available bandwidth, packet loss rate, network jitter, and round-trip delay of the upstream and downstream last-mile networks. It enables you to examine if current network conditions are good enough to meet the requirements of the currently selected audio bitrate or the target video bitrate.

    <CalloutContainer type="info">
      <CalloutDescription>
        Best practice is to run the device test first and then perform a network test.
      </CalloutDescription>
    </CalloutContainer>

    ## Prerequisites [#prerequisites-3]

    Ensure that you have implemented the [SDK quickstart](../../index.mdx) project and that your app has obtained permissions to use the relevant devices.

    ## Implement pre-call testing [#implement-pre-call-testing-3]

    This section shows you how to implement pre-call testing in your project.

    ### Equipment quality test [#equipment-quality-test-3]

    You test the recording and playback devices separately.

    #### Recording equipment testing [#recording-equipment-testing]

    Refer to the following steps to test the local microphone and camera:

    1. Call `AgoraRTC.getDevices` to get the available devices and their IDs.

    2. When calling `AgoraRTC.createCameraVideoTrack` and `AgoraRTC.createMicrophoneAudioTrack` to create local audio and video track objects, pass in `cameraId` and `microphoneId` to specify the devices you want to test.

    3. After creating the local audio or video track object, call `CameraVideoTrack.play` to play the local video track:

    4. If you are testing the microphone, call `MicrophoneAudioTrack.getVolumeLevel` to get the volume level. If the volume is greater than `0`, it means that the microphone is working normally.

    5. When testing the camera, if you see the picture after playing the video track, it means that the camera is working normally.

    To implement recording equipment tests in your app, refer to the following code:

    ```javascript
    // Get all audio and video devices
    AgoraRTC.getDevices()
     .then(devices => {
      const audioDevices = devices.filter(function(device){
        return device.kind === "audioinput";
      });
      const videoDevices = devices.filter(function(device){
        return device.kind === "videoinput";
      });

      var selectedMicrophoneId = audioDevices[0].deviceId;
      var selectedCameraId = videoDevices[0].deviceId;
      return Promise.all([
       AgoraRTC.createCameraVideoTrack({ cameraId: selectedCameraId }),
       AgoraRTC.createMicrophoneAudioTrack({ microphoneId: selectedMicrophoneId }),
      ]);
     })
     .then([videoTrack, audioTrack] => {
      videoTrack.play("<ELEMENT_ID_IN_DOM>");
      setInterval(() => {
       const level = audioTrack.getVolumeLevel();
       console.log("local stream audio level", level);
      }, 1000);
     });
    ```

    <CalloutContainer type="info">
      <CalloutDescription>
        * Best practice is to draw the volume change and camera screen on the UI so that users can judge if the device is working properly.
        * Device IDs are randomly generated, and in some cases the ID of the same device may change. Best practice is to call `AgoraRTC.getDevices` to get the device ID every time you test the device.
      </CalloutDescription>
    </CalloutContainer>

    #### Playback device testing [#playback-device-testing]

    The Agora SDK for Web does not provide an API for testing audio playback devices. Use the following methods to test the audio playback devices:

    * Create an audio player on the page using the HTML5 `<audio>` element. Prompt the user to play the audio file and confirm that the sound is audible.

    * After capturing the microphone audio, call `MicrophoneAudioTrack.play` to play the microphone sound and prompt the user to subjectively verify that the playback is audible.

    ### Network quality analysis [#network-quality-analysis-3]

    Refer to the following steps to perform a network quality test before a call or live broadcast:

    1. Call `createClient` twice, to create two clients:
       * `uplinkClient`: To test the connection status of the uplink network.
       * `downlinkClient`: To test the connection status of the downlink network.

    2. Both clients call `join` to enter a channel for testing.

    3. Call `createMicrophoneAndCameraTracks` to create audio and video tracks.

    4. Call `publish` on `uplinkClient` to publish audio and video tracks and `subscribe` on `downlinkClient` to subscribe to audio and video tracks.

    5. Listen to the `uplinkClient.on("network-quality")` event to get the uplink network status between the local device and Agora server.

    6. Listen to `downlinkClient.on("network-quality")` event to get the downlink network status between the local device and the Agora server. The SDK triggers the `client.on("network-quality")` callback every two seconds.

    7. To get specific statistics about the sent or received media tracks, such as send/receive bitrate, end-to-end latency, call `getLocalAudioStats` and `getLocalVideoStats` on `uplinkClient` to get the uplink statistics, and `getRemoteAudioStats` and `getRemoteVideoStats` on `downlinkClient` to get the downlink statistics.

    The following figure summarizes the calling sequence of network quality tests:

    **Pre-call last mile test**

    ![Network quality analysis](https://assets-docs.agora.io/images/video-sdk/pre-call-network-quality-web.svg)

    To implement network quality testing in your app, refer to the following code:

    ```typescript
    // Get uplink network quality
    uplinkClient.on("network-quality", (quality) => {
     console.log("uplink network quality", quality.uplinkNetworkQuality);
    });

    // Get downlink network quality
    downlinkClient.on("network-quality", (quality) => {
     console.log("downlink network quality", quality.downlinkNetworkQuality);
    });

    // Get uplink statistics
    uplinkVideoStats = uplinkClient.getLocalVideoStats();
    // Get downlink statistics
    downlinkVideoStats = downlinkClient.getRemoteVideoStats()[<UPLINKCLIENT_UID>];

    console.log("uplink video stats", uplinkVideoStats);
    console.log("downlink video stats", downlinkVideoStats);
    ```

    ## Reference [#reference-3]

    This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

    ### Troubleshooting device and network issues [#troubleshooting-device-and-network-issues-3]

    If you encounter problems while running pre-call tests, first ensure that you have implemented the API calls properly. To troubleshoot device and network issues, refer to the following table:

    | Problem                                                                           | Solution                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
    | :-------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | Can't hear sound when testing audio devices.                                      | * Check that the recording device and the playback device are working properly, and are not occupied by other programs.
    * Check that the network connection is normal.                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
    | Cannot see the screen when testing video devices.                                 | - Check that the video device is working properly and not occupied by other programs.
    - Check whether the network connection is normal.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
    | Poor uplink network quality detected (packet loss > 5%; network jitter > 100ms)   | * Check that the local network is working properly.
    * Ensure that the bitrate of the published audio and video streams does not exceed the available uplink bandwidth by reducing the resolution or lowering the frame rate.                                                                                                                                                                                                                                                                                                                                                                                            |
    | Poor downlink network quality detected (packet loss > 5%; network jitter > 100ms) | - Check that the local network is working properly.
    - Ensure that the total bandwidth of the local subscription does not exceed the available downstream bandwidth by:
      * Reducing the number of subscribed audio and video streams on the receiving end or reducing the bitrate of published audio and video streams on the sending end.
      * Enabling dual-stream mode on the sending side and requesting to receive small streams on the receiving side to reduce bandwidth consumption.
      * Enabling the video stream fallback function or the multiple streams by priority fallback function at the receiving end. |

    ### Sample project [#sample-project-3]

    Agora provides the following open-source projects for your reference:

    * [JoinChannelAudio](https://github.com/AgoraIO-Extensions/Electron-SDK/blob/main/example/src/renderer/examples/basic/JoinChannelAudio/JoinChannelAudio.tsx)

    Download or view the code for more detailed examples.

    ### API reference [#api-reference-3]

    * Equipment testing :
      * [getDevices](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartc.html#getdevices)
      * [getCameras](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartc.html#getcameras)
      * [getMicrophones](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartc.html#getmicrophones)
      * [createMicrophoneAudioTrack](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartc.html#createmicrophoneaudiotrack)
      * [createCameraVideoTrack](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartc.html#createcameravideotrack)

    * Network analysis:
      * [network-quality](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartcclient.html#event_network_quality)
      * [getLocalAudioStats](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartcclient.html#getlocalaudiostats)
      * [getLocalVideoStats](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartcclient.html#getlocalvideostats)
      * [getRemoteAudioStats](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartcclient.html#getremoteaudiostats)
      * [getRemoteVideoStats](https://api-ref.agora.io/en/video-sdk/web/4.x/interfaces/iagorartcclient.html#getremotevideostats)

    
  
      
  
      
  
      
  
      
  
      
  
      
  
      
  
