WebRTC stats API — extracting real-time MOS score from RTCPeerConnection

We need to extract real-time MOS scores from the browser’s WebRTC stats API to display call quality indicators on our custom agent desktop.

Is there a way to access the RTP statistics during a live call, or do we have to wait for the call to end?

Yes! The RTCPeerConnection.getStats() API provides real-time RTP statistics during the call.

async function getMOSScore(peerConnection) {
  const stats = await peerConnection.getStats();
  let jitter, packetsLost, roundTripTime;
  stats.forEach(report => {
    if (report.type === 'inbound-rtp' && report.kind === 'audio') {
      jitter = report.jitter;
      packetsLost = report.packetsLost;
    }
    if (report.type === 'candidate-pair' && report.nominated) {
      roundTripTime = report.currentRoundTripTime;
    }
  });
  return calculateMOS(jitter, packetsLost, roundTripTime);
}

The MOS calculation from raw stats uses the E-model (ITU-T G.107).

The simplified formula: R = 93.2 - (jitter_ms * 0.5) - (packet_loss_pct * 2.5) - (rtt_ms * 0.1). Then convert R to MOS: MOS = 1 + 0.035*R + R*(R-60)*(100-R)*7e-6. This gives you a MOS score from 1.0 to 4.5.

We display the MOS score as a color-coded indicator on our custom desktop.

MOS Range Color Label
4.0-4.5 Green Excellent
3.5-3.9 Yellow Good
3.0-3.4 Orange Fair
< 3.0 Red Poor

Agents see the indicator in real-time and can alert their supervisor if quality degrades mid-call.

1 Like

From a compliance perspective, we log every MOS reading to prove call quality meets our SLA thresholds.

Our contract guarantees MOS ≥ 3.5 for 95% of calls. We sample MOS every 10 seconds during each call, store the readings in Elasticsearch, and generate monthly SLA compliance reports.

3 Likes

For remote agents, correlate MOS drops with VPN reconnection events.

We overlay the MOS timeline with the agent’s network event log. Every VPN reconnect creates a 3-5 second MOS dip. If an agent has 10+ VPN reconnects per shift, their average MOS will be significantly lower than office-based agents.

1 Like