Skip to main content

Overview

The stats package provides comprehensive statistics collection for WebRTC connections. It implements the WebRTC Statistics API, allowing you to monitor and measure various aspects of peer connections, RTP streams, ICE candidates, transports, and more.

Core Types

Stats Interface

The base interface for all statistics objects.
All statistics types implement this interface to identify them as valid stats objects.

StatsReport

A collection of stats objects indexed by their unique identifiers.
Usage Example

StatsTimestamp

A timestamp represented as floating point milliseconds since epoch.
time.Time
Converts the timestamp to a Go time.Time value
Example

Statistics Types

StatsType

Indicates the type of statistics object.
Constants
string
Used by CodecStats (“codec”)
string
Used by InboundRTPStreamStats (“inbound-rtp”)
string
Used by OutboundRTPStreamStats (“outbound-rtp”)
string
Used by RemoteInboundRTPStreamStats (“remote-inbound-rtp”)
string
Used by RemoteOutboundRTPStreamStats (“remote-outbound-rtp”)
string
Used by RTPContributingSourceStats (“csrc”)
string
Used by AudioSourceStats or VideoSourceStats (“media-source”)
string
Used by AudioPlayoutStats (“media-playout”)
string
Used by PeerConnectionStats (“peer-connection”)
string
Used by DataChannelStats (“data-channel”)
string
Used by TransportStats (“transport”)
string
Used by ICECandidatePairStats (“candidate-pair”)
string
Used by ICECandidateStats for local candidates (“local-candidate”)
string
Used by ICECandidateStats for remote candidates (“remote-candidate”)
string
Used by CertificateStats (“certificate”)
string
Used by SCTPTransportStats (“sctp-transport”)

RTP Stream Statistics

InboundRTPStreamStats

Statistics for an inbound RTP stream currently being received.

OutboundRTPStreamStats

Statistics for an outbound RTP stream currently being sent.
Example

RemoteInboundRTPStreamStats

Statistics for the remote endpoint’s inbound RTP stream, measured at the remote endpoint and reported via RTCP.

RemoteOutboundRTPStreamStats

Statistics for the remote endpoint’s outbound RTP stream, measured at the remote endpoint and reported via RTCP.

Codec Statistics

CodecStats

Statistics for a codec currently being used by RTP streams.
string
Either CodecTypeEncode or CodecTypeDecode
Example

Media Source Statistics

AudioSourceStats

Statistics for an audio track attached to sender(s).

VideoSourceStats

Statistics for a video track attached to sender(s).
Example

ICE Statistics

ICECandidatePairStats

Statistics for an ICE candidate pair.
Example

ICECandidateStats

Statistics for an ICE candidate.
Example

Transport Statistics

TransportStats

Statistics for the ICE/DTLS transport.
Example

CertificateStats

Statistics for a certificate used by an ICE transport.

Data Channel Statistics

DataChannelStats

Statistics for a data channel.
Example

SCTPTransportStats

Statistics for the SCTP transport used by data channels.

PeerConnection Statistics

PeerConnectionStats

Statistics for the overall peer connection.

Additional Statistics Types

AudioPlayoutStats

Statistics for audio playout path.

RTPContributingSourceStats

Statistics for a contributing source (CSRC).

Sender and Receiver Statistics

Utility Functions

UnmarshalStatsJSON

Unmarshals a Stats object from JSON.
Parameters
[]byte
required
JSON-encoded statistics object
Returns
Stats
The unmarshaled statistics object (specific type based on the “type” field)
error
Error if unmarshaling fails or type is unknown
Example

Common Patterns

Monitoring Connection Quality

Exporting Stats to JSON

Calculating Bitrates

See Also