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

got gracefulExit to stop hanging

  • Loading branch information
whitef0x0 committed Nov 27, 2015
commit c68d39d814efb392155dfc3e1d1bbc398bea30db
@@ -264,12 +264,6 @@ 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
@@ -279,6 +273,7 @@ function runDownload (torrentId) {

if (!argv.quiet) {
updateMetadata()

torrent.on('wire', updateMetadata)
torrent.on('metadata', function () {
clivas.clear()
@@ -461,16 +456,12 @@ function runDownload (torrentId) {
})
}

process.stdin.setRawMode(true)
process.stdin.resume()
drawTorrent(torrent)
}
}

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
@@ -507,10 +498,11 @@ function drawTorrent (torrent) {
process.stdin.on('data', function(chunk) {
blockDraw = true

if (chunk === 'q' || chunk === 's') {
if (!cliInput && (chunk === 'q' || chunk === 's')) {
cliInput = true
process.stdin.setRawMode(false)
process.stdin.pause();
process.stdin.pause()
torrent.pause()
var cli = inquirer.prompt([{
type: 'input',
name: 'shouldQuit',
@@ -526,14 +518,53 @@ function drawTorrent (torrent) {
if(input === 'y') return true
else if(input === 'n') return false
},
message: 'Do you wish to stop seeding?',
message: 'Do you wish to quit? (Y/n)',
}], function (answers) {
if(answers.shouldQuit){
clearInterval(drawInterval)
drawInterval.unref()
torrent.resume()
gracefulExit()
}else{
process.stdin.setRawMode(true)
process.stdin.resume()
torrent.resume()
blockDraw = false
cliInput = false
}
})

cli.rl.on('SIGINT', function () {
return gracefulExit()
})
} else if (!cliInput && (chunk === 'p')) {
cliInput = true
process.stdin.setRawMode(false)
process.stdin.pause();
torrent.pause()
clivas.line('{green: torrent paused}')
var cli = inquirer.prompt([{
type: 'input',
name: 'inputChoice',
validate: function(input) {
if (input === 'r' || input === 'q') {
// Pass the return value in the done callback
return true
}else{
return "Incorrect input. Please enter 'r' or 'q'"
}
},
filter: function( input ) {
if(input === 'r') return 'resume'
else if(input === 'q') return 'quit'
},
message: 'Do you want to (r)esume or (q)uit seeding?',
}], function (answers) {
if(answers.inputChoice === 'quit'){
torrent.resume()
gracefulExit()
}else{
process.stdin.setRawMode(true)
process.stdin.resume();
torrent.resume()
blockDraw = false
cliInput = false
}
@@ -542,7 +573,8 @@ function drawTorrent (torrent) {
cli.rl.on('SIGINT', function () {
return gracefulExit()
})
}else if(!cliInput){
}
else if(!cliInput){
setTimeout(function(){
blockDraw = false
draw()
@@ -251,7 +251,7 @@ Torrent.prototype._onPausedTorrent = function (parsedTorrent) {

self.files.forEach(function(file){
file.emit('paused')
}
})

self.on('resume', function(stream) { self._onResume(parsedTorrent); });
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.