RTCStatsInsight

RTCStatsInsight

EventEmitter class that polls getStats() to monitor connection status.

Constructor

new RTCStatsInsight(statsSrc, options)

Create a RTCStatsInsight.

Parameters:
Name Type Description
statsSrc RTCPeerConnection | RTCRtpReceiver | RTCRtpSender

getStats() method of this object is called in RTCStatsInsight.

options Object
Name Type Description
interval Number

The polling interval in milliseconds. default 1000ms.

thresholds Thresholds

A set of thresholds for emitting each events.

triggerCondition Object

The trigger condition which defines how much failures makes this to fire an event. ${triggerCondition.failCount} failures within ${triggerCondition.within} attemption causes trigger of events.

Example
import {
  StatusLevels,
  RTCStatsInsightEvents,
  RTCStatsInsight
} from 'rtcstats-wrapper';

const options = {
  interval: 3000,
  thresholds: {
    "audio-rtt": {
      unstable: 0.1
    },
    "audio-fractionLost": {
      unstable: 0.03,
      critical: 0.08,
    },
  },
  triggerCondition: {
    failCount: 2,
    within: 3
  }
}

const insight = new RTCStatsInsight(sender, options);

insight.on(RTCStatsInsightEvents["audio-rtt"].key, event => {
  if (event.level === StatusLevels.stable.key) {
    console.log("Now back to stable!");
  }
});

insight.watch()

Methods

stop()

Stop polling getStats().

Events

audio-fractionLost

Fires when the packet loss rate of receiving audio stream has been changed. By default, unstable fires on packet loss rate > 8% and critical fires on packet loss rate > 15%.

Properties:
Name Type Description
level string

Warning level. This will be "stable" or "unstable" or "critical".

threshold string

Threshold for this event to fire.

value string

Last measured value when this event fires.

audio-jitter

Fires when a jitter of sending audio stream has been changed. By default, unstable fires on jitter > 50ms and critical fires on jitter > 100ms.

Properties:
Name Type Description
level string

Warning level. This will be "stable" or "unstable" or "critical".

threshold string

Threshold for this event to fire.

value string

Last measured value when this event fires.

audio-jitterBufferDelay

Fires when the jitter buffer delay of receiving audio stream has been changed. By default, unstable fires on jitter buffer delay > 500ms and critical fires on jitter buffer delay > 1000ms.

Properties:
Name Type Description
level string

Warning level. This will be "stable" or "unstable" or "critical".

threshold string

Threshold for this event to fire.

value string

Last measured value when this event fires.

audio-rtt

Fires when an RTT of sending audio stream has been changed. By default, unstable fires on RTT > 400ms and critical fires on RTT > 800ms.

Properties:
Name Type Description
level string

Warning level. This will be "stable" or "unstable" or "critical".

threshold string

Threshold for this event to fire.

value string

Last measured value when this event fires.

rtt

Fires when the rtt of ICE connection has been changed. The difference with media RTT is that media RTT uses the value of RTCP packet, and this RTT uses ICE connectivity checks timestamp. By default, unstable fires on rtt > 500ms and critical fires on rtt > 1000ms.

Properties:
Name Type Description
level string

Warning level. This will be "stable" or "unstable" or "critical".

threshold string

Threshold for this event to fire.

value string

Last measured value when this event fires.

video-fractionLost

Fires when the packet loss rate of receiving video stream has been changed. By default, unstable fires on packet loss rate > 8% and critical fires on packet loss rate > 15%.

Properties:
Name Type Description
level string

Warning level. This will be "stable" or "unstable" or "critical".

threshold string

Threshold for this event to fire.

value string

Last measured value when this event fires.

video-jitter

Fires when a jitter of sending video stream has been changed. By default, unstable fires on jitter > 30ms and critical fires on jitter > 100ms.

Properties:
Name Type Description
level string

Warning level. This will be "stable" or "unstable" or "critical".

threshold string

Threshold for this event to fire.

value string

Last measured value when this event fires.

video-jitterBufferDelay

Fires when the jitter buffer delay of receiving video stream has been changed. By default, unstable fires on jitter buffer delay > 50ms and critical fires on jitter buffer delay > 100ms.

Properties:
Name Type Description
level string

Warning level. This will be "stable" or "unstable" or "critical".

threshold string

Threshold for this event to fire.

value string

Last measured value when this event fires.

video-rtt

Fires when an RTT of sending video stream has been changed. By default, unstable fires on RTT > 400ms and critical fires on RTT > 800ms.

Properties:
Name Type Description
level string

Warning level. This will be "stable" or "unstable" or "critical".

threshold string

Threshold for this event to fire.

value string

Last measured value when this event fires.