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 (and more) #515

Closed
wants to merge 31 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
53d6335
got tests for pause/resume to pass
whitef0x0 Nov 27, 2015
cd1d84c
added nice cli for seed quitting interface
whitef0x0 Nov 27, 2015
61d1afb
added resume/pause support for audio/video streaming
whitef0x0 Nov 27, 2015
c68d39d
got gracefulExit to stop hanging
whitef0x0 Nov 27, 2015
67c9c47
added disableSeeding option for torrent
whitef0x0 Nov 27, 2015
01a685a
added getBySearch method
whitef0x0 Nov 27, 2015
b003801
added documentation for getBySearch
whitef0x0 Nov 27, 2015
9f4768f
fixed cli for search
whitef0x0 Nov 27, 2015
9ceac78
added tests for addBySearch()
whitef0x0 Nov 27, 2015
2415418
got all tests to pass but one
whitef0x0 Nov 30, 2015
be0b718
got download /path/to/file cmd.js test to pass
whitef0x0 Dec 1, 2015
b1430c8
updated browser code
whitef0x0 Dec 2, 2015
3db0dad
fixed cmd
whitef0x0 Dec 2, 2015
488bcc9
updated minified build
whitef0x0 Dec 2, 2015
10f9cc2
added unit tests for torrent.js
whitef0x0 Dec 3, 2015
53ea5f1
added tests for appendTo
whitef0x0 Dec 4, 2015
af023ce
added .npmignore
whitef0x0 Dec 4, 2015
74382ee
got zuul tests to run
whitef0x0 Dec 4, 2015
341ed30
removed extraneous user stories
whitef0x0 Dec 4, 2015
428a9ac
added documentation for new methods to the README
whitef0x0 Dec 4, 2015
8752393
added test cli interface
whitef0x0 Dec 5, 2015
2737d3f
updated travis-ci build
whitef0x0 Dec 5, 2015
9067381
started travis-ci
whitef0x0 Dec 5, 2015
254eae0
fixed package.json and travis.yml; got travis-ci to pass
whitef0x0 Dec 5, 2015
7f03f39
added main property to bower.json
whitef0x0 Dec 5, 2015
cb9849c
added ignore to bower.json
whitef0x0 Dec 5, 2015
d82559d
removed search functionality
whitef0x0 Dec 5, 2015
7610325
removed bower
whitef0x0 Dec 5, 2015
4d44ccd
Create description.md
whitef0x0 Dec 11, 2015
9f56b0c
Update test.js
whitef0x0 Dec 11, 2015
82fffad
Added description of changes
whitef0x0 Dec 11, 2015
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.