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 test cli interface

  • Loading branch information
whitef0x0 committed Dec 5, 2015
commit 8752393ce0be6217d9ac3e69da48f25e61c7761f
@@ -6,5 +6,6 @@ node_js:
sudo: false
env:
global:
- IS_TRAVIS='true'
- secure: AJsEWFnWC5W8hcF3hJzm3PT7heazJpKg85xiSvIWVzLHZU/s0h4+WfJ6t0F9v3L4awaowm62vy8CRaxRkB4lJyJg+JK2K0QN7lNFGj2f8Jx2cFlVJ1IyY959GY4iUg66JrNj1yzS02+yQfweDngyifqzb7IlxnowiveDjUO2gyo=
- secure: hvihwLUqlPchrGFXKWFF7iKRugISU7r/gLBo6O63nPeg0OwnYqYcC2BnBWoSiOdu9oR5bM4a5u0os04XL+bP3dqt324g0uBTqvyyxD6NhBsphVFkUmdUH3HMe7IQY6JTns96KT/6UkQapKhIuW4CUDeidR+5NFKvyRdKIjSawS4=
@@ -1,18 +1,107 @@
#!/usr/bin/env node

var spawn = require('cross-spawn-async')
var minimist = require('minimist')
var fs = require('fs')
var path = require('path')
var clivas = require('clivas')

var runBrowserTests = !process.env.TRAVIS_PULL_REQUEST ||
process.env.TRAVIS_PULL_REQUEST === 'false'
var argv = minimist(process.argv.slice(2), {
alias: {
l: 'local',
b: 'browser',
s: 'standard'
},
boolean: [ // options that are always boolean
'local',
'standard',
'browser',
'help'
]
})

var runBrowserTests = (!process.env.TRAVIS_PULL_REQUEST ||
process.env.TRAVIS_PULL_REQUEST === 'false') && argv.local

var command = argv._[0]
if (argv.help || command === 'help') {
runHelp()
} else if (command === 'coverage' || command === 'test') {
runTest(command)
} else {
clivas.line('webtorrent-test: \'' + command + '\' is not a webtorrent-test command. See \'webtorrent-test --help\'')
}

var node = spawn('npm', ['run', 'test-node'], { stdio: 'inherit' })
node.on('close', function (code) {
if (code === 0 && runBrowserTests) {
var browser = spawn('npm', ['run', 'test-browser'], { stdio: 'inherit' })
browser.on('close', function (code) {
process.exit(code)
function runHelp () {
fs.readFileSync(path.join(__dirname, 'ascii-logo.txt'), 'utf8')
.split('\n')
.forEach(function (line) {
clivas.line('{bold:' + line.substring(0, 20) + '}{red:' + line.substring(20) + '}')
})

console.log(function () {
/*
Usage:
webtorrent-test [command] <options>
Example:
webtorrent-test test --local --browser
Commands:
test Run the nodejs test suite
coverage Generate test coverage data (via istanbul)
Options:
-l, --local run test suite for local development
-b, --browser run browser test suite (along with existing test suite)
-b, --standard run js `standard` code linting tool before test suite
*/
}.toString().split(/\n/).slice(2, -2).join('\n'))
process.exit(0)
}

function runTest (testType) {
var testCommand = testType
var browserTestCommand = 'test'

if (argv.local) {
if (testType === 'coverage') {
testCommand += '-local'
} else {
testCommand += '-node'
}

if (argv.browser) {
browserTestCommand += '-browser-local'
}
} else {
process.exit(code)
browserTestCommand += '-browser'
testCommand += '-node'
}
})

if (argv.standard) {
var node = spawn('sh', ['-c', 'node_modules/.bin/standard'], { stdio: 'inherit' })
node.on('close', function (code) {
if (code === 0) {
executeTest(testCommand, browserTestCommand)
}
})
} else {
executeTest(testCommand, browserTestCommand)
}

function executeTest (_command, _browserCommand) {
var node = spawn('npm', ['run', _command], { stdio: 'inherit' })
node.on('close', function (code) {
if (code === 0 && runBrowserTests && argv.browser) {
var browser = spawn('npm', ['run', _browserCommand], { stdio: 'inherit' })
browser.on('close', function (code) {
process.exit(code)
})
} else {
process.exit(code)
}
})
}
}
@@ -232,20 +232,22 @@ WebTorrent.prototype.download = function (torrentId, opts, ontorrent) {
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 (!(currentTorrent instanceof Torrent)) return self.emit('error', new Error('input for pause() 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(cb)
}

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

if (!(currentTorrent instanceof Torrent)) return self.emit('error', new Error('input for resume() 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.resume(cb)
currentTorrent.resume()
}

/**
@@ -8,7 +8,8 @@
"url": "http://feross.org/"
},
"bin": {
"webtorrent": "./bin/cmd.js"
"webtorrent": "./bin/cmd.js",
"webtorrent-test": "./bin/test.js"
},
"browser": {
"./lib/server.js": false,
@@ -76,7 +77,6 @@
"browserify": "^12.0.1",
"finalhandler": "^0.4.0",
"http-server": "^0.8.5",
"istanbul-combine": "^0.3.0",
"istanbul-coveralls": "^1.0.3",
"jsdom": "^7.1.1",
"run-auto": "^1.0.0",
@@ -116,12 +116,11 @@
"build": "browserify -s WebTorrent -e ./ | uglifyjs -m > webtorrent.min.js",
"build-debug": "browserify -s WebTorrent -e ./ > webtorrent.debug.js",
"size": "npm run build && cat webtorrent.min.js | gzip | wc -c",
"test-local": "standard && node ./bin/test.js",
"coverage": "istanbul cover -- tape test/*.js && istanbul-coveralls",
"coverage-local": "istanbul cover -- tape test/*.js && http-server coverage/client/report-html/ -p 6000 -a 127.0.0.1 && echo 'Istanbul coverage report served at 127.0.0.1:6000'",
"test": "standard && node ./bin/test.js && coverage",
"test-browser": "zuul -- test/browser/*.js",
"test-browser-local": "zuul --local 4000 -- test/browser/*.js",
"test-node": "tape test/*.js"
"coverage-node": "istanbul cover -- tape test/*.js && istanbul-coveralls",
"coverage-local": "istanbul cover -- tape test/*.js && http-server coverage/client/report-html/ -p 3000 -q && echo 'Istanbul coverage report served at 127.0.0.1:3000'",
"test-browser": "tape test/*.js && zuul -- test/browser/*.js",
"test-browser-local": "tape test/*.js && zuul --local 4000 -- test/browser/*.js",
"test-node": "tape test/*.js",
"test": "bin/test.js coverage --standard"
}
}
@@ -6,7 +6,7 @@ var WebTorrent = require('../')

var leaves = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
var leavesTorrent = parseTorrent(leaves)
var leavesBook = fs.readFileSync(__dirname + 'content/Leaves of Grass by Walt Whitman.epub')
var leavesBook = fs.readFileSync(__dirname + '/content/Leaves of Grass by Walt Whitman.epub')

var leavesMagnetURI = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=http%3A%2F%2Ftracker.bittorrent.am%2Fannounce&tr=http%3A%2F%2Ftracker.thepiratebay.org%2Fannounce&tr=udp%3A%2F%2Ffr33domtracker.h33t.com%3A3310%2Fannounce&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80'

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