Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pause/resume, refactored code, improved command line interface, etc #514

Closed
wants to merge 21 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

added documentation for new methods to the README

  • Loading branch information
whitef0x0 committed Dec 4, 2015
commit 428a9acee6b884b47caea1f35c25bed59fbbfc13
@@ -267,25 +267,45 @@ If you want access to the torrent object immediately in order to listen to event
metadata is fetched from the network, then use the return value of `client.add`. If you
just want the file data, then use `ontorrent` or the 'torrent' event.

#### `client.seed(input, [opts], [function onseed (torrent) {}])`
#### `client.addBySearch(torrentId, [opts], [function ontorrent (torrent) {}])`

Start seeding a new torrent.
Get torrent from most relevant result from a http://kat.cr query. Then start downloading a new torrent.

`input` can be any of the following:
`query` must be a string

- path to the file or folder on filesystem (string) (Node.js only)
- W3C [File](https://developer.mozilla.org/en-US/docs/Web/API/File) object (from an `<input>` or drag and drop)
- W3C [FileList](https://developer.mozilla.org/en-US/docs/Web/API/FileList) object (basically an array of `File` objects)
- Node [Buffer](http://nodejs.org/api/buffer.html) object (works in [the browser](https://www.npmjs.org/package/buffer))
If `opts` is specified, then the default options (shown below) will be overridden.

```js
{
announce: [], // Torrent trackers to use (added to list in .torrent or magnet uri)
path: String, // Folder to download files to (default=`/tmp/webtorrent/`)
store: Function // Custom chunk store (must follow [abstract-chunk-store](https://www.npmjs.com/package/abstract-chunk-store) API)
}
```

If `ontorrent` is specified, then it will be called when **this** torrent is ready to be
used (i.e. metadata is available). Note: this is distinct from the 'torrent' event which
will fire for **all** torrents.

If you want access to the torrent object immediately in order to listen to events as the
metadata is fetched from the network, then use the return value of `client.addBySearch`. If you
just want the file data, then use `ontorrent` or the 'torrent' event.

#### `client.pause(input, [function onpause (torrent) {}])`

Pause a torrent's current uploading and downloading

Or, an **array of `string`, `File`, or `Buffer` objects**.
`input` must be a:
- Torrent object (from /lib/torrent.js) that is part of the client

If `opts` is specified, it should contain the following types of options:
If `onpause` is specified, it will be called after the client is paused

- options for [create-torrent](https://github.com/feross/create-torrent#createtorrentinput-opts-function-callback-err-torrent-) (to allow configuration of the .torrent file that is created)
- options for `client.add` (see above)
#### `client.resume(input)`

If `onseed` is specified, it will be called when the client has begun seeding the file.
Resume a torrent's uploading and downloading

`input` must be a:
- Torrent object (from /lib/torrent.js) that is part of the client

#### `client.on('torrent', function (torrent) {})`

@@ -317,6 +337,24 @@ Seed ratio for all torrents in the client.

### torrent api

#### `torrent.disableSeeding(input)`

Disable seeding and disconnect all current leeching peers

#### `torrent.disableSeeding(input)`

Enable seeding and start broadcasting seed status to leeching peers

#### `torrent.pause([function onpause (torrent) {}])`

Pause a torrent's current uploading and downloading

If `onpause` is specified, it will be called after the client is paused

#### `torrent.resume()`

Resume a torrent's uploading and downloading

#### `torrent.infoHash`

Get the info hash of the torrent.
@@ -229,21 +229,23 @@ WebTorrent.prototype.download = function (torrentId, opts, ontorrent) {
return torrent
}

WebTorrent.prototype.pause = function (currentTorrent) {
WebTorrent.prototype.pause = function (currentTorrent, cb) {
var self = this

if (currentTorrent instanceof Torrent) self.emit('error', new Error('input must be a valid torrent')
if (self.destroyed) return self.emit('error', new Error('client is destroyed'))

if (currentTorrent === null) return self.emit('error', new Error('torrent does not exist'))

currentTorrent.pause()
currentTorrent.pause(cb)
}

WebTorrent.prototype.resume = function (currentTorrent) {
WebTorrent.prototype.resume = function (currentTorrent, cb) {
var self = this
if (self.destroyed) return self.emit('error', new Error('client is destroyed'))
if (currentTorrent === null) return self.emit('error', new Error('torrent does not exist'))

currentTorrent.resume()
currentTorrent.resume(cb)
}

/**
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.