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

Next

got tests for pause/resume to pass

  • Loading branch information
whitef0x0 committed Nov 27, 2015
commit 53d63357b256207f71e002d0b295c1cb72af6061
@@ -264,6 +264,12 @@ function runDownload (torrentId) {

var torrent = client.add(torrentId, { path: argv.out })

torrent.on('paused', function (data) {
if (argv.quiet) return
clivas.clear()
clivas.line('{green:torrent paused}')
})

torrent.on('infoHash', function () {
function updateMetadata () {
var numPeers = torrent.swarm.numPeers
@@ -458,6 +464,12 @@ function runDownload (torrentId) {
}
}

function pauseDownload (torrent) {
}

function resumeDownload (torrent) {
}

function runSeed (input) {
if (path.extname(input).toLowerCase() === '.torrent' || /^magnet:/.test(input)) {
// `webtorrent seed` is meant for creating a new torrent based on a file or folder
@@ -142,7 +142,7 @@ WebTorrent.prototype.add =
WebTorrent.prototype.download = function (torrentId, opts, ontorrent) {
var self = this
if (self.destroyed) throw new Error('client is destroyed')
if (typeof opts === 'function') return self.add(torrentId, null, opts)
if (typeof opts === 'function') return self.add(torrentId, opts, null)
debug('add')
if (!opts) opts = {}
else opts = extend({}, opts)
@@ -172,6 +172,18 @@ WebTorrent.prototype.download = function (torrentId, opts, ontorrent) {
self.emit('listening', port, torrent)
})

torrent.on('paused', function (port) {
self.emit('paused', port, torrent)
})

torrent.on('resume', function (port) {
self.emit('resume', torrent)
})

torrent.on('infoHash', function () {
self.emit('infoHash', torrent)
})

torrent.on('ready', function () {
_ontorrent()
self.emit('torrent', torrent)
@@ -181,6 +193,25 @@ WebTorrent.prototype.download = function (torrentId, opts, ontorrent) {
return torrent
}

WebTorrent.prototype.pause = function(currentTorrent){
var self = this
if (self.destroyed) throw new Error('client is destroyed')

if (currentTorrent === null) throw new Error('torrent does not exist')

currentTorrent.pause();
}

WebTorrent.prototype.resume = function(currentTorrent){
var self = this
if (self.destroyed) throw new Error('client is destroyed')

if (currentTorrent === null) throw new Error('torrent does not exist')

currentTorrent.resume();
}


/**
* Start seeding a new file/folder.
* @param {string|File|FileList|Buffer|Array.<string|File|Buffer>} input
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.