@dolbyio/webrtc-stats

中文文档
1.3.0发布于 2026/09/04MITTypeScriptESM + CJS构建来源已验证近 30 天下载 5.8万

Dolby OptiView WebRTC Statistics

原始使用文档
文档目录8 节
  1. Install this project
  2. Use the library
  3. Collection
  4. Events
  5. Example
  6. Logs
  7. How to
  8. Related Projects

Build Package Build Documentation Publish Package npm License

Dolby OptiView WebRTC Statistics

This project is a library to use to parse WebRTC statistics.

Install this project

Run the following npm command to install the package @dolbyio/webrtc-stats into your project:

npm install @dolbyio/webrtc-stats

Use the library

Collection

A WebRTCStats object needs to be created to start a WebRTC statistics collection. It requires some settings to configure how you want the collection to work. First, import the WebRTCStats definition.

import { WebRTCStats } from '@dolbyio/webrtc-stats';

Create the collection object like this example:

const collection = new WebRTCStats({
    getStats: () => {
        // Get the raw WebRTC statistics from the web browser
    },
    getStatsInterval: 1000,
    includeRawStats: true,
});

Start the collection with the start() function.

collection.start();

Stop the collection with the stop() function.

collection.stop();

Events

After starting the collection, the stats event is triggered when the WebRTC statistics have been collected and parsed.

import { OnStats } from '@dolbyio/webrtc-stats';

collection.on('stats', (event: OnStats) => {
    console.log(event);
});

The error event is triggered when an error happens during the collection or the parsing of the WebRTC statistics.

collection.on('error', (reason: string) => {
    console.error(reason);
});

Example

Example on how to start a statistics collection from the Dolby OptiView SDK.

import { WebRTCStats, OnStats } from '@dolbyio/webrtc-stats';
import { Director, Publish } from '@millicast/sdk';

const PUBLISHER_TOKEN = '';
const STREAM_NAME = '';

const tokenGenerator = () =>
    Director.getPublisher({
        token: PUBLISHER_TOKEN,
        streamName: STREAM_NAME,
    });

const publisher = new Publish(undefined, tokenGenerator);

// HERE: Publish a stream to Dolby OptiView

const collection = new WebRTCStats({
    getStatsInterval: 1000,
    getStats: () => {
        return publisher.webRTCPeer.getRTCPeer().getStats();
    },
});

// The stats event is triggered after each interval has elapsed
collection.on('stats', (event: OnStats) => {
    console.log(event);
});

// Start the statistics collection
collection.start();

Logs

You can also print the logs in the console and select the log level by using the following code.

import { Logger } from '@dolbyio/webrtc-stats';

Logger.useDefaults({
    defaultLevel: Logger.TRACE,
});

How to

Run tests:

npm run test

Create distribution package:

npm run build

The documentation is built on TypeDoc, to generate the doc, run the following command. You will find the HTML files in the docs folder.

npm run docs

版本与发布记录

@dolbyio/webrtc-stats 共发布 12 个版本,首次发布于 2023/03/08;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.0latest2026/09/042 个月前
1.2.22026/08/133 个月前
1.2.12026/07/253 个月前
1.0.42025/05/021.5 年前
1.0.32025/04/111.6 年前
1.0.22024/07/182 年前

关于 @dolbyio/webrtc-stats 的常见问题

@dolbyio/webrtc-stats 是什么?

Dolby OptiView WebRTC Statistics

如何安装 @dolbyio/webrtc-stats?

在项目目录运行 npm install @dolbyio/webrtc-stats,或使用 pnpm add / yarn add / bun add。

@dolbyio/webrtc-stats 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dolbyio/webrtc-stats 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dolbyio/webrtc-stats 可以商用吗?

@dolbyio/webrtc-stats 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dolbyio/webrtc-stats 的下载量有多少?

根据 npm 官方下载统计,@dolbyio/webrtc-stats 在 2026/10/13 – 2026/11/11 这 30 天内被下载 58,228 次,日均约 1,941 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dolbyio/webrtc-stats 还在维护吗?

最新版本 1.3.0 发布于 2026/09/04(2 个月前);至今共发布 12 个版本,其中过去 12 个月发布了 3 个;首次发布于 2023/03/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。