mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2025-01-18 12:11:36 +00:00
Revert "client: socketPool should not be shared across clients"
This reverts commit 3f3db7deb1
.
This commit is contained in:
parent
78722e0a05
commit
1dd1cc32da
@ -69,11 +69,6 @@ function Client (opts) {
|
||||
// See: https://github.com/feross/webtorrent-hybrid/issues/46
|
||||
self._wrtc = typeof opts.wrtc === 'function' ? opts.wrtc() : opts.wrtc
|
||||
|
||||
// Use a socket pool, so WebSocket tracker clients share WebSocket objects for
|
||||
// the same server. In practice, WebSockets are pretty slow to establish, so this
|
||||
// gives a nice performance boost, and saves browser resources.
|
||||
self._socketPool = {}
|
||||
|
||||
var announce = typeof opts.announce === 'string'
|
||||
? [ opts.announce ]
|
||||
: opts.announce == null ? [] : opts.announce
|
||||
|
@ -10,6 +10,11 @@ var Socket = require('simple-websocket')
|
||||
var common = require('../common')
|
||||
var Tracker = require('./tracker')
|
||||
|
||||
// Use a socket pool, so tracker clients share WebSocket objects for the same server.
|
||||
// In practice, WebSockets are pretty slow to establish, so this gives a nice performance
|
||||
// boost, and saves browser resources.
|
||||
var socketPool = {}
|
||||
|
||||
var RECONNECT_MINIMUM = 15 * 1000
|
||||
var RECONNECT_MAXIMUM = 30 * 60 * 1000
|
||||
var RECONNECT_VARIANCE = 30 * 1000
|
||||
@ -124,15 +129,15 @@ WebSocketTracker.prototype.destroy = function (cb) {
|
||||
self._onSocketDataBound = null
|
||||
self._onSocketCloseBound = null
|
||||
|
||||
if (self.client._socketPool[self.announceUrl]) {
|
||||
self.client._socketPool[self.announceUrl].consumers -= 1
|
||||
if (socketPool[self.announceUrl]) {
|
||||
socketPool[self.announceUrl].consumers -= 1
|
||||
}
|
||||
|
||||
// Other instances are using the socket, so there's nothing left to do here
|
||||
if (self.client._socketPool[self.announceUrl].consumers > 0) return cb()
|
||||
if (socketPool[self.announceUrl].consumers > 0) return cb()
|
||||
|
||||
var socket = self.client._socketPool[self.announceUrl]
|
||||
delete self.client._socketPool[self.announceUrl]
|
||||
var socket = socketPool[self.announceUrl]
|
||||
delete socketPool[self.announceUrl]
|
||||
socket.on('error', noop) // ignore all future errors
|
||||
socket.once('close', cb)
|
||||
|
||||
@ -177,11 +182,11 @@ WebSocketTracker.prototype._openSocket = function () {
|
||||
self._onSocketClose()
|
||||
}
|
||||
|
||||
self.socket = self.client._socketPool[self.announceUrl]
|
||||
self.socket = socketPool[self.announceUrl]
|
||||
if (self.socket) {
|
||||
self.client._socketPool[self.announceUrl].consumers += 1
|
||||
socketPool[self.announceUrl].consumers += 1
|
||||
} else {
|
||||
self.socket = self.client._socketPool[self.announceUrl] = new Socket(self.announceUrl)
|
||||
self.socket = socketPool[self.announceUrl] = new Socket(self.announceUrl)
|
||||
self.socket.consumers = 1
|
||||
self.socket.once('connect', self._onSocketConnectBound)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user