Skip to main content
Version: 1.x.x

Monitoring Network Quality - Javascript

VideoSDK gives you two ways to keep an eye on network conditions during a meeting:

  • Participant network quality: the server measures every participant's connection and reports a quality level for what they send (uplink) and what they receive (downlink). Use it to show network indicators next to participants.
  • Quality limitation: the quality-limitation event tells you when the local participant's media quality is reduced, or restored, because of CPU, bandwidth or congestion.

Participant Network Quality​

network-quality-changed​

  • This event is triggered with a participant's network quality, measured by the server, for both directions:

    • uplink: the connection from the participant to the server (the media they send).
    • downlink: the connection from the server to the participant (the media they receive).
  • It can be subscribed to using the participant object, and works for meeting.localParticipant as well as remote participants.

  • Adding the first network-quality-changed listener with participant.on() subscribes to that participant's network quality. Removing the last listener with participant.off() unsubscribes.

  • A listener added before the meeting is joined subscribes once the meeting is joined.

  • The first event carries the current quality, once the server knows it. A listener added while the participant is already subscribed also receives the current quality. After that, the event is triggered whenever the level or the reasons of either direction change, including when the connection recovers.

  • The subscription is restored automatically after a reconnect.

Network quality data​

The event receives { uplink, downlink }. uplink and downlink have the same shape:

PropertyTypeDescription
levelstringgood, fair, poor, bad, or unknown. It is unknown when no media flows in that direction.
scorenumberFrom 1 (bad) to 5 (good). It is 0 when the level is unknown.
reasonsarrayEvery signal pulling the level down, worst first. It is empty when the level is good or unknown.
metricsobjectThe raw values behind the level. A field is present only when it was measured.

Possible values of reasons:

ReasonMeaning
packetLossHigh packet loss
rttHigh round-trip time
jitterHigh jitter
bandwidthNot enough bandwidth
stalledMedia has stalled

Fields of metrics:

MetricDirectionDescription
packetLossBothPacket loss, in %.
jitterBothAudio jitter, in ms.
rttDownlinkRound-trip time, in ms.
availableBitrateDownlinkThe server's bandwidth estimate for the participant, in bps.
limitedStreamsDownlinkNumber of video streams forwarded below the quality the participant asked for.
videoStreamsDownlinkNumber of video streams the participant receives.
activeLayersUplinkNumber of simulcast layers the participant is sending now.
peakLayersUplinkThe most simulcast layers the participant has sent so far.

Example​

This example logs the network quality of every remote participant, and stops listening when they leave.

let meeting;

// Initialize Meeting
meeting = VideoSDK.initMeeting({
// Configuration options
});

function onNetworkQualityChanged({ uplink, downlink }) {
console.log(
`${peerId} uplink: ${uplink.level} [${uplink.reasons.join(", ")}],`,
`downlink: ${downlink.level} [${downlink.reasons.join(", ")}]`
);
}

meeting.on("participant-joined", (participant) => {
// Subscribes to this participant's network quality
participant.on("network-quality-changed", onNetworkQualityChanged);
});

meeting.on("participant-left", (participant) => {
// Removing the last listener unsubscribes
participant.off("network-quality-changed", onNetworkQualityChanged);
});

Getting the current network quality​

participant.getNetworkQuality() returns the participant's last known { uplink, downlink }. The value is kept up to date while a network-quality-changed listener is attached.

const { uplink, downlink } = participant.getNetworkQuality();
console.log(uplink.level, downlink.level);

Quality Limitation​

VideoSDK's quality-limitation event helps you stay informed whenever media quality is impacted or restored during a meeting. This allows you to take proactive steps and ensure a smooth user experience.

quality-limitation​

  • This event is triggered whenever a media quality limitation is either detected or resolved during a meeting.

  • The callback includes a type parameter that specifies the cause of the quality limitation. Possible values:

    • cpu: Quality is reduced due to high CPU usage.
    • bandwidth: Quality is reduced due to insufficient bandwidth.
    • congestion: Quality is reduced due to network congestion.
  • The callback also includes a state parameter that indicates the current status of the limitation:

    • detected: A limitation has been identified.
    • resolved: The limitation has been cleared.
  • A timestamp parameter is provided, representing the exact time (in milliseconds since epoch) when the event occurred.

  • It can be subscribed to using the meeting object.

Example​

Here is an example demonstrating the usage of the event mentioned on this page.

let meeting;

// Initialize Meeting
meeting = VideoSDK.initMeeting({
// Configuration options
});

// Subscribe to the quality-limitation event
meeting.on("quality-limitation", ({ type, state, timestamp }) => {});

API Reference​

The API references for all the methods and events utilized in this guide are provided below.

Got a Question? Ask us on discord