@@ -30,6 +30,7 @@ inherits(Client, EventEmitter)
3030 * @param {number } opts.port torrent client listening port
3131 * @param {function } opts.getAnnounceOpts callback to provide data to tracker
3232 * @param {number } opts.rtcConfig RTCPeerConnection configuration object
33+ * @param {number } opts.userAgent User-Agent header for http requests
3334 * @param {number } opts.wrtc custom webrtc impl (useful in node.js)
3435 */
3536function Client ( opts ) {
@@ -43,7 +44,6 @@ function Client (opts) {
4344 if ( ! opts . announce ) throw new Error ( 'Option `announce` is required' )
4445 if ( ! process . browser && ! opts . port ) throw new Error ( 'Option `port` is required' )
4546
46- // required
4747 self . peerId = typeof opts . peerId === 'string'
4848 ? opts . peerId
4949 : opts . peerId . toString ( 'hex' )
@@ -56,39 +56,35 @@ function Client (opts) {
5656 self . _infoHashBuffer = Buffer . from ( self . infoHash , 'hex' )
5757 self . _infoHashBinary = self . _infoHashBuffer . toString ( 'binary' )
5858
59- self . _port = opts . port
59+ debug ( 'new client %s' , self . infoHash )
6060
6161 self . destroyed = false
6262
63- self . _rtcConfig = opts . rtcConfig
63+ self . _port = opts . port
6464 self . _getAnnounceOpts = opts . getAnnounceOpts
65- self . _wrtc = opts . wrtc
65+ self . _rtcConfig = opts . rtcConfig
66+ self . _userAgent = opts . userAgent
6667
6768 // Support lazy 'wrtc' module initialization
6869 // See: https://github.com/feross/webtorrent-hybrid/issues/46
69- if ( typeof self . _wrtc === 'function' ) self . _wrtc = self . _wrtc ( )
70-
71- debug ( 'new client %s' , self . infoHash )
72-
73- var webrtcSupport = self . _wrtc !== false && ( ! ! self . _wrtc || Peer . WEBRTC_SUPPORT )
70+ self . _wrtc = typeof opts . wrtc === 'function' ? opts . wrtc ( ) : opts . wrtc
7471
75- var announce = ( typeof opts . announce === 'string' )
72+ var announce = typeof opts . announce === 'string'
7673 ? [ opts . announce ]
77- : opts . announce == null
78- ? [ ]
79- : opts . announce
74+ : opts . announce == null ? [ ] : opts . announce
8075
76+ // Remove trailing slash from trackers to catch duplicates
8177 announce = announce . map ( function ( announceUrl ) {
8278 announceUrl = announceUrl . toString ( )
8379 if ( announceUrl [ announceUrl . length - 1 ] === '/' ) {
84- // remove trailing slash from trackers to catch duplicates
8580 announceUrl = announceUrl . substring ( 0 , announceUrl . length - 1 )
8681 }
8782 return announceUrl
8883 } )
89-
9084 announce = uniq ( announce )
9185
86+ var webrtcSupport = self . _wrtc !== false && ( ! ! self . _wrtc || Peer . WEBRTC_SUPPORT )
87+
9288 self . _trackers = announce
9389 . map ( function ( announceUrl ) {
9490 var protocol = url . parse ( announceUrl ) . protocol
0 commit comments