npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rtcstats/rtcstats-js

v2.1.0

Published

gather WebRTC API traces and statistics

Readme

This is part of the monorepo for rtcstats-js (clientside monitoring), rtcstats-server (serverside dump collection) and the updated dump-importer (supporting rtcstats and webrtc-internals formats).

It is part of a bigger offering that includes rtcstats.com, an online service for debugging and troubleshooting WebRTC statistics.

rtcstats-js: A Javascript client SDK for monitoring WebRTC

The Javascript SDK provides low-level logging on peerconnection API calls and periodic getStats calls for analytics/debugging purposes. It was designed to add a negligible overhead to the application’s performance with minimal integration efforts and remains inspired by chrome's webrtc-internals page.

This repository is the current iteration of the 2015 rtcstats.js. The principle is still the same:

  • Transparent integration by overriding RTCPeerConnection et al with techniques used by adapter.js
  • Trace all RTCPeerConnection and getUserMedia API calls and events.
  • Send them to a server over Websocket.

Usage

The main rtcstats.js exports a number of methods that facilitate this:

  • WebSocketTrace instantiates a trace function that is passed to the other methods. It connects to a server over WebSocket.
  • wrapRTCPeerConnection wraps RTCPeerConnection and related APIs on the supplied window object and generates traces using the supplied trace method.
  • wrapGetUserMedia and wrapEnumerateDevices do the same for the getUserMedia/getDisplayMedia, enumerateDevices and related APIs such as MediaStreamTracks and HTMLVideoElement.

Typical usage looks like this:

import {wrapRTCStatsWithDefaultOptions} from '@rtcstats/rtcstats-js';

// Instantiate a trace function, using the helper with default options.
// See the example for a more fine-grained approach to wrapping.
const trace = wrapRTCStatsWithDefaultOptions();

// Connect to the rtcstats-server instance.
trace.connect('ws://localhost:8080' + window.location.pathname);

const pc = new RTCPeerConnection();

Using a JWT to connect to rtcstats-server

See the server README for how to generate JWT token with information about the user, session and conference.

If the server is configured to require an authorization token, the websocket will be closed with a 1008 policy-violation error and a console warning is emitted.

Bundling

To bundle rtcstats-js including its dependencies, use

npx webpack --entry ./packages/rtcstats-js/rtcstats.js --output-path ./packages/rtcstats-js/dist --output-filename rtcstats.bundle.js --mode production --output-library rtcstats

then include the resulting bundle which is exported as the global rtcstats object:

<script type="text/javascript" src="rtcstats.bundle.js"></script>
<script type="text/javascript">
const trace = rtcstats.wrapRTCStatsWithDefaultOptions();
// Do something.
</script>

Ending a session

RTCStats sessions create a single dump file for every websocket connection. For long-running pages it may be required to close the websocket when a "session" is done and reconnect (possibly with a new JWT):

trace.connect('ws://localhost:8080/?rtcstats-token=token-1');
// Do something
trace.close()

// Reconnect.
trace.connect('ws://localhost:8080/?rtcstats-token=token-2');

Note that RTCStats is not keeping track of whether all RTCPeerConnections have been closed and track from getUserMedia/getDisplayMedia have been stopped.

See also

See also the end-to-end example in example/ directory and the (internal) API docs here.