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

#411 Choose random port when port not specified #462

Closed
wants to merge 6 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

Choose random port if port not specified

  • Loading branch information
Krizz committed Oct 14, 2015
commit cb85e1226023b66755c48a6f448c6785baf29d79
@@ -14,6 +14,7 @@ var path = require('path')
var prettyBytes = require('pretty-bytes')
var WebTorrent = require('../')
var zeroFill = require('zero-fill')
var grop = require('grop')

process.title = 'WebTorrent'

@@ -67,10 +68,7 @@ var argv = minimist(process.argv.slice(2), {
'subtitles',
'on-done',
'on-exit'
],
default: {
port: 8000
}
]
})

if (process.env.DEBUG || argv.stdout) {
@@ -310,10 +308,19 @@ function runDownload (torrentId) {

// Start http server
server = torrent.createServer()
server.listen(argv.port, function () {
if (torrent.ready) onReady()
else torrent.once('ready', onReady)
var port;

// Find available port
grop(function (availablePort) {
// if port is specified the use that
port = argv.port || availablePort;
server.listen(port, function () {
if (torrent.ready) onReady()
else torrent.once('ready', onReady)
})
})


server.once('connection', function () {
serving = true
})
@@ -366,8 +373,8 @@ function runDownload (torrentId) {

function onSelection (index) {
href = (argv.airplay || argv.chromecast || argv.xbmc)
? 'http://' + networkAddress() + ':' + argv.port + '/' + index
: 'http://localhost:' + argv.port + '/' + index
? 'http://' + networkAddress() + ':' + port + '/' + index
: 'http://localhost:' + port + '/' + index

if (playerName) torrent.files[index].select()
if (argv.stdout) torrent.files[index].createReadStream().pipe(process.stdout)
@@ -33,6 +33,7 @@
"end-of-stream": "^1.0.0",
"executable": "^1.1.0",
"fs-chunk-store": "^1.3.4",
"grop": "^0.1.0",
"hat": "0.0.3",
"immediate-chunk-store": "^1.0.7",
"inherits": "^2.0.1",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.