mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-09 15:51:35 +00:00
31 lines
660 B
JavaScript
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
|