always produce valid urls with trailing /

Fixes this error:

ERROR: connection error to wss://tracker.webtorrent.io?1fe16837ed
ERROR: If you think this is a bug in webtorrent, report it!
This commit is contained in:
Feross Aboukhadijeh 2015-05-22 16:21:55 +02:00
parent 19ba81a989
commit 3be06d6684

View File

@ -25,7 +25,11 @@ function WebSocketTracker (client, announceUrl, opts) {
self.destroyed = false self.destroyed = false
self._opts = opts self._opts = opts
self._announceUrl = announceUrl self._announceUrl = announceUrl
if (self._announceUrl[self._announceUrl.length - 1] !== '/') self._announceUrl += '/'
self._announceUrl += '?' + hat(40)
self._peers = {} // peers (offer id -> peer) self._peers = {} // peers (offer id -> peer)
self._socket = null self._socket = null
self._intervalMs = self.client._intervalMs // use client interval initially self._intervalMs = self.client._intervalMs // use client interval initially
@ -98,7 +102,7 @@ WebSocketTracker.prototype._openSocket = function () {
self._onSocketDataBound = self._onSocketData.bind(self) self._onSocketDataBound = self._onSocketData.bind(self)
self._onSocketCloseBound = self._onSocketClose.bind(self) self._onSocketCloseBound = self._onSocketClose.bind(self)
self._socket = new Socket(self._announceUrl + '?' + hat(40)) self._socket = new Socket(self._announceUrl)
self._socket.on('data', self._onSocketDataBound) self._socket.on('data', self._onSocketDataBound)
self._socket.on('close', self._onSocketCloseBound) self._socket.on('close', self._onSocketCloseBound)
self._socket.on('error', self._onSocketErrorBound) self._socket.on('error', self._onSocketErrorBound)