Skip to main content

Overview

RTCStats is a singleton service that proxies WebRTC functions (getUserMedia, RTCPeerConnection) and sends analytics data to an rtcstats server via WebSocket. It must be initialized once after lib-jitsi-meet is loaded and persists for the lifetime of the application.

Key Features

  • Proxies WebRTC APIs to capture statistics automatically
  • Sends getstats data and WebRTC events to rtcstats server
  • Handles connection and conference lifecycle
  • Supports breakout rooms and multi-conference scenarios
  • Collects and flushes logs automatically

Methods

startWithConnection

Initializes the rtcstats trace module when a JitsiConnection is created, before joining a conference.
JitsiConnection
required
The JitsiConnection instance containing rtcstats configuration
Configuration Options (from connection.options.analytics):
boolean
default:"false"
Whether rtcstats collection is enabled
string
WebSocket URL of the rtcstats server
number
default:"10000"
Interval in milliseconds for polling WebRTC statistics
boolean
default:"false"
Whether to send SDP (Session Description Protocol) data
Example:

attachToConference

Attaches RTCStats to a conference instance to track conference-specific metrics and handle conference lifecycle events.
JitsiConference
required
The JitsiConference instance to attach to
This method:
  • Waits for the conference to be joined before sending identity data
  • Handles breakout room transitions
  • Tracks conference unique ID and participant information
  • Flushes logs when conference ends
Example:

sendStatsEntry

Sends a custom statistics entry to the rtcstats server. Called internally by the rtcstats proxy or by applications for custom metrics.
RTCStatsEvents
required
The type of statistics event being sent
string
Optional peer connection identifier
any
Optional data payload for the stats entry
Example:

sendIdentity

Sends identity and configuration data to the rtcstats server for tracking purposes.
object
required
Object containing identity information (conference name, user ID, display name, etc.)
Example:

reset

Resets the trace module by closing the WebSocket connection. Used when switching between conferences (e.g., breakout rooms).
Example:

isTraceAvailable

Checks if the trace module is currently initialized and connected.
Returns: true if trace is connected, false otherwise Example:

getDefaultLogCollector

Creates or retrieves the default log collector that buffers logs and sends them to rtcstats.
number
default:"10000"
Maximum length in bytes for each log entry
Example:

Events

RTCStats emits events through its events EventEmitter:

RTC_STATS_PC_EVENT

Emitted when a peer connection event occurs.

RTC_STATS_WC_DISCONNECTED

Emitted when the WebSocket connection to the rtcstats server closes.

Complete Example

Important Notes

RTCStats must be initialized only once per application lifetime. Calling startWithConnection multiple times will cause the global WebRTC objects to be rewritten with unforeseen consequences.
Data is not sent to the rtcstats server until the WebSocket connection is established. However, getUserMedia calls are buffered internally and sent once connected.
When using breakout rooms or multi-conference scenarios in React Native (where the JS context persists), RTCStats automatically handles trace reset and reinitialization between conferences.