From 8e2dbdc576d56d2fd05ba072db78cf20710cd9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rodr=C3=ADguez=20Baquero?= Date: Fri, 11 Mar 2016 04:12:09 -0300 Subject: [PATCH] Reconnect timeout increase lineally Minimum set at 15 seconds, each retry adds 30 seconds. --- lib/client/websocket-tracker.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/client/websocket-tracker.js b/lib/client/websocket-tracker.js index 773aa83..cd51aa5 100644 --- a/lib/client/websocket-tracker.js +++ b/lib/client/websocket-tracker.js @@ -15,8 +15,8 @@ var Tracker = require('./tracker') // boost, and saves browser resources. var socketPool = {} -var RECONNECT_VARIANCE = 30 * 1000 -var RECONNECT_MINIMUM = 5 * 1000 +var RECONNECT_MINIMUM = 15 * 1000 +var RECONNECT_RETRY = 30 * 1000 var OFFER_TIMEOUT = 50 * 1000 inherits(WebSocketTracker, Tracker) @@ -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._openSocket() } @@ -118,6 +119,7 @@ WebSocketTracker.prototype._onSocketConnect = function () { if (self.reconnecting) { self.reconnecting = false + self.retries = 0 self.announce(self.client._defaultAnnounceOpts()) } } @@ -233,10 +235,11 @@ WebSocketTracker.prototype._onSocketError = function (err) { WebSocketTracker.prototype._startReconnectTimer = function () { var self = this - var ms = Math.floor(Math.random() * RECONNECT_VARIANCE) + RECONNECT_MINIMUM + var ms = RECONNECT_MINIMUM + (self.retries * RECONNECT_RETRY) self.reconnecting = true var reconnectTimer = setTimeout(function () { + self.retries++ self._openSocket() }, ms) if (reconnectTimer.unref) reconnectTimer.unref()