@@ -8,6 +8,7 @@ var inherits = require('inherits')
88var once = require ( 'once' )
99var parallel = require ( 'run-parallel' )
1010var Peer = require ( 'simple-peer' )
11+ var Socks = require ( 'socks' )
1112var uniq = require ( 'uniq' )
1213var url = require ( 'url' )
1314
@@ -31,8 +32,7 @@ inherits(Client, EventEmitter)
3132 * @param {function } opts.getAnnounceOpts callback to provide data to tracker
3233 * @param {number } opts.rtcConfig RTCPeerConnection configuration object
3334 * @param {number } opts.wrtc custom webrtc impl (useful in node.js)
34- * @param {object } opts.httpAgent HTTP agent impl (used to proxy http requests in node.js)
35- * @param {object } opts.socksProxyOpts socks proxy options (used to proxy UDP requests in node.js)
35+ * @param {object } opts.proxyOpts proxy options (useful in node.js)
3636 */
3737function Client ( opts ) {
3838 var self = this
@@ -64,9 +64,16 @@ function Client (opts) {
6464
6565 self . _rtcConfig = opts . rtcConfig
6666 self . _wrtc = opts . wrtc
67- self . _httpAgent = opts . httpAgent
68- self . _socksProxyOpts = opts . socksProxyOpts
6967 self . _getAnnounceOpts = opts . getAnnounceOpts
68+ self . _proxyOpts = opts . proxyOpts
69+
70+ // Create HTTP agents from socks proxy if needed
71+ if ( self . _proxyOpts && self . _proxyOpts . socksProxy && ! self . _proxyOpts . httpAgent ) {
72+ self . _proxyOpts . httpAgent = new Socks . Agent ( self . _proxyOpts . socksProxy , false )
73+ }
74+ if ( self . _proxyOpts && self . _proxyOpts . socksProxy && ! self . _proxyOpts . httpsAgent ) {
75+ self . _proxyOpts . httpsAgent = new Socks . Agent ( self . _proxyOpts . socksProxy , true )
76+ }
7077
7178 debug ( 'new client %s' , self . infoHash )
7279
0 commit comments