2016-05-30 06:12:23 +00:00
|
|
|
var Buffer = require('safe-buffer').Buffer
|
2014-06-07 22:15:00 +00:00
|
|
|
var Client = require('../')
|
2014-07-22 05:58:13 +00:00
|
|
|
var common = require('./common')
|
2016-03-16 19:22:33 +00:00
|
|
|
var fixtures = require('webtorrent-fixtures')
|
2014-03-26 08:17:59 +00:00
|
|
|
var test = require('tape')
|
|
|
|
|
2016-05-30 06:12:23 +00:00
|
|
|
var peerId1 = Buffer.from('01234567890123456789')
|
|
|
|
var peerId2 = Buffer.from('12345678901234567890')
|
|
|
|
var peerId3 = Buffer.from('23456789012345678901')
|
2014-03-26 08:17:59 +00:00
|
|
|
var port = 6881
|
|
|
|
|
2014-07-11 10:50:35 +00:00
|
|
|
function testClientStart (t, serverType) {
|
2016-02-29 22:48:23 +00:00
|
|
|
t.plan(4)
|
2016-03-16 19:22:33 +00:00
|
|
|
|
2014-07-22 05:58:13 +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.leaves.parsedTorrent.infoHash,
|
|
|
|
announce: announceUrl,
|
|
|
|
peerId: peerId1,
|
|
|
|
port: port,
|
|
|
|
wrtc: {}
|
|
|
|
})
|
2014-03-26 08:17:59 +00:00
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
2016-02-29 22:48:23 +00:00
|
|
|
client.on('error', function (err) { t.error(err) })
|
|
|
|
client.on('warning', function (err) { t.error(err) })
|
2014-07-11 04:58:19 +00:00
|
|
|
|
2014-03-26 08:17:59 +00:00
|
|
|
client.once('update', function (data) {
|
2014-05-09 06:38:41 +00:00
|
|
|
t.equal(data.announce, announceUrl)
|
2014-03-26 08:17:59 +00:00
|
|
|
t.equal(typeof data.complete, 'number')
|
|
|
|
t.equal(typeof data.incomplete, 'number')
|
2014-03-27 07:17:49 +00:00
|
|
|
|
2014-05-24 04:14:19 +00:00
|
|
|
client.stop()
|
|
|
|
|
|
|
|
client.once('update', function () {
|
2015-05-17 06:24:20 +00:00
|
|
|
t.pass('got response to stop')
|
|
|
|
server.close()
|
|
|
|
client.destroy()
|
2014-05-24 04:14:19 +00:00
|
|
|
})
|
2014-03-27 07:17:49 +00:00
|
|
|
})
|
2014-03-26 08:17:59 +00:00
|
|
|
|
2014-05-24 04:14:19 +00:00
|
|
|
client.start()
|
|
|
|
})
|
2014-07-11 10:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test('http: client.start()', function (t) {
|
|
|
|
testClientStart(t, 'http')
|
2014-05-24 04:14:19 +00:00
|
|
|
})
|
2014-03-26 08:17:59 +00:00
|
|
|
|
2014-07-11 10:50:35 +00:00
|
|
|
test('udp: client.start()', function (t) {
|
|
|
|
testClientStart(t, 'udp')
|
|
|
|
})
|
2014-03-26 08:17:59 +00:00
|
|
|
|
2016-02-29 22:48:23 +00:00
|
|
|
test('ws: client.start()', function (t) {
|
|
|
|
testClientStart(t, 'ws')
|
|
|
|
})
|
|
|
|
|
2014-07-11 10:50:35 +00:00
|
|
|
function testClientStop (t, serverType) {
|
2015-05-17 06:24:20 +00:00
|
|
|
t.plan(3)
|
2016-03-16 19:22:33 +00:00
|
|
|
|
2014-07-22 05:58:13 +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.leaves.parsedTorrent.infoHash,
|
|
|
|
announce: announceUrl,
|
|
|
|
peerId: peerId1,
|
|
|
|
port: port,
|
|
|
|
wrtc: {}
|
|
|
|
})
|
2014-03-26 08:17:59 +00:00
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
2016-02-29 22:48:23 +00:00
|
|
|
client.on('error', function (err) { t.error(err) })
|
|
|
|
client.on('warning', function (err) { t.error(err) })
|
2014-07-11 04:58:19 +00:00
|
|
|
|
2014-05-24 04:14:19 +00:00
|
|
|
client.start()
|
2014-03-26 08:17:59 +00:00
|
|
|
|
2014-05-24 04:14:19 +00:00
|
|
|
setTimeout(function () {
|
2014-03-26 08:17:59 +00:00
|
|
|
client.stop()
|
2014-05-24 04:14:19 +00:00
|
|
|
|
|
|
|
client.once('update', function (data) {
|
|
|
|
// receive one final update after calling stop
|
|
|
|
t.equal(data.announce, announceUrl)
|
|
|
|
t.equal(typeof data.complete, 'number')
|
|
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
|
2015-05-17 06:24:20 +00:00
|
|
|
server.close()
|
|
|
|
client.destroy()
|
2014-05-24 04:14:19 +00:00
|
|
|
})
|
|
|
|
}, 1000)
|
|
|
|
})
|
2014-07-11 10:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test('http: client.stop()', function (t) {
|
|
|
|
testClientStop(t, 'http')
|
2014-05-24 04:14:19 +00:00
|
|
|
})
|
|
|
|
|
2014-07-11 10:50:35 +00:00
|
|
|
test('udp: client.stop()', function (t) {
|
|
|
|
testClientStop(t, 'udp')
|
|
|
|
})
|
2014-05-24 04:14:19 +00:00
|
|
|
|
2016-02-29 22:48:23 +00:00
|
|
|
test('ws: client.stop()', function (t) {
|
|
|
|
testClientStop(t, 'ws')
|
|
|
|
})
|
|
|
|
|
2014-07-11 10:50:35 +00:00
|
|
|
function testClientUpdate (t, serverType) {
|
|
|
|
t.plan(4)
|
2016-03-16 19:22:33 +00:00
|
|
|
|
2014-07-22 05:58:13 +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.leaves.parsedTorrent.infoHash,
|
|
|
|
announce: announceUrl,
|
|
|
|
peerId: peerId1,
|
|
|
|
port: port,
|
|
|
|
wrtc: {}
|
|
|
|
})
|
2014-05-24 04:14:19 +00:00
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
2016-02-29 22:48:23 +00:00
|
|
|
client.on('error', function (err) { t.error(err) })
|
|
|
|
client.on('warning', function (err) { t.error(err) })
|
2014-03-26 08:17:59 +00:00
|
|
|
|
2016-02-29 22:48:23 +00:00
|
|
|
client.setInterval(2000)
|
2014-07-11 04:58:19 +00:00
|
|
|
|
2014-05-24 04:14:19 +00:00
|
|
|
client.start()
|
|
|
|
|
|
|
|
client.once('update', function () {
|
2015-12-05 08:06:23 +00:00
|
|
|
client.setInterval(2000)
|
|
|
|
|
2015-03-24 08:02:10 +00:00
|
|
|
// after interval (2s), we should get another update
|
2014-05-24 04:14:19 +00:00
|
|
|
client.once('update', function (data) {
|
|
|
|
// received an update!
|
|
|
|
t.equal(data.announce, announceUrl)
|
|
|
|
t.equal(typeof data.complete, 'number')
|
|
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
client.stop()
|
|
|
|
|
|
|
|
client.once('update', function () {
|
2015-05-17 06:24:20 +00:00
|
|
|
t.pass('got response to stop')
|
|
|
|
server.close()
|
|
|
|
client.destroy()
|
2014-05-24 04:14:19 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-03-26 08:17:59 +00:00
|
|
|
})
|
2014-07-11 10:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test('http: client.update()', function (t) {
|
|
|
|
testClientUpdate(t, 'http')
|
2014-03-26 08:17:59 +00:00
|
|
|
})
|
|
|
|
|
2014-07-11 10:50:35 +00:00
|
|
|
test('udp: client.update()', function (t) {
|
|
|
|
testClientUpdate(t, 'udp')
|
|
|
|
})
|
2014-05-09 06:38:41 +00:00
|
|
|
|
2016-02-29 22:48:23 +00:00
|
|
|
test('ws: client.update()', function (t) {
|
|
|
|
testClientUpdate(t, 'ws')
|
|
|
|
})
|
|
|
|
|
2014-07-11 10:50:35 +00:00
|
|
|
function testClientScrape (t, serverType) {
|
2015-05-17 06:24:20 +00:00
|
|
|
t.plan(4)
|
2016-03-16 19:22:33 +00:00
|
|
|
|
2014-07-22 05:58:13 +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.leaves.parsedTorrent.infoHash,
|
|
|
|
announce: announceUrl,
|
|
|
|
peerId: peerId1,
|
|
|
|
port: port,
|
|
|
|
wrtc: {}
|
|
|
|
})
|
2014-05-09 06:38:41 +00:00
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
2016-02-29 22:48:23 +00:00
|
|
|
client.on('error', function (err) { t.error(err) })
|
|
|
|
client.on('warning', function (err) { t.error(err) })
|
2014-07-11 04:58:19 +00:00
|
|
|
|
2014-05-24 04:14:19 +00:00
|
|
|
client.once('scrape', function (data) {
|
|
|
|
t.equal(data.announce, announceUrl)
|
|
|
|
t.equal(typeof data.complete, 'number')
|
|
|
|
t.equal(typeof data.incomplete, 'number')
|
|
|
|
t.equal(typeof data.downloaded, 'number')
|
2014-05-12 00:32:57 +00:00
|
|
|
|
2015-05-17 06:24:20 +00:00
|
|
|
server.close()
|
|
|
|
client.destroy()
|
2014-05-24 04:14:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
client.scrape()
|
|
|
|
})
|
2014-07-11 10:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test('http: client.scrape()', function (t) {
|
|
|
|
testClientScrape(t, 'http')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('udp: client.scrape()', function (t) {
|
|
|
|
testClientScrape(t, 'udp')
|
|
|
|
})
|
|
|
|
|
2016-06-04 13:50:46 +00:00
|
|
|
test('ws: client.scrape()', function (t) {
|
|
|
|
testClientScrape(t, 'ws')
|
|
|
|
})
|
2016-02-29 22:48:23 +00:00
|
|
|
|
2016-03-01 01:02:55 +00:00
|
|
|
function testClientAnnounceWithParams (t, serverType) {
|
|
|
|
t.plan(5)
|
2016-03-16 19:22:33 +00:00
|
|
|
|
2016-03-01 01:02:55 +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.leaves.parsedTorrent.infoHash,
|
|
|
|
announce: announceUrl,
|
|
|
|
peerId: peerId1,
|
|
|
|
port: port,
|
|
|
|
wrtc: {}
|
|
|
|
})
|
2016-03-01 01:02:55 +00:00
|
|
|
|
|
|
|
server.on('start', function (peer, params) {
|
|
|
|
t.equal(params.testParam, 'this is a test')
|
|
|
|
})
|
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
2016-03-01 01:02:55 +00:00
|
|
|
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.stop()
|
|
|
|
|
|
|
|
client.once('update', function () {
|
|
|
|
t.pass('got response to stop')
|
|
|
|
server.close()
|
|
|
|
client.destroy()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
client.start({
|
|
|
|
testParam: 'this is a test'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
test('http: client.announce() with params', function (t) {
|
|
|
|
testClientAnnounceWithParams(t, 'http')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('ws: client.announce() with params', function (t) {
|
|
|
|
testClientAnnounceWithParams(t, 'ws')
|
|
|
|
})
|
|
|
|
|
|
|
|
function testClientGetAnnounceOpts (t, serverType) {
|
|
|
|
t.plan(5)
|
2016-03-16 19:22:33 +00:00
|
|
|
|
2016-03-01 01:02:55 +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.leaves.parsedTorrent.infoHash,
|
|
|
|
announce: announceUrl,
|
|
|
|
peerId: peerId1,
|
|
|
|
port: port,
|
2016-03-01 01:02:55 +00:00
|
|
|
getAnnounceOpts: function () {
|
|
|
|
return {
|
|
|
|
testParam: 'this is a test'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
wrtc: {}
|
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
|
|
|
})
|
2016-03-01 01:02:55 +00:00
|
|
|
|
|
|
|
server.on('start', function (peer, params) {
|
|
|
|
t.equal(params.testParam, 'this is a test')
|
|
|
|
})
|
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
2016-03-01 01:02:55 +00:00
|
|
|
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.stop()
|
|
|
|
|
|
|
|
client.once('update', function () {
|
|
|
|
t.pass('got response to stop')
|
|
|
|
server.close()
|
|
|
|
client.destroy()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
client.start()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
test('http: client `opts.getAnnounceOpts`', function (t) {
|
|
|
|
testClientGetAnnounceOpts(t, 'http')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('ws: client `opts.getAnnounceOpts`', function (t) {
|
|
|
|
testClientGetAnnounceOpts(t, 'ws')
|
|
|
|
})
|
|
|
|
|
2014-07-11 10:50:48 +00:00
|
|
|
function testClientAnnounceWithNumWant (t, serverType) {
|
2015-05-17 06:24:20 +00:00
|
|
|
t.plan(4)
|
2016-03-16 19:22:33 +00:00
|
|
|
|
2014-07-22 05:58:13 +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 client1 = new Client({
|
|
|
|
infoHash: fixtures.leaves.parsedTorrent.infoHash,
|
|
|
|
announce: [ announceUrl ],
|
|
|
|
peerId: peerId1,
|
|
|
|
port: port,
|
|
|
|
wrtc: {}
|
|
|
|
})
|
2016-02-29 22:48:23 +00:00
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client1)
|
2016-02-29 22:48:23 +00:00
|
|
|
client1.on('error', function (err) { t.error(err) })
|
|
|
|
client1.on('warning', function (err) { t.error(err) })
|
2014-07-11 10:50:48 +00:00
|
|
|
|
|
|
|
client1.start()
|
2014-11-26 12:11:49 +00:00
|
|
|
client1.once('update', function () {
|
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 client2 = new Client({
|
|
|
|
infoHash: fixtures.leaves.parsedTorrent.infoHash,
|
|
|
|
announce: announceUrl,
|
|
|
|
peerId: peerId2,
|
|
|
|
port: port + 1,
|
|
|
|
wrtc: {}
|
|
|
|
})
|
2016-02-29 22:48:23 +00:00
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client2)
|
2016-02-29 22:48:23 +00:00
|
|
|
client2.on('error', function (err) { t.error(err) })
|
|
|
|
client2.on('warning', function (err) { t.error(err) })
|
|
|
|
|
2014-07-11 10:50:48 +00:00
|
|
|
client2.start()
|
|
|
|
client2.once('update', function () {
|
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 client3 = new Client({
|
|
|
|
infoHash: fixtures.leaves.parsedTorrent.infoHash,
|
|
|
|
announce: announceUrl,
|
|
|
|
peerId: peerId3,
|
|
|
|
port: port + 2,
|
|
|
|
wrtc: {}
|
|
|
|
})
|
2016-02-29 22:48:23 +00:00
|
|
|
|
2016-03-01 01:11:02 +00:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client3)
|
2016-02-29 22:48:23 +00:00
|
|
|
client3.on('error', function (err) { t.error(err) })
|
|
|
|
client3.on('warning', function (err) { t.error(err) })
|
|
|
|
|
2015-07-29 08:47:09 +00:00
|
|
|
client3.start({ numwant: 1 })
|
2014-07-11 10:50:48 +00:00
|
|
|
client3.on('peer', function () {
|
|
|
|
t.pass('got one peer (this should only fire once)')
|
|
|
|
|
2015-05-17 06:24:20 +00:00
|
|
|
var num = 3
|
|
|
|
function tryCloseServer () {
|
|
|
|
num -= 1
|
|
|
|
if (num === 0) server.close()
|
|
|
|
}
|
|
|
|
|
2014-07-11 10:50:48 +00:00
|
|
|
client1.stop()
|
2015-05-17 06:24:20 +00:00
|
|
|
client1.once('update', function () {
|
|
|
|
t.pass('got response to stop (client1)')
|
|
|
|
client1.destroy()
|
|
|
|
tryCloseServer()
|
|
|
|
})
|
2014-07-11 10:50:48 +00:00
|
|
|
client2.stop()
|
2015-05-17 06:24:20 +00:00
|
|
|
client2.once('update', function () {
|
|
|
|
t.pass('got response to stop (client2)')
|
|
|
|
client2.destroy()
|
|
|
|
tryCloseServer()
|
|
|
|
})
|
2014-07-11 10:50:48 +00:00
|
|
|
client3.stop()
|
2015-05-17 06:24:20 +00:00
|
|
|
client3.once('update', function () {
|
|
|
|
t.pass('got response to stop (client3)')
|
|
|
|
client3.destroy()
|
|
|
|
tryCloseServer()
|
|
|
|
})
|
2014-07-11 10:50:48 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-07-27 22:19:18 +00:00
|
|
|
test('http: client announce with numwant', function (t) {
|
2014-07-11 10:50:48 +00:00
|
|
|
testClientAnnounceWithNumWant(t, 'http')
|
|
|
|
})
|
|
|
|
|
2015-07-27 22:19:18 +00:00
|
|
|
test('udp: client announce with numwant', function (t) {
|
2014-07-11 10:50:48 +00:00
|
|
|
testClientAnnounceWithNumWant(t, 'udp')
|
2014-05-09 06:38:41 +00:00
|
|
|
})
|
2017-01-16 23:43:47 +00:00
|
|
|
|
|
|
|
test('http: userAgent', function (t) {
|
|
|
|
t.plan(2)
|
|
|
|
|
|
|
|
common.createServer(t, 'http', function (server, announceUrl) {
|
|
|
|
// Confirm that user-agent header is set
|
|
|
|
server.http.on('request', function (req, res) {
|
|
|
|
t.ok(req.headers['user-agent'].indexOf('WebTorrent') !== -1)
|
|
|
|
})
|
|
|
|
|
|
|
|
var client = new Client({
|
|
|
|
infoHash: fixtures.leaves.parsedTorrent.infoHash,
|
|
|
|
announce: announceUrl,
|
|
|
|
peerId: peerId1,
|
|
|
|
port: port,
|
|
|
|
userAgent: 'WebTorrent/0.98.0 (https://webtorrent.io)',
|
|
|
|
wrtc: {}
|
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
server.close()
|
|
|
|
client.destroy()
|
|
|
|
})
|
|
|
|
|
|
|
|
client.start()
|
|
|
|
})
|
|
|
|
})
|