Skip to content

Commit

Permalink
Make swarming opt-out (#2)
Browse files Browse the repository at this point in the history
* Make swarming opt-out

* Put usage in README

* Fix comment
  • Loading branch information
emilbayes authored and mafintosh committed Sep 27, 2017
1 parent 8691d91 commit 56eef46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -17,7 +17,12 @@ hypercored
For more info run

```
hypercored --help
Usage: hypercored [key?] [options]
--cwd [folder to run in]
--websockets [share over websockets as well]
--port [explicit websocket port]
--no-swarm [disable swarming]
```

## License
Expand Down
23 changes: 12 additions & 11 deletions index.js
Expand Up @@ -24,7 +24,8 @@ if (argv.help) {
'Usage: hypercored [key?] [options]\n\n' +
' --cwd [folder to run in]\n' +
' --websockets [share over websockets as well]\n' +
' --port [explicit websocket port]\n'
' --port [explicit websocket port]\n' +
' --no-swarm [disable swarming]\n'
)
process.exit(0)
}
Expand Down Expand Up @@ -60,17 +61,17 @@ server.on('request', function (req, res) {
}))
})

swarm(ar).on('listening', function () {
var self = this

if (argv.websockets) server.listen(port, onlisten)
else onlisten()
if (argv.swarm !== false) {
swarm(ar).on('listening', function () {
console.log('Swarm listening on port %d', this.address().port)
})
}

function onlisten () {
console.log('Swarm listening on port %d', self.address().port)
if (argv.websockets) console.log('WebSocket server listening on port %d', server.address().port)
}
})
if (argv.websockets === true) {
server.listen(port, function () {
console.log('WebSocket server listening on port %d', server.address().port)
})
}

function resolveAll (links, cb) {
var keys = []
Expand Down

0 comments on commit 56eef46

Please sign in to comment.