How to Retrieve Outgoing Bandwidth available Using RTC Stats How to Retrieve Outgoing Bandwidth available Using RTC Stats

How to Retrieve Outgoing Bandwidth available Using RTC Stats

Vonage API Support

Understanding AvailableOutgoingBitrate

AvailableOutgoingBitrate reports the current available bandwidth for outgoing media in a WebRTC session. It can be obtained using the method publisher.getRtcStatsReport. This method dynamically monitors network conditions and adjusts the bitrate to match the available bandwidth, ensuring optimal media quality.

Key Features

  • How it works: It measures the network's capacity to send media and adjusts the media quality (e.g., video resolution) to fit within the available bandwidth.
  • Value type: The value is a number representing the available bandwidth for sending media, measured in bits per second (bps).

How to Retrieve AvailableOutgoingBitrate

Use the following example to initialize a publisher and check the AvailableOutgoingBitrate value:

// Example: Initializing a publisher and checking stats using getRtcStatsReport
const publisher = OT.initPublisher('publisherElementId', {
  insertMode: 'append',
  width: '100%',
  height: '100%'
});

// Check stats every few seconds (adjust interval as needed)
setInterval(() = {
  publisher.getRtcStatsReport((error, report) = {
    if (error) {
      console.error('Error getting RTC stats report: ', error);
      return;
    }

    // Loop through the RTC stats report
    report.forEach((stats) = {
      if (stats.type === 'candidate-pair' && stats.availableOutgoingBitrate) {
        console.log('Available Outgoing Bitrate: ', stats.availableOutgoingBitrate / 1000, 'kbps');
      }
    });
  });
}, 5000); // Check every 5 seconds

Important Notes

  • The AvailableOutgoingBitrate value is not a strict threshold but an estimate of the available bandwidth for sending media. Actual performance may vary depending on frame rate, video resolution, and other network conditions.
  • These values are not applicable for screen sharing.

Recommended Bitrate Settings for Video Resolutions

Target Bitrate (Relay Mode) (kbps) Target Bitrate (Routed Mode) (kbps) Recommended Setting
4000 5550 1920x1080 @ 30FPS (1080p)
2500 3150 1280x720 @ 30FPS (HD)
1200 1550 960x540 @ 30FPS
500 650 640x360 @ 30FPS
300 350 480x270 @ 30FPS
150 150 320x180 @ 30FPS

Relay Mode vs. Routed Mode

The difference between relay and routed modes lies in the Simulcast feature, which is available in routed mode. Simulcast increases bandwidth requirements by sending multiple video streams at different resolutions simultaneously. This allows clients with varying network conditions to select the most suitable stream but demands more bandwidth for additional video layers.