mirror of
https://github.com/logos-storage/bittorrent-tracker.git
synced 2026-01-03 13:33:08 +00:00
To use the client, you used to pass in four arguments:
`new Client(peerId, port, parsedTorrent, opts)`
Now, passing in the torrent is no longer required, just the `announce`
and `infoHash` properties. This decouples this package from
`parse-torrent`.
All options get passed in together now:
new Client({
infoHash: '', // hex string or Buffer
peerId: '', // hex string or Buffer
announce: [], // list of tracker server urls
port: 6881 // torrent client port, (in browser, optional)
})
All the normal optional arguments (rtcConfig, wrtc, etc.) can still be
passed in with the rest of these options.
Fixes #118. Fixes #115.
Added ws tests for scrape.
64 lines
1.6 KiB
JavaScript
64 lines
1.6 KiB
JavaScript
var Client = require('../')
|
|
var common = require('./common')
|
|
var fixtures = require('webtorrent-fixtures')
|
|
var test = require('tape')
|
|
|
|
var peerId = new Buffer('01234567890123456789')
|
|
|
|
function testLargeTorrent (t, serverType) {
|
|
t.plan(9)
|
|
|
|
common.createServer(t, serverType, function (server, announceUrl) {
|
|
var client = new Client({
|
|
infoHash: fixtures.sintel.parsedTorrent.infoHash,
|
|
peerId: peerId,
|
|
port: 6881,
|
|
announce: announceUrl,
|
|
wrtc: {}
|
|
})
|
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
|
client.on('error', function (err) { t.error(err) })
|
|
client.on('warning', function (err) { t.error(err) })
|
|
|
|
client.once('update', function (data) {
|
|
t.equal(data.announce, announceUrl)
|
|
t.equal(typeof data.complete, 'number')
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
client.update()
|
|
|
|
client.once('update', function (data) {
|
|
t.equal(data.announce, announceUrl)
|
|
t.equal(typeof data.complete, 'number')
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
client.stop()
|
|
|
|
client.once('update', function (data) {
|
|
t.equal(data.announce, announceUrl)
|
|
t.equal(typeof data.complete, 'number')
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
server.close()
|
|
client.destroy()
|
|
})
|
|
})
|
|
})
|
|
|
|
client.start()
|
|
})
|
|
}
|
|
|
|
test('http: large torrent: client.start()', function (t) {
|
|
testLargeTorrent(t, 'http')
|
|
})
|
|
|
|
test('udp: large torrent: client.start()', function (t) {
|
|
testLargeTorrent(t, 'udp')
|
|
})
|
|
|
|
test('ws: large torrent: client.start()', function (t) {
|
|
testLargeTorrent(t, 'ws')
|
|
})
|