mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 20:21:36 +00:00
prevent two reconnect timers for running at same time
This commit is contained in:
parent
49025c1320
commit
89b9fb7f40
@ -29,6 +29,7 @@ function WebSocketTracker (client, announceUrl, opts) {
|
||||
|
||||
self.peers = {} // peers (offer id -> peer)
|
||||
self.socket = null
|
||||
|
||||
self.reconnecting = false
|
||||
self.retries = 0
|
||||
self.reconnectTimer = null
|
||||
@ -91,7 +92,9 @@ WebSocketTracker.prototype.destroy = function (cb) {
|
||||
var self = this
|
||||
if (!cb) cb = noop
|
||||
if (self.destroyed) return cb(null)
|
||||
|
||||
self.destroyed = true
|
||||
|
||||
clearInterval(self.interval)
|
||||
clearTimeout(self.reconnectTimer)
|
||||
|
||||
@ -319,6 +322,7 @@ WebSocketTracker.prototype._startReconnectTimer = function () {
|
||||
var ms = Math.floor(Math.random() * RECONNECT_VARIANCE) + Math.min(Math.pow(2, self.retries) * RECONNECT_MINIMUM, RECONNECT_MAXIMUM)
|
||||
|
||||
self.reconnecting = true
|
||||
clearTimeout(self.reconnectTimer)
|
||||
self.reconnectTimer = setTimeout(function () {
|
||||
self.retries++
|
||||
self._openSocket()
|
||||
|
Loading…
Reference in New Issue
Block a user