2018-10-03 12:44:11 +00:00
|
|
|
const EventEmitter = require('events')
|
2015-07-29 08:47:09 +00:00
|
|
|
|
2018-10-03 12:44:11 +00:00
|
|
|
class Tracker extends EventEmitter {
|
|
|
|
constructor (client, announceUrl) {
|
|
|
|
super()
|
2015-07-29 08:47:09 +00:00
|
|
|
|
2018-10-03 12:44:11 +00:00
|
|
|
const self = this
|
|
|
|
self.client = client
|
|
|
|
self.announceUrl = announceUrl
|
2015-12-05 07:59:11 +00:00
|
|
|
|
2018-10-03 12:44:11 +00:00
|
|
|
self.interval = null
|
|
|
|
self.destroyed = false
|
|
|
|
}
|
2015-07-29 08:47:09 +00:00
|
|
|
|
2018-10-03 12:44:11 +00:00
|
|
|
setInterval (intervalMs) {
|
|
|
|
const self = this
|
|
|
|
if (intervalMs == null) intervalMs = self.DEFAULT_ANNOUNCE_INTERVAL
|
2015-07-29 08:47:09 +00:00
|
|
|
|
2018-10-03 12:44:11 +00:00
|
|
|
clearInterval(self.interval)
|
2015-07-29 08:47:09 +00:00
|
|
|
|
2018-10-03 12:44:11 +00:00
|
|
|
if (intervalMs) {
|
|
|
|
self.interval = setInterval(() => {
|
|
|
|
self.announce(self.client._defaultAnnounceOpts())
|
|
|
|
}, intervalMs)
|
|
|
|
if (self.interval.unref) self.interval.unref()
|
|
|
|
}
|
2015-07-29 08:47:09 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-03 12:44:11 +00:00
|
|
|
|
|
|
|
module.exports = Tracker
|