Skip to content

Commit eb854e8

Browse files
committed
Ability to provide callback function to provide stats for announce
1 parent 60387dd commit eb854e8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

client.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function Client (peerId, port, torrent, opts) {
5454
self._rtcConfig = opts.rtcConfig
5555
self._wrtc = opts.wrtc
5656
self._userAgent = opts.userAgent
57+
self._statsForAnnounce = opts.statsForAnnounce
5758

5859
debug('new client %s', self._infoHashHex)
5960

@@ -263,8 +264,10 @@ Client.prototype._defaultAnnounceOpts = function (opts) {
263264

264265
if (opts.numwant == null) opts.numwant = common.DEFAULT_ANNOUNCE_PEERS
265266

266-
if (opts.uploaded == null) opts.uploaded = 0
267-
if (opts.downloaded == null) opts.downloaded = 0
267+
var providedStats = self._statsForAnnounce ? self._statsForAnnounce() : {}
268+
269+
if (opts.uploaded == null) opts.uploaded = providedStats.uploaded || 0
270+
if (opts.downloaded == null) opts.downloaded = providedStats.downloaded || 0
268271

269272
if (opts.left == null && self.torrentLength != null) {
270273
opts.left = self.torrentLength - opts.downloaded

0 commit comments

Comments
 (0)