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 tests for addBySearch()

  • Loading branch information
whitef0x0 committed Nov 27, 2015
commit 9ceac788a71e46e67d8bb3b9e8851c8ea6d9b39d
@@ -144,7 +144,7 @@ if (command === 'help' || argv.help) {
runDownload(/* torrentId */ argv._[1])
} else if (command === 'seed') {
runSeed(/* input */ argv._[1])
} else if (command === 'search'){
} else if (command === 'search') {
runSearch(/* query */ argv._[1])
} else if (command) {
// assume command is "download" when not specified
@@ -345,7 +345,6 @@ function runDownload (torrentId) {
return a.length > b.length ? a : b
}))


if (argv.select) {
var interactive = process.stdin.isTTY && !!process.stdin.setRawMode
if (interactive) {
@@ -468,39 +467,45 @@ function runDownload (torrentId) {
}

function runSearch (input_query) {
if(!input_query) {
var showUsage = function showUsage() {
if (!input_query) {
(function showUsage () {
var pathToBin = path.join(
path.relative(
process.cwd(),
path.dirname(process.argv[1])
),
path.basename(process.argv[1])
);
)

clivas.line('{green:Usage: }')
clivas.line('{green: '+process.argv[0] + ' ' + pathToBin + ' "query"'+'}')
};
}else{
clivas.line('{green: ' + process.argv[0] + ' ' + pathToBin + ' "query"' + '}')
})()
} else {
process.stdout.write(new Buffer('G1tIG1sySg==', 'base64')) // clear for drawing
clivas.line('Searching for {green:\''+input_query+'\'}...')
search(input_query).then(function(search_results) {
clivas.line('Searching for {green:\'' + input_query + '\'}...')
search(input_query).then(function (search_results) {
clivas.clear()
clivas.line('\n{bold: Search Results for {green: \''+input_query+'\' } }\n')
choices('Select your torrent (by number)', search_results.slice(0, 9).filter(function(r){ if(r.torrent || r.magnet){ return true } else { return false } }).map(function(r) { return r.name + ' [' + r.size + ' / ' + r.files + ' files] ' + r.seeds + '/' + r.leech }), function(index) {
if (index === null) {
return
}
//console.log(search_results[index])
if(/^magnet:/.test(search_results[index].magnet)) {
clivas.clear()
runDownload(search_results[index].magnet)
}else {
return
}

});
});
clivas.line('\n{bold: Search Results for {green: \'' + input_query + '\' } }\n')
choices('Select your torrent (by number)', search_results.slice(0, 9)
.filter(function (r) {
if (r.torrent || r.magnet) { return true }
return false
})
.map(function (r) {
return r.name + ' [' + r.size + ' / ' + r.files + ' files] ' + r.seeds + '/' + r.leech
}),
function (index) {
if (index === null) {
return
}
if (/^magnet:/.test(search_results[index].magnet)) {
clivas.clear()
runDownload(search_results[index].magnet)
} else {
return
}
})
})
}
}

@@ -528,44 +533,41 @@ function runSeed (input) {
})
}

var drawInterval
var drawInterval, cli
var commandMode = false
var lastInput = ''
var blockDraw = false
var cliInput = false


function drawTorrent (torrent) {

process.stdin.on('data', function(chunk) {
process.stdin.on('data', function (chunk) {
blockDraw = true

if (!cliInput && (chunk === 'q' || chunk === 's')) {
cliInput = true
process.stdin.setRawMode(false)
process.stdin.pause()
torrent.pause()
var cli = inquirer.prompt([{
cli = inquirer.prompt([{
type: 'input',
name: 'shouldQuit',
validate: function(input) {
if (input === 'Y' || input === 'y' || input === 'N' || input === 'n') {
// Pass the return value in the done callback
return true
}else{
return "Incorrect input. Please enter 'Y' or 'n'"
}
validate: function (input) {
if (input === 'Y' || input === 'y' || input === 'N' || input === 'n') {
// Pass the return value in the done callback
return true
} else {
return "Incorrect input. Please enter 'Y' or 'n'"
}
},
filter: function( input ) {
if(input === 'Y' || input === 'y') return true
else if(input === 'N' || input === 'n') return false
filter: function (input) {
if (input === 'Y' || input === 'y') return true
else if (input === 'N' || input === 'n') return false
},
message: 'Do you wish to quit? (Y/n)',
message: 'Do you wish to quit? (Y/n)'
}], function (answers) {
if(answers.shouldQuit){
if (answers.shouldQuit) {
torrent.resume()
gracefulExit()
}else{
} else {
process.stdin.setRawMode(true)
process.stdin.resume()
torrent.resume()
@@ -580,32 +582,33 @@ function drawTorrent (torrent) {
} else if (!cliInput && (chunk === 'p')) {
cliInput = true
process.stdin.setRawMode(false)
process.stdin.pause();
process.stdin.pause()
torrent.pause()
clivas.line('{green: torrent paused}')
var cli = inquirer.prompt([{

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'"
}
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'
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?',
message: 'Do you want to (r)esume or (q)uit seeding?'
}], function (answers) {
if(answers.inputChoice === 'quit'){
if (answers.inputChoice === 'quit') {
torrent.resume()
gracefulExit()
}else{
} else {
process.stdin.setRawMode(true)
process.stdin.resume();
process.stdin.resume()
torrent.resume()
blockDraw = false
cliInput = false
@@ -615,26 +618,23 @@ function drawTorrent (torrent) {
cli.rl.on('SIGINT', function () {
return gracefulExit()
})
}
else if(!cliInput){
setTimeout(function(){
} else if (!cliInput) {
setTimeout(function () {
blockDraw = false
draw()
},100)
}, 100)
}
});
})

if (!argv.quiet) {

process.stdout.write(new Buffer('G1tIG1sySg==', 'base64')) // clear for drawing
process.stdin.setEncoding('utf8');
process.stdin.setEncoding('utf8')
drawInterval = setInterval(draw, 500)
drawInterval.unref()

}

function draw () {
if(!blockDraw){
if (!blockDraw) {
var hotswaps = 0
torrent.on('hotswap', function () {
hotswaps += 1
@@ -739,7 +739,7 @@ function drawTorrent (torrent) {

clivas.line('{80:}')

if(commandMode){
if (commandMode) {
clivas.line('{green:command :}')
}
clivas.flush(true)
@@ -0,0 +1,78 @@
#Webtorrent User Story 1 -- Resume/Pause:
As a user, I want to be able to pause my torrent while seeding or downloading and be able to resume progress after pausing my torrent.

#Webtorrent User Story 2 -- Search:
As a user, I want to be able to find and download a torrent by searching torrents online.

#Webtorrent User Story 3 -- SMS Notification on Finish:
As a user, I want to be able to get an SMS message sent to a phone number I provide when my torrent is finished downloading.


PM = A x Size^b x EM

PM = 1.2*(0.10)^0.95*5 = .63months

###Size

`Size = 0.05 KLoC`
___Justification___: Our lines of code have been justified by the relative size of other modules of similar complexity that have already been written for this project.

###Scale Factor

`b= 0.95`
___Justification___: Our scale factor b is 0.95 which is a nearly global scale factor because we believe that much of the work will be almost linear as our project scales up in size. We will need to create an module to add to the project.

###Calibration Factor (A)

`A=1.7`

___Justification___: We think our calibration factor is this as it is an average of our self reflected skill and familiarity with the codebase, Javascript and with PDF conversion.

###Effort Multiplier (EM)

`EM=7`

___Justification___: We think our team will put a lot of effort due to the interest in the project and interest in Javascript.

####Scenario S1.1: After I have created a new Torrent, and it has started downloading,
When I call the pause() function
Then my torrent will pause
And then my torrent will stop downloading

####Scenario S1.2: After I have created a new Torrent,
And I have paused my torrent
When I call the resume() function
Then my torrent will resume downloading
And my torrent will pick up progress from last pause

####Scenario S1.3: After I have created a new Torrent,
And it has started downloading,
When I call the resume() function,
Then my RESUME will not execute

####Scenario S1.4: After I have created a new Torrent,
And it has been paused
When I call the pause() function,
Then my PAUSE will not execute,
And my Torrent will still be paused

####Scenario S1.5: After I have created a new Torrent,
And I have started downloading it ,
And my torrent has finished downloading
When I call the pause() function,
Then my PAUSE will not execute

####Scenario S2.1: After I have started the program,
When I call the search() function with a valid QUERY string
And there is at least one match for my QUERY string
Then it will return a torrent that is the first result in search query
And then it will start downloading the returned torrent

####Scenario S2.2: After I have started the program,
When I call the search() function with an invalid QUERY string
Then it will throw an error no torrent will be downloaded

####Scenario S2.3: After I have started the program,
When I call the search() function with a valid QUERY string
And there are no matches for my QUERY string
Then it will throw an error no torrent will be downloaded
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.