webtorrent/webtorrent

GitHub: webtorrent/webtorrent

一个同时支持 Node.js 和浏览器环境的纯 JavaScript 流式 BitTorrent 客户端,让网页无需插件即可实现点对点文件下载与视频流播放。

Stars: 31256 | Forks: 2809


WebTorrent
WebTorrent

流式 torrent 客户端。适用于 node.js 和 Web。

discord ci npm version npm downloads Standard - JavaScript Style Guide

Sponsored by    Socket - JavaScript open source supply chain security    Wormhole

**WebTorrent** 是一个用于 **node.js** 和**浏览器**的流式 torrent 客户端。没错, 就是浏览器。它完全使用 JavaScript 编写——作为 Web 的语言——因此同一套代码可以在两个运行环境中使用。 在 node.js 中,此模块是一个简单的 torrent 客户端,使用 TCP 和 UDP 与其他 torrent 客户端通信。 在浏览器中,WebTorrent 使用 **WebRTC**(数据通道)进行点对点(peer-to-peer)传输。 它可以**无需**浏览器插件、扩展或安装直接使用。这仅仅是 JavaScript™。注意:WebTorrent 在浏览器中**不**支持 UDP/TCP 节点。 只需在你的页面中包含 [`webtorrent.min.js`](https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js) 脚本 即可开始通过 WebRTC 使用 BitTorrent 协议获取文件,或者 配合 [browserify](http://browserify.org/) 或 [webpack](https://webpack.js.org/) 使用 `import WebTorrent from 'webtorrent'`。请查看下方的[演示应用](#who-is-using-webtorrent-today)和[代码示例](#usage)。 [![jsdelivr 下载量](https://data.jsdelivr.com/v1/package/npm/webtorrent/badge)](https://cdn.jsdelivr.net/npm/webtorrent@latest/webtorrent.min.js) 为了让 BitTorrent 能够在 WebRTC(这是 Web 上唯一可用的 P2P 传输协议)上运行,我们对协议进行了一些修改。因此,基于浏览器的 WebTorrent 客户端或**“Web 节点”**只能连接到支持 WebTorrent/WebRTC 的其他客户端。 要将文件做种(seed)给 Web 节点,请使用支持 WebTorrent 的客户端,例如 [WebTorrent Desktop][webtorrent-desktop],这是一个界面熟悉且能连接到 Web 节点的桌面客户端; [webtorrent-hybrid](https://github.com/webtorrent/webtorrent-hybrid),一个命令行程序; 或者 [Instant.io](https://instant.io/),一个网站。现有的 torrent 客户端(如 **Vuze**)已经[添加了对 WebTorrent 的支持](https://wiki.vuze.com/w/WebTorrent),因此它们可以同时连接普通节点*和* Web 节点。我们希望其他客户端也能效仿。 ![Network](https://webtorrent.io/img/network.png) ### 功能 - **适用于 node.js 和浏览器的 torrent 客户端**(同一个 npm 包!) - **速度极快** - 高效地同时下载**多个 torrent** - **纯 JavaScript** 实现(无原生依赖) - 将文件以**流**的形式公开 - 按需从网络获取分片,从而支持跳转播放(甚至在 torrent 下载完成之前) - 在顺序选择和最稀优分片选择策略之间无缝切换 - 支持高级 torrent 客户端特性 - 通过 **[ut_metadata](https://github.com/webtorrent/ut_metadata)** 支持 **magnet uri** - 通过 **[dht](https://github.com/webtorrent/bittorrent-dht)**、 **[tracker](https://github.com/webtorrent/bittorrent-tracker)**、 **[lsd](https://github.com/webtorrent/bittorrent-lsd)** 和 **[ut_pex](https://github.com/webtorrent/ut_pex)** 实现**节点发现(peer discovery)** - **[协议扩展 API](https://github.com/webtorrent/bittorrent-protocol#extension-api)** 可用于添加新扩展 - **全面的测试套件**(完全离线运行,因此可靠且快速) - 在此查看所有**[支持的 BEP](docs/bep_support.md)** #### 浏览器/WebRTC 环境功能 - **WebRTC 数据通道**,实现**无需插件**的轻量级点对点通信 - **没有信息孤岛。** WebTorrent 是面向**整个 Web** 的 P2P 网络。运行在一个域名上的 WebTorrent 客户端可以连接到任何其他域名上的客户端。 - 将视频 torrent 流式传输到 `