update documentation for #107

This commit is contained in:
Feross Aboukhadijeh 2016-02-29 18:16:08 -08:00
parent 48d1f38e63
commit 3485f2275b
2 changed files with 31 additions and 7 deletions

View File

@ -58,6 +58,22 @@ var parsedTorrent = parseTorrent(torrent) // { infoHash: 'xxx', length: xx, anno
var peerId = new Buffer('01234567890123456789')
var port = 6881
// optional options dictionary
var opts = {
rtcConfig: {}, // RTCPeerConnection configuration object
wrtc: {}, // custom webrtc impl (useful in node.js)
getAnnounceOpts: function () {
// provide a callback that will be called whenever announce() is called
// internally (on timer), or by the user
return {
uploaded: 0,
downloaded: 0,
left: 0,
customParam: 'blah' // custom parameters supported
}
}
}
var client = new Client(peerId, port, parsedTorrent)
client.on('error', function (err) {
@ -89,6 +105,14 @@ client.complete()
// force a tracker announce. will trigger more 'update' events and maybe more 'peer' events
client.update()
// provide parameters to the tracker
client.update({
uploaded: 0,
downloaded: 0,
left: 0,
customParam: 'blah' // custom parameters supported
})
// stop getting peers from the tracker, gracefully leave the swarm
client.stop()

View File

@ -21,13 +21,13 @@ inherits(Client, EventEmitter)
*
* Find torrent peers, to help a torrent client participate in a torrent swarm.
*
* @param {string|Buffer} peerId peer id
* @param {Number} port torrent client listening port
* @param {Object} torrent parsed torrent
* @param {Object} opts options object
* @param {Number} opts.rtcConfig RTCPeerConnection configuration object
* @param {Number} opts.wrtc custom webrtc implementation
* @param {Object} opts.getAnnounceOpts callback to provide data to tracker
* @param {string|Buffer} peerId peer id
* @param {Number} port torrent client listening port
* @param {Object} torrent parsed torrent
* @param {Object} opts options object
* @param {Number} opts.rtcConfig RTCPeerConnection configuration object
* @param {Number} opts.wrtc custom webrtc impl (useful in node.js)
* @param {function} opts.getAnnounceOpts callback to provide data to tracker
*/
function Client (peerId, port, torrent, opts) {
var self = this