# WebTorrent

**WebTorrent** 是一个用 [JavaScript](https://www.edgepedia.org/zh/javascript) 编写的流媒体种子客户端，既能在网页浏览器中运行，也能在 Node.js 中运行。在浏览器中，它通过 WebRTC（一种使浏览器之间能够直接建立点对点连接的技术）数据通道使用 [BitTorrent](https://www.edgepedia.org/zh/bittorrent) 协议；在 Node.js 中则通过 TCP 和 UDP 使用该协议。<sup>[1](https://github.com/webtorrent/webtorrent/blob/master/README.md)</sup> 其维护者称其为第一个在浏览器中利用开放网络标准工作的 BitTorrent 客户端，无需插件，仅依赖 HTML5 和 WebRTC。<sup>[2](https://github.com/webtorrent/webtorrent)</sup> 该项目由费罗斯·阿布哈迪杰（Feross Aboukhadijeh）创建，他是一位 JavaScript 开发者，也因 StandardJS 和供应链安全公司 Socket 而为人所知。<sup>[3](https://aiminterviews.com/interview/feross-aboukhadijeh)</sup>

| 关键事实 | 详情 |
|---|---|
| 它是什么 | 一个面向 Node.js 和浏览器的流媒体种子客户端，完全用 JavaScript 编写，无原生依赖<sup>[1](https://github.com/webtorrent/webtorrent/blob/master/README.md)</sup> |
| 浏览器传输方式 | WebRTC 数据通道；浏览器客户端无法连接 UDP/TCP 节点<sup>[1](https://github.com/webtorrent/webtorrent/blob/master/README.md)</sup> |
| Node.js 传输方式 | TCP 和 UDP，与常规种子客户端相同<sup>[1](https://github.com/webtorrent/webtorrent/blob/master/README.md)</sup> |
| 节点发现 | DHT、tracker、lsd（本地节点发现）和 ut_pex；通过 ut_metadata 支持磁力链接<sup>[1](https://github.com/webtorrent/webtorrent/blob/master/README.md)</sup> |
| 流媒体 | 按需获取分片，因此种子未完成时也可拖动进度；对 .mp4、.m4v 和 .m4a 提供完整流媒体支持<sup>[1](https://github.com/webtorrent/webtorrent/blob/master/README.md)</sup><sup> • </sup><sup>[4](https://github.com/webtorrent/webtorrent/blob/master/docs/faq.md)</sup> |
| 浏览器支持 | Chrome、Firefox、Opera 和 Safari<sup>[2](https://github.com/webtorrent/webtorrent)</sup> |
| 生态系统 | WebTorrent Desktop（测试版）、webtorrent-cli、webtorrent-hybrid、instant.io；libtorrent 于 2020 年 7 月加入支持<sup>[5](https://webtorrent.io/desktop/)</sup><sup> • </sup><sup>[6](https://feross.org/about/)</sup> |

## 工作原理

BitTorrent 线路协议本身没有改变，不同的是传输方式。在浏览器中，唯一可用的点对点传输方式是 WebRTC，因此 WebTorrent 通过 WebRTC 数据通道而非 TCP 或 uTP 来运行 BitTorrent 协议。节点一旦连接，用于通信的线路协议与普通 BitTorrent 相同，这一设计选择是为了让 Transmission 和 uTorrent 等现有客户端能够轻松添加支持。<sup>[4](https://github.com/webtorrent/webtorrent/blob/master/docs/faq.md)</sup> 支持 WebRTC 的连接模型需要对 tracker 协议进行修改，因此基于浏览器的客户端（称为“web 节点”）只能连接其他支持 WebTorrent/WebRTC 的客户端。<sup>[1](https://github.com/webtorrent/webtorrent/blob/master/README.md)</sup><sup> • </sup><sup>[4](https://github.com/webtorrent/webtorrent/blob/master/docs/faq.md)</sup>

**跨域群。** 运行在一个网站上的 WebTorrent 客户端可以连接任何其他网站上的客户端。浏览器的同源策略不适用于 WebRTC 连接，因为这些连接不是客户端到服务器的连接，不过浏览器到浏览器的连接要求两个站点都加载了 WebTorrent 脚本。<sup>[4](https://github.com/webtorrent/webtorrent/blob/master/docs/faq.md)</sup>

**流媒体。** WebTorrent 将文件暴露为流，并按需从网络获取分片，因此下载完成前即可开始播放，拖动进度则通过重新调整分片获取的优先级来实现。它在顺序选择和最稀有优先的分片选择策略之间切换。<sup>[1](https://github.com/webtorrent/webtorrent/blob/master/README.md)</sup> 任意文件的视频和音频流媒体依赖 `videostream` 包，该包使用 `mp4box.js`；只有 .mp4、.m4v 和 .m4a 文件获得完整支持（包括拖动进度），其他格式则取决于浏览器的编解码器支持。<sup>[4](https://github.com/webtorrent/webtorrent/blob/master/docs/faq.md)</sup>

## 桥接常规 BitTorrent 网络

由于浏览器无法打开 TCP 或 UDP 连接，web 节点只能通过同时支持 WebRTC 和常规传输方式的混合客户端来接入更广泛的 BitTorrent 网络。在 Node.js 中，`webtorrent-hybrid` 可以从 WebRTC 节点或 TCP 节点下载，既可作为命令行程序使用，也可作为库使用。<sup>[4](https://github.com/webtorrent/webtorrent/blob/master/docs/faq.md)</sup> WebTorrent Desktop 是一款面向 Mac、Windows 和 Linux 的免费开源桌面应用，既能连接 Transmission 或 uTorrent 等 BitTorrent 节点，也能连接 instant.io 等 web 节点，并可将视频流式传输到 AirPlay、Chromecast 和 [DLNA](https://www.edgepedia.org/zh/dlna) 设备；它明确标注为测试版。<sup>[5](https://webtorrent.io/desktop/)</sup> Vuze 添加了 WebTorrent 支持，因此可以同时连接普通节点和 web 节点。<sup>[1](https://github.com/webtorrent/webtorrent/blob/master/README.md)</sup> 2020 年 7 月，Deluge 和 qBittorrent 等客户端背后的库 libtorrent 添加了对 WebTorrent 协议的支持。<sup>[6](https://feross.org/about/)</sup>

种子必须由支持 WebRTC 的客户端做种，浏览器下载才能工作；来自通用 BitTorrent 网络的任意磁力链接或 .torrent 文件在浏览器客户端中不会显示任何节点。<sup>[4](https://github.com/webtorrent/webtorrent/blob/master/docs/faq.md)</sup>

## 历史

这一想法最早在 2013 年 10 月的 RealtimeConf 大会的一次演讲中被提及，第一个可工作的演示于 2014 年 9 月在 NodeConf EU 上展示。<sup>[2](https://github.com/webtorrent/webtorrent)</sup> 阿布哈迪杰此前的项目 PeerCDN 是一个由 WebRTC 驱动的点对点网站内容分发网络，于 2013 年 3 月与阿比·拉贾（Abi Raja）和约翰·希西（John Hiesey）共同创立，并于 2013 年 12 月出售给雅虎。<sup>[4](https://github.com/webtorrent/webtorrent/blob/master/docs/faq.md)</sup> 该项目的既定目标是打造一个无需安装、能与常规 BitTorrent 网络互操作的浏览器 BitTorrent 客户端，最初先以 Chrome 应用的形式构建了一个可工作的 JavaScript 客户端来学习协议，之后才移植到 WebRTC。<sup>[7](https://github.com/webtorrent/webtorrent/issues/39)</sup>

该库仍在积极维护；当前发布系列为 v3.x，v3.0.21 于 2026 年 7 月 27 日发布。<sup>[8](https://github.com/webtorrent/webtorrent/releases)</sup>

## 采用与局限

联邦式视频平台 [PeerTube](https://www.edgepedia.org/zh/peertube) 最初使用 WebTorrent 进行点对点视频流媒体传输，并将该模式称为 Web Video。由于该系统存在若干局限，PeerTube 添加了支持 P2P 的 HLS，现在会将每个视频转码为两个版本：用于 HLS 的分片 mp4 和用于 Web Videos 的原始 mp4，两者同时启用时存储占用翻倍。<sup>[9](https://docs.joinpeertube.org/admin/configuration)</sup> 其文档仍指出，通过种子下载视频需要兼容 WebTorrent 的客户端，以便除源服务器外还能从节点获取数据。<sup>[10](https://docs.joinpeertube.org/use/watch-video)</sup>

主要的实际局限源于传输方式的割裂：对于普通种子下载，传统客户端能连接多得多的节点，因为浏览器中的 WebTorrent 只能与其他支持 WebTorrent 的节点组成群。<sup>[11](https://privacytools.io/app/webtorrent)</sup> 已有学术工作在该库基础上展开，例如一种将 WebTorrent 与 AES 分片加密以及用于分发解密密钥的 Solana 智能合约相结合的点对点视频流媒体方案，该方案指出中继节点数量随节点数呈对数增长。<sup>[12](https://www.jstage.jst.go.jp/article/transinf/E106.D/10/E106.D_2023EDP7027/_pdf)</sup> 还有人提出了一种 WebTorrent 专用的 DHT 变体，其工作方式类似 BitTorrent 的 BEP 5 DHT，但使用 WebRTC 传输而非 UDP。<sup>[13](https://github.com/nazar-pc/webtorrent-dht/blob/master/bep.rst)</sup>

## References

1. [webtorrent README, GitHub](https://github.com/webtorrent/webtorrent/blob/master/README.md)
2. [webtorrent/webtorrent repository, GitHub](https://github.com/webtorrent/webtorrent)
3. [Feross Aboukhadijeh Interview, AIM Interviews](https://aiminterviews.com/interview/feross-aboukhadijeh)
4. [webtorrent FAQ, GitHub](https://github.com/webtorrent/webtorrent/blob/master/docs/faq.md)
5. [WebTorrent Desktop](https://webtorrent.io/desktop/)
6. [Feross Aboukhadijeh bio](https://feross.org/about/)
7. [How does WebTorrent work? Issue #39, GitHub](https://github.com/webtorrent/webtorrent/issues/39)
8. [Releases · webtorrent/webtorrent, GitHub](https://github.com/webtorrent/webtorrent/releases)
9. [Configuration, PeerTube documentation](https://docs.joinpeertube.org/admin/configuration)
10. [Watch, share, download a video, PeerTube documentation](https://docs.joinpeertube.org/use/watch-video)
11. [WebTorrent Review, PrivacyTools.io](https://privacytools.io/app/webtorrent)
12. [P2P video streaming with WebTorrent and blockchain incentives, IEICE Transactions on Information and Systems](https://www.jstage.jst.go.jp/article/transinf/E106.D/10/E106.D_2023EDP7027/_pdf)
13. [webtorrent-dht BEP proposal, GitHub](https://github.com/nazar-pc/webtorrent-dht/blob/master/bep.rst)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 17, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Named software products and platforms › File-sharing, piracy, and adult websites

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/webtorrent

English original: https://www.edgepedia.org/webtorrent
