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