Skip to content

Commit 3be06d6

Browse files
committed
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!
1 parent 19ba81a commit 3be06d6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/websocket-tracker.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ function WebSocketTracker (client, announceUrl, opts) {
2525
self.destroyed = false
2626

2727
self._opts = opts
28+
2829
self._announceUrl = announceUrl
30+
if (self._announceUrl[self._announceUrl.length - 1] !== '/') self._announceUrl += '/'
31+
self._announceUrl += '?' + hat(40)
32+
2933
self._peers = {} // peers (offer id -> peer)
3034
self._socket = null
3135
self._intervalMs = self.client._intervalMs // use client interval initially
@@ -98,7 +102,7 @@ WebSocketTracker.prototype._openSocket = function () {
98102
self._onSocketDataBound = self._onSocketData.bind(self)
99103
self._onSocketCloseBound = self._onSocketClose.bind(self)
100104

101-
self._socket = new Socket(self._announceUrl + '?' + hat(40))
105+
self._socket = new Socket(self._announceUrl)
102106
self._socket.on('data', self._onSocketDataBound)
103107
self._socket.on('close', self._onSocketCloseBound)
104108
self._socket.on('error', self._onSocketErrorBound)

0 commit comments

Comments
 (0)