bittorrent-tracker/lib/client/tracker.js
2018-10-03 14:44:11 +02:00

31 lines
660 B
JavaScript

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