bittorrent-tracker/lib/client/tracker.js

29 lines
609 B
JavaScript
Raw Normal View History

import EventEmitter from '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 13:06:38 +00:00
this.client = client
this.announceUrl = announceUrl
2018-10-03 13:06:38 +00:00
this.interval = null
this.destroyed = false
2018-10-03 12:44:11 +00:00
}
2015-07-29 08:47:09 +00:00
2018-10-03 12:44:11 +00:00
setInterval (intervalMs) {
2018-10-03 13:06:38 +00:00
if (intervalMs == null) intervalMs = this.DEFAULT_ANNOUNCE_INTERVAL
2015-07-29 08:47:09 +00:00
2018-10-03 13:06:38 +00:00
clearInterval(this.interval)
2015-07-29 08:47:09 +00:00
2018-10-03 12:44:11 +00:00
if (intervalMs) {
2018-10-03 13:06:38 +00:00
this.interval = setInterval(() => {
this.announce(this.client._defaultAnnounceOpts())
2018-10-03 12:44:11 +00:00
}, intervalMs)
2018-10-03 13:06:38 +00:00
if (this.interval.unref) this.interval.unref()
2018-10-03 12:44:11 +00:00
}
2015-07-29 08:47:09 +00:00
}
}
2018-10-03 12:44:11 +00:00
export default Tracker