Constructor
new WebTorrent([opts])
Create a new WebTorrent instance.
Client configuration options
Static Properties
WebTorrent.WEBRTC_SUPPORT
Boolean indicating whether WebRTC is natively supported in the current environment.
WebTorrent.VERSION
String representing the current WebTorrent version.
Methods
client.add(torrentId, [opts], [ontorrent])
Start downloading a new torrent.
Can be:
- Magnet URI (string)
- Torrent file (Uint8Array)
- Info hash (hex string or Uint8Array)
- Parsed torrent object
- HTTP/HTTPS URL to a torrent file (string)
- Filesystem path to a torrent file (Node.js only)
Torrent-specific options. See options page for details.
Callback called when torrent is ready (has metadata)
Returns the torrent instance immediately (before metadata is available)
client.seed(input, [opts], [onseed])
Start seeding a new torrent.
Can be:
- Filesystem path to file or folder (string, Node.js only)
- W3C FileList object (browser only)
- W3C File/Blob object
- Typed array or array of numbers
- Node Buffer object
- Node Readable stream object
- Array of any of the above
Options for create-torrent and client.add combined
Called when client has begun seeding
Returns the torrent instance immediately
client.remove(torrentId, [opts], [callback])
Remove a torrent from the client. Destroy all connections to peers and delete all saved file metadata.
Torrent to remove
Called when torrent is fully destroyed
client.get(torrentId)
Returns the torrent with the given torrentId.
Torrent identifier
Promise that resolves to the torrent, or null if not found
client.destroy([callback])
Destroy the client, including all torrents and connections to peers.
Called when client has gracefully closed
client.createServer([opts], [force])
Create an HTTP server to serve torrent contents.
Force specific implementation
Server instance
client.throttleDownload(rate)
Sets the maximum download speed.
Speed in bytes/sec. Use
-1 to disable throttling.client.throttleUpload(rate)
Sets the maximum upload speed.
Speed in bytes/sec. Use
-1 to disable throttling.client.address()
Returns the address the client is listening on.
Address object with
address, family, and port propertiesProperties
client.torrents
Array of all torrents in the client
client.peerId
Client peer ID (hex string)
client.downloadSpeed
Total download speed for all torrents, in bytes/sec
client.uploadSpeed
Total upload speed for all torrents, in bytes/sec
client.progress
Total download progress for all active torrents, from 0 to 1
client.ratio
Aggregate seed ratio for all torrents (uploaded / downloaded)