@@ -55,16 +55,16 @@ npm install bittorrent-tracker
5555To connect to a tracker, just do this:
5656
5757``` js
58- var Client = require ( ' bittorrent-tracker' )
58+ import Client from ' bittorrent-tracker'
5959
60- var requiredOpts = {
60+ const requiredOpts = {
6161 infoHash: new Buffer (' 012345678901234567890' ), // hex string or Buffer
6262 peerId: new Buffer (' 01234567890123456789' ), // hex string or Buffer
6363 announce: [], // list of tracker server urls
6464 port: 6881 // torrent client port, (in browser, optional)
6565}
6666
67- var optionalOpts = {
67+ const optionalOpts = {
6868 // RTCPeerConnection config object (only used in browser)
6969 rtcConfig: {},
7070 // User-Agent header for http requests
@@ -81,48 +81,24 @@ var optionalOpts = {
8181 customParam: ' blah' // custom parameters supported
8282 }
8383 },
84- // Proxy config object
84+ // Proxy options (used to proxy requests in node)
8585 proxyOpts: {
86- // Socks proxy options (used to proxy requests in node)
87- socksProxy: {
88- // Configuration from socks module (https://github.com/JoshGlazebrook/socks)
89- proxy: {
90- // IP Address of Proxy (Required)
91- ipaddress: " 1.2.3.4" ,
92- // TCP Port of Proxy (Required)
93- port: 1080 ,
94- // Proxy Type [4, 5] (Required)
95- // Note: 4 works for both 4 and 4a.
96- // Type 4 does not support UDP association relay
97- type: 5 ,
98-
99- // SOCKS 4 Specific:
100-
101- // UserId used when making a SOCKS 4/4a request. (Optional)
102- userid: " someuserid" ,
103- password: " somepassword" ,
104- // SOCKS 5 Specific:
105-
106- // Authentication used for SOCKS 5 (when it's required) (Optional)
107- authentication: {
108- username: " Josh" ,
109- password: " somepassword"
110- }
111- },
112-
113- // Amount of time to wait for a connection to be established. (Optional)
114- // - defaults to 10000ms (10 seconds)
115- timeout: 10000
116- },
117- // NodeJS HTTP agents (used to proxy HTTP and Websocket requests in node)
118- // For HTTP trackers this is either an undici Agent if using Node16 or later, or http.Agent if using versions prior to Node 16
119- // Populated with Socks.Agent if socksProxy is provided
120- httpAgent: {},
121- httpsAgent: {}
86+ // For WSS trackers this is always a http.Agent
87+ // For UDP trackers this is an object of options for the Socks Connection
88+ // For HTTP trackers this is either an undici Agent if using Node16 or later, or http.Agent if using versions prior to Node 16, ex:
89+ // import Socks from 'socks'
90+ // proxyOpts.socksProxy = new Socks.Agent(optionsObject, isHttps)
91+ // or if using Node 16 or later
92+ // import { socksDispatcher } from 'fetch-socks'
93+ // proxyOpts.socksProxy = socksDispatcher(optionsObject)
94+ socksProxy: new SocksProxy (socksOptionsObject),
95+ // Populated with socksProxy if it's provided
96+ httpAgent: new http.Agent (agentOptionsObject),
97+ httpsAgent: new https.Agent (agentOptionsObject)
12298 },
12399}
124100
125- var client = new Client (requiredOpts)
101+ const client = new Client (requiredOpts)
126102
127103client .on (' error' , function (err ) {
128104 // fatal client error!
@@ -183,7 +159,7 @@ client.on('scrape', function (data) {
183159To start a BitTorrent tracker server to track swarms of peers:
184160
185161``` js
186- const Server = require ( ' bittorrent-tracker' ). Server
162+ import { Server } from ' bittorrent-tracker'
187163
188164const server = new Server ({
189165 udp: true , // enable udp server? [default=true]
@@ -290,7 +266,7 @@ The http server will handle requests for the following paths: `/announce`, `/scr
290266Scraping multiple torrent info is possible with a static ` Client.scrape ` method:
291267
292268``` js
293- var Client = require ( ' bittorrent-tracker' )
269+ import Client from ' bittorrent-tracker'
294270Client .scrape ({ announce: announceUrl, infoHash: [ infoHash1, infoHash2 ]}, function (err , results ) {
295271 results[infoHash1].announce
296272 results[infoHash1].infoHash
0 commit comments