Appearance
Class: StatsSampler
Turns successive RTCStatsReports into samples.
Stateful because the interesting numbers are rates and the report carries counters: bitrate is bytes since the last sample, loss is lost-since-last over received-since-last. Taking loss from the cumulative counters instead — which is the obvious reading of the report — averages a call's whole history and reports "fine" for minutes after the line has gone bad.
Every field of a sample is the interval since the last one, the NACK, PLI and freeze counts included. Those three were sent as the report's running totals until 2026-09-29, beside rates that were not: a row every five seconds each repeating the call's whole history, so a column summed over a call counted its first NACK once per sample.
Constructors
Constructor
ts
new StatsSampler(): StatsSampler;Returns
StatsSampler
Methods
reset()
ts
reset(): void;Returns
void
sample()
ts
sample(
report,
atMs,
opts?
): StatsSample[];opts.skip drops a stream that is not a track — the sfu subscriber's probator — and opts.trackSidOf names the TR_ sid a stream carries, where there is one (an sfu room; never p2p).
opts.interrupted says whether the connection a stream arrives on is disconnected or failed. A stream that received nothing there lost everything it was sent: its loss is 100 %, not the 0-of-0 the counters give, which graded a frozen call excellent (measured). On a connection that is up, the same silence is a paused or muted track.
Parameters
| Parameter | Type |
|---|---|
report | RTCStatsReport |
atMs | number |
opts | { interrupted?: (stat) => boolean; skip?: (stat) => boolean; trackSidOf?: (stat) => string; } |
opts.interrupted? | (stat) => boolean |
opts.skip? | (stat) => boolean |
opts.trackSidOf? | (stat) => string |