Skip to content

Commit b21d2cc

Browse files
Updated docs to better match default server config (webtorrent#405)
* Updated docs to better match default server config * docs: updated to more recent version * docs: Changed var to const * Update README.md Co-authored-by: Diego Rodríguez Baquero <[email protected]>
1 parent b0227c3 commit b21d2cc

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

README.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ client.on('scrape', function (data) {
182182
To start a BitTorrent tracker server to track swarms of peers:
183183

184184
```js
185-
var Server = require('bittorrent-tracker').Server
185+
const Server = require('bittorrent-tracker').Server
186186

187-
var server = new Server({
187+
const server = new Server({
188188
udp: true, // enable udp server? [default=true]
189189
http: true, // enable http server? [default=true]
190190
ws: true, // enable websocket server? [default=true]
191191
stats: true, // enable web-based statistics? [default=true]
192-
trustProxy: false // enable trusting x-forwarded-for header for remote IP [default=false]
192+
trustProxy: false, // enable trusting x-forwarded-for header for remote IP [default=false]
193193
filter: function (infoHash, params, cb) {
194194
// Blacklist/whitelist function for allowing/disallowing torrents. If this option is
195195
// omitted, all torrents are allowed. It is possible to interface with a database or
@@ -201,7 +201,7 @@ var server = new Server({
201201

202202
// This example only allows one torrent.
203203

204-
var allowed = (infoHash === 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa')
204+
const allowed = (infoHash === 'aaa67059ed6bd08362da625b3ae77f6f4a075aaa')
205205
if (allowed) {
206206
// If the callback is passed `null`, the torrent will be allowed.
207207
cb(null)
@@ -230,12 +230,34 @@ server.on('warning', function (err) {
230230

231231
server.on('listening', function () {
232232
// fired when all requested servers are listening
233-
console.log('listening on http port:' + server.http.address().port)
234-
console.log('listening on udp port:' + server.udp.address().port)
233+
234+
// HTTP
235+
const httpAddr = server.http.address()
236+
const httpHost = httpAddr.address !== '::' ? httpAddr.address : 'localhost'
237+
const httpPort = httpAddr.port
238+
console.log(`HTTP tracker: http://${httpHost}:${httpPort}/announce`)
239+
240+
// UDP
241+
const udpAddr = server.udp.address()
242+
const udpHost = udpAddr.address
243+
const udpPort = udpAddr.port
244+
console.log(`UDP tracker: udp://${udpHost}:${udpPort}`)
245+
246+
// WS
247+
const wsAddr = server.http.address()
248+
const wsHost = wsAddr.address !== '::' ? wsAddr.address : 'localhost'
249+
const wsPort = wsAddr.port
250+
console.log(`WebSocket tracker: ws://${wsHost}:${wsPort}`)
251+
235252
})
236253

254+
237255
// start tracker server listening! Use 0 to listen on a random free port.
238-
server.listen(port, hostname, onlistening)
256+
const port = 0
257+
const hostname = "localhost"
258+
server.listen(port, hostname, () => {
259+
// Do something on listening...
260+
})
239261

240262
// listen for individual tracker messages from peers:
241263

0 commit comments

Comments
 (0)