mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-31 10:31: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.peers = {} // peers (offer id -> peer)
|
||||||
self.socket = null
|
self.socket = null
|
||||||
|
|
||||||
self.reconnecting = false
|
self.reconnecting = false
|
||||||
self.retries = 0
|
self.retries = 0
|
||||||
self.reconnectTimer = null
|
self.reconnectTimer = null
|
||||||
@ -91,7 +92,9 @@ WebSocketTracker.prototype.destroy = function (cb) {
|
|||||||
var self = this
|
var self = this
|
||||||
if (!cb) cb = noop
|
if (!cb) cb = noop
|
||||||
if (self.destroyed) return cb(null)
|
if (self.destroyed) return cb(null)
|
||||||
|
|
||||||
self.destroyed = true
|
self.destroyed = true
|
||||||
|
|
||||||
clearInterval(self.interval)
|
clearInterval(self.interval)
|
||||||
clearTimeout(self.reconnectTimer)
|
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)
|
var ms = Math.floor(Math.random() * RECONNECT_VARIANCE) + Math.min(Math.pow(2, self.retries) * RECONNECT_MINIMUM, RECONNECT_MAXIMUM)
|
||||||
|
|
||||||
self.reconnecting = true
|
self.reconnecting = true
|
||||||
|
clearTimeout(self.reconnectTimer)
|
||||||
self.reconnectTimer = setTimeout(function () {
|
self.reconnectTimer = setTimeout(function () {
|
||||||
self.retries++
|
self.retries++
|
||||||
self._openSocket()
|
self._openSocket()
|
||||||
|
Loading…
Reference in New Issue
Block a user