Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

⚡️ Streaming torrent client for the web

License

NotificationsYou must be signed in to change notification settings

webtorrent/webtorrent

Repository files navigation


WebTorrent
WebTorrent

The streaming torrent client. For node.js and the web.

discordcinpm versionnpm downloadsStandard - JavaScript Style Guide

Sponsored by    Socket - JavaScript open source supply chain security    Wormhole

WebTorrent is a streaming torrent client fornode.js and thebrowser. YEP,THAT'S RIGHT. THE BROWSER. It's written completely in JavaScript – the language of the web– so the same code works in both runtimes.

In node.js, this module is a simple torrent client, using TCP and UDP to talk toother torrent clients.

In the browser, WebTorrent usesWebRTC (data channels) for peer-to-peer transport.It can be usedwithout browser plugins, extensions, or installations. It's JustJavaScript™. Note: WebTorrent doesnot support UDP/TCP peers in browser.

Simply include thewebtorrent.min.js scripton your page to start fetching files over WebRTC using the BitTorrent protocol, orimport WebTorrent from 'webtorrent' withbrowserify orwebpack. Seedemo apps andcode examples below.

jsdelivr download count

To make BitTorrent work over WebRTC (which is the only P2P transport that works on theweb) we made some protocol changes. Therefore, a browser-based WebTorrent client or"webpeer" can only connect to other clients that support WebTorrent/WebRTC.

To seed files to web peers, use a client that supports WebTorrent, e.g.WebTorrent Desktop, a desktop client with afamiliar UI that can connect to web peers,webtorrent-hybrid, a command line program,orInstant.io, a website. Established torrent clients likeVuze havealready added WebTorrent support sothey can connect to both normaland web peers. We hope other clients will follow.

Network

Features

  • Torrent client for node.js & the browser (same npm package!)
  • Insanely fast
  • Downloadmultiple torrents simultaneously, efficiently
  • Pure Javascript (no native dependencies)
  • Exposes files asstreams
    • Fetches pieces from the network on-demand so seeking is supported (even before torrent is finished)
    • Seamlessly switches between sequential and rarest-first piece selection strategy
  • Supports advanced torrent client features
  • Comprehensive test suite (runs completely offline, so it's reliable and fast)
  • Check all thesupported BEPs here

Browser/WebRTC environment features

  • WebRTC data channels for lightweight peer-to-peer communication withno plugins
  • No silos. WebTorrent is a P2P network for theentire web. WebTorrent clientsrunning on one domain can connect to clients on any other domain.
  • Stream video torrents into a<video> tag (webm, mkv, mp4, ogv, mov, etc (AV1, H264, HEVC*, VP8, VP9, AAC, FLAC, MP3, OPUS, Vorbis, etc))
  • Supports Chrome, Firefox, Opera and Safari.

Install

To install WebTorrent for use in node or the browser withimport WebTorrent from 'webtorrent', run:

npm install webtorrent

To install awebtorrentcommand line program, run:

npm install webtorrent-cli -g

To install a WebTorrent desktop application for Mac, Windows, or Linux, seeWebTorrent Desktop.

Ways to help

Who is using WebTorrent today?

Lots of folks!

WebTorrent API Documentation

Read the full API Documentation.

Usage

WebTorrent is the first BitTorrent client that works in the browser, using open webstandards (no plugins, just HTML5 and WebRTC)! It's easy to get started!

In the browser

Downloading a file is simple:
importWebTorrentfrom'webtorrent'constclient=newWebTorrent()constmagnetURI='...'client.add(magnetURI,torrent=>{// Got torrent metadata!console.log('Client is downloading:',torrent.infoHash)for(constfileoftorrent.files){document.body.append(file.name)}})
Seeding a file is simple, too:
importdragDropfrom'drag-drop'importWebTorrentfrom'webtorrent'constclient=newWebTorrent()// When user drops files on the browser, create a new torrent and start seeding it!dragDrop('body',files=>{client.seed(files,torrent=>{console.log('Client is seeding:',torrent.infoHash)})})

There are more examples indocs/get-started.md.

Browserify

WebTorrent works great withbrowserify, an npm package that letsyou usenode-style require() to organize your browser code and load modules installed bynpm (as seen in the previous examples).

Webpack

WebTorrent also works withwebpack, another modulebundler. However, webpack requires extra configuration which you can find inthe webpack bundle config used by webtorrent.

Or, you can just use the pre-built version viaimport WebTorrent from 'webtorrent/dist/webtorrent.min.js' and skip the webpack configuration.

Script tag

WebTorrent is also available as a standalone script(webtorrent.min.js) which exposesWebTorrent on thewindowobject, so it can be used with just a script tag:

<scripttype='module'>importWebTorrentfrom'webtorrent.min.js'</script>

The WebTorrent script is also hosted on fast, reliable CDN infrastructure (Cloudflare andMaxCDN) for easy inclusion on your site:

<scripttype='module'>importWebTorrentfrom'https://esm.sh/webtorrent'</script>
Chrome App

If you want to use WebTorrent in aChrome App, you can include thefollowing script:

<scripttype='module'>importWebTorrentfrom'webtorrent.chromeapp.js'</script>

Be sure to enable thechrome.sockets.udp andchrome.sockets.tcp permissions!

In Node.js

WebTorrent also works in node.js, using thesame npm package! It's mad science!

NOTE: To connect to "web peers" (browsers) in addition to normal BitTorrent peers, usewebtorrent-hybrid which includes WebRTCsupport for node.

As a command line app

WebTorrent is also available as acommand line app. Here's how to use it:

$ npm install webtorrent-cli -g$ webtorrent --help

To download a torrent:

$ webtorrent magnet_uri

To stream a torrent to a device likeAirPlay orChromecast, just pass a flag:

$ webtorrent magnet_uri --airplay

There are many supported streaming options:

--airplay               Apple TV--chromecast            Chromecast--mplayer               MPlayer--mpv                   MPV--omx [jack]            omx [default: hdmi]--vlc                   VLC--xbmc                  XBMC--stdout                standard out [implies --quiet]

In addition to magnet uris, WebTorrent supportsmany ways to specify a torrent.

Talks about WebTorrent

Modules

Most of the active development is happening inside of small npm packages which are used by WebTorrent.

The Node Way™

"When applications are done well, they are just the really application-specific, brackish residue that can't be so easily abstracted away. All the nice, reusable components sublimate away onto github and npm where everybody can collaborate to advance the commons." — substack from"how I write modules"

node.js is shiny

Modules

These are the main modules that make up WebTorrent:

moduletestsversiondescription
webtorrenttorrent client (this module)
bittorrent-dhtdistributed hash table client
bittorrent-peerididentify client name/version
bittorrent-protocolbittorrent protocol stream
bittorrent-trackerbittorrent tracker server/client
bittorrent-lsdbittorrent local service discovery
create-torrentcreate .torrent files
magnet-uriparse magnet uris
parse-torrentparse torrent identifiers
torrent-discoveryfind peers via dht, tracker, and lsd
ut_metadatametadata for magnet uris (protocol extension)
ut_pexpeer discovery (protocol extension)

Enable debug logs

Innode, enable debug logs by setting theDEBUG environment variable to the name of themodule you want to debug (e.g.bittorrent-protocol, or* to printall logs).

DEBUG=* webtorrent

In thebrowser, enable debug logs by running this in the developer console:

localStorage.setItem('debug','*')

Disable by running this:

localStorage.removeItem('debug')

License

MIT. Copyright (c)Feross Aboukhadijeh andWebTorrent, LLC.


[8]ページ先頭

©2009-2025 Movatter.jp