Skip to content

Commit 0a486c4

Browse files
committed
Merge branch 'torrent-announce-opts'
2 parents fe8db47 + accce99 commit 0a486c4

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ var requiredOpts = {
5959
}
6060

6161
var optionalOpts = {
62-
getAnnounceOpts: function () {
62+
getAnnounceOpts: function (opts) {
6363
// Provide a callback that will be called whenever announce() is called
64-
// internally (on timer), or by the user
64+
// internally (on timer), or by the user.
65+
// this refers to the tracker and opts to the current announce options.
6566
return {
6667
uploaded: 0,
6768
downloaded: 0,

client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function Client (opts) {
6161
self.destroyed = false
6262

6363
self._port = opts.port
64-
self._getAnnounceOpts = opts.getAnnounceOpts
64+
self._getAnnounceOpts = opts.getAnnounceOpts && opts.getAnnounceOpts.bind(self)
6565
self._rtcConfig = opts.rtcConfig
6666
self._userAgent = opts.userAgent
6767

@@ -291,6 +291,6 @@ Client.prototype._defaultAnnounceOpts = function (opts) {
291291
if (opts.uploaded == null) opts.uploaded = 0
292292
if (opts.downloaded == null) opts.downloaded = 0
293293

294-
if (self._getAnnounceOpts) opts = extend(opts, self._getAnnounceOpts())
294+
if (self._getAnnounceOpts) opts = extend(opts, self._getAnnounceOpts(opts))
295295
return opts
296296
}

test/client.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,18 @@ test('ws: client.announce() with params', function (t) {
301301
})
302302

303303
function testClientGetAnnounceOpts (t, serverType) {
304-
t.plan(5)
304+
t.plan(7)
305305

306306
common.createServer(t, serverType, function (server, announceUrl) {
307307
var client = new Client({
308308
infoHash: fixtures.leaves.parsedTorrent.infoHash,
309309
announce: announceUrl,
310310
peerId: peerId1,
311311
port: port,
312-
getAnnounceOpts: function () {
312+
getAnnounceOpts: function (opts) {
313313
return {
314+
infoHash: this.infoHash,
315+
optsDL: opts.downloaded,
314316
testParam: 'this is a test'
315317
}
316318
},
@@ -319,6 +321,8 @@ function testClientGetAnnounceOpts (t, serverType) {
319321

320322
server.on('start', function (peer, params) {
321323
t.equal(params.testParam, 'this is a test')
324+
t.equal(params.infoHash, fixtures.leaves.parsedTorrent.infoHash)
325+
t.equal(params.optsDL, params.downloaded)
322326
})
323327

324328
if (serverType === 'ws') common.mockWebsocketTracker(client)

0 commit comments

Comments
 (0)