2014-06-07 22:15:00 +00:00
|
|
|
var Client = require('../')
|
2016-03-01 01:14:47 +00:00
|
|
|
var common = require('./common')
|
2016-03-16 19:22:33 +00:00
|
|
|
var fixtures = require('webtorrent-fixtures')
|
2014-04-19 06:08:17 +00:00
|
|
|
var test = require('tape')
|
|
|
|
|
|
|
|
var peerId = new Buffer('01234567890123456789')
|
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
function testLargeTorrent (t, serverType) {
|
2016-03-01 01:14:47 +00:00
|
|
|
t.plan(9)
|
2014-04-19 06:08:17 +00:00
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
common.createServer(t, serverType, function (server, announceUrl) {
|
BREAKING: Client() takes single opts object now
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.
2016-04-01 04:37:51 +00:00
|
|
|
var client = new Client({
|
|
|
|
infoHash: fixtures.sintel.parsedTorrent.infoHash,
|
|
|
|
peerId: peerId,
|
|
|
|
port: 6881,
|
|
|
|
announce: announceUrl,
|
|
|
|
wrtc: {}
|
|
|
|
})
|
2014-04-19 06:08:17 +00:00
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
|
|
|
client.on('error', function (err) { t.error(err) })
|
|
|
|
client.on('warning', function (err) { t.error(err) })
|
2014-05-24 03:35:29 +00:00
|
|
|
|
|
|
|
client.once('update', function (data) {
|
2016-03-01 01:11:02 +00:00
|
|
|
t.equal(data.announce, announceUrl)
|
2014-05-24 03:35:29 +00:00
|
|
|
t.equal(typeof data.complete, 'number')
|
|
|
|
t.equal(typeof data.incomplete, 'number')
|
2014-05-24 04:02:53 +00:00
|
|
|
|
2016-03-01 01:14:47 +00:00
|
|
|
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')
|
2014-05-24 04:02:53 +00:00
|
|
|
|
2016-03-01 01:14:47 +00:00
|
|
|
server.close()
|
|
|
|
client.destroy()
|
|
|
|
})
|
2014-05-24 03:43:45 +00:00
|
|
|
})
|
2014-05-24 04:02:53 +00:00
|
|
|
})
|
2016-03-01 01:11:02 +00:00
|
|
|
|
|
|
|
client.start()
|
2014-05-24 03:35:29 +00:00
|
|
|
})
|
2016-03-01 01:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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')
|
2014-04-19 06:08:17 +00:00
|
|
|
})
|