2015-07-29 08:47:09 +00:00
|
|
|
module.exports = Tracker
|
|
|
|
|
|
|
|
var EventEmitter = require('events').EventEmitter
|
|
|
|
var inherits = require('inherits')
|
|
|
|
|
|
|
|
inherits(Tracker, EventEmitter)
|
|
|
|
|
|
|
|
function Tracker (client, announceUrl) {
|
|
|
|
var self = this
|
|
|
|
EventEmitter.call(self)
|
|
|
|
self.client = client
|
|
|
|
self.announceUrl = announceUrl
|
2015-12-05 07:59:11 +00:00
|
|
|
|
2015-07-29 08:47:09 +00:00
|
|
|
self.interval = null
|
|
|
|
self.destroyed = false
|
|
|
|
}
|
|
|
|
|
|
|
|
Tracker.prototype.setInterval = function (intervalMs) {
|
|
|
|
var self = this
|
2015-07-29 09:12:14 +00:00
|
|
|
if (intervalMs == null) intervalMs = self.DEFAULT_ANNOUNCE_INTERVAL
|
2015-07-29 08:47:09 +00:00
|
|
|
|
|
|
|
clearInterval(self.interval)
|
|
|
|
|
|
|
|
if (intervalMs) {
|
|
|
|
var update = self.announce.bind(self, self.client._defaultAnnounceOpts())
|
|
|
|
self.interval = setInterval(update, intervalMs)
|
2015-08-23 22:11:48 +00:00
|
|
|
if (self.interval.unref) self.interval.unref()
|
2015-07-29 08:47:09 +00:00
|
|
|
}
|
|
|
|
}
|