bittorrent-tracker/lib/client/tracker.js
2018-10-03 15:06:38 +02:00

29 lines
616 B
JavaScript

const EventEmitter = require('events')
class Tracker extends EventEmitter {
constructor (client, announceUrl) {
super()
this.client = client
this.announceUrl = announceUrl
this.interval = null
this.destroyed = false
}
setInterval (intervalMs) {
if (intervalMs == null) intervalMs = this.DEFAULT_ANNOUNCE_INTERVAL
clearInterval(this.interval)
if (intervalMs) {
this.interval = setInterval(() => {
this.announce(this.client._defaultAnnounceOpts())
}, intervalMs)
if (this.interval.unref) this.interval.unref()
}
}
}
module.exports = Tracker