Skip to content

Commit 80f8986

Browse files
committed
Provide context data to getAnnounceOpts
1 parent 40707a1 commit 80f8986

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
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

@@ -296,6 +296,6 @@ Client.prototype._defaultAnnounceOpts = function (opts) {
296296
if (opts.uploaded == null) opts.uploaded = 0
297297
if (opts.downloaded == null) opts.downloaded = 0
298298

299-
if (self._getAnnounceOpts) opts = extend(opts, self._getAnnounceOpts())
299+
if (self._getAnnounceOpts) opts = extend(opts, self._getAnnounceOpts(opts))
300300
return opts
301301
}

0 commit comments

Comments
 (0)