@100mslive/hls-stats

中文文档
0.7.3发布于 2026/10/01ISCTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4.2万

A simple library that provides stats for your hls stream

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. initialization
  4. Subscribing to Stats
  5. Exposed Stats

@100mslive/hms-stats

Lint, Test and Build Bundle Size License Tree shaking

A simple library for HLS stats for Hls.js.

Installation

yarn add @100mslive/hls-stats

or

npm install --save @100mslive/hls-stats

Usage

initialization


import Hls from "hls.js";

/**
 * Initialize Hls.js and attach the video element.
 */
const hlsInstance = new Hls();
hlsInstance.loadSource(hlsUrl);
hlsInstance.attachMedia(videoEl);

/**
 * initialize HlsStats
 */
const hlsStats = new HlsStats(hlsController.getHlsJsInstance(), videoEl);

Subscribing to Stats

hlsStats have a subscribe function which takes two parameter. a callbackFn and an interval in ms. The interval tells how frequent you want hls-stats to report back to you. Default is 2000ms

const unsubscribe = hlsStats.subscribe(state => {
    // ...
});

the subscribe() also returns a reference to unsubscribe() function which could later be used to unsubscribe from your subscription

Exposed Stats

hls-stats currently exposes the following stats

NameDescriptionUnitUsage
bandwidthEstimateThe current bandwidth, as seen by the playerbits per secondUse this to show the current network speed of the user
bitrateserver indicated bitrate of current layer of hls streambits per secondUse to know the bitrate required for current layer
bufferedDurationbuffered duration from the current positionmsThis can be used to show how much data is buffered from the current location (forward buffer)
distanceFromLiveEdgeThe distance from the live edgemsUsed to know currently buffered duration ahead
droppedFramesThe number of dropped frames till nowUsed to calculate the total num of dropped frames
videoSize.width videoSize.heightThe width and height of the videopxUsed to know the resolution being played
watchDurationTotal duration watchedmsused to know the overall watch duration (not the stream length)

版本与发布记录

@100mslive/hls-stats 共发布 537 个版本,首次发布于 2022/11/10;过去 12 个月发布了 82 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.7.3latest2026/10/011 个月前
0.7.3-alpha.1alpha2026/10/011 个月前
0.7.3-alpha.02026/09/291 个月前
0.7.22026/09/221 个月前
0.7.2-alpha.62026/09/221 个月前
0.7.2-alpha.52026/09/221 个月前

其他发布通道:experimental → 0.0.6-alpha.0,alpha → 0.7.3-alpha.1。

关于 @100mslive/hls-stats 的常见问题

@100mslive/hls-stats 是什么?

A simple library that provides stats for your hls stream

如何安装 @100mslive/hls-stats?

在项目目录运行 npm install @100mslive/hls-stats,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:hls.js(1.4.12)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@100mslive/hls-stats 支持 TypeScript 吗?

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

@100mslive/hls-stats 支持 ESM 还是 CommonJS?

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

@100mslive/hls-stats 可以商用吗?

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

@100mslive/hls-stats 的下载量有多少?

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

@100mslive/hls-stats 还在维护吗?

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