2022-12-05 22:06:54 +00:00
|
|
|
import Client from '../index.js'
|
|
|
|
import common from './common.js'
|
|
|
|
import fixtures from 'webtorrent-fixtures'
|
|
|
|
import magnet from 'magnet-uri'
|
|
|
|
import test from 'tape'
|
2014-05-14 19:45:48 +00:00
|
|
|
|
2020-10-29 04:57:47 +00:00
|
|
|
const peerId = Buffer.from('01234567890123456789')
|
2014-05-14 19:45:48 +00:00
|
|
|
|
2016-03-01 01:15:03 +00:00
|
|
|
function testMagnet (t, serverType) {
|
|
|
|
t.plan(9)
|
2014-05-14 19:45:48 +00:00
|
|
|
|
2020-10-29 04:57:47 +00:00
|
|
|
const parsedTorrent = magnet(fixtures.leaves.magnetURI)
|
2016-03-16 19:22:33 +00:00
|
|
|
|
2021-06-15 01:54:41 +00:00
|
|
|
common.createServer(t, serverType, (server, announceUrl) => {
|
2020-10-29 04:57:47 +00:00
|
|
|
const client = new Client({
|
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
|
|
|
infoHash: parsedTorrent.infoHash,
|
|
|
|
announce: announceUrl,
|
2020-04-25 09:34:40 +00:00
|
|
|
peerId,
|
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
|
|
|
port: 6881,
|
|
|
|
wrtc: {}
|
|
|
|
})
|
2014-05-24 04:02:53 +00:00
|
|
|
|
2016-03-01 01:15:03 +00:00
|
|
|
if (serverType === 'ws') common.mockWebsocketTracker(client)
|
2021-06-15 01:54:41 +00:00
|
|
|
client.on('error', err => { t.error(err) })
|
|
|
|
client.on('warning', err => { t.error(err) })
|
2014-05-14 19:45:48 +00:00
|
|
|
|
2021-06-15 01:54:41 +00:00
|
|
|
client.once('update', data => {
|
2014-05-14 19:45:48 +00:00
|
|
|
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
|
|
|
|
|
|
|
client.update()
|
2014-05-14 19:45:48 +00:00
|
|
|
|
2021-06-15 01:54:41 +00:00
|
|
|
client.once('update', data => {
|
2014-05-14 19:45:48 +00:00
|
|
|
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
|
|
|
client.stop()
|
2014-05-14 19:45:48 +00:00
|
|
|
|
2021-06-15 01:54:41 +00:00
|
|
|
client.once('update', data => {
|
2014-05-24 04:02:53 +00:00
|
|
|
t.equal(data.announce, announceUrl)
|
|
|
|
t.equal(typeof data.complete, 'number')
|
|
|
|
t.equal(typeof data.incomplete, 'number')
|
2014-05-14 19:45:48 +00:00
|
|
|
|
2015-05-17 06:24:20 +00:00
|
|
|
server.close()
|
|
|
|
client.destroy()
|
2014-05-24 04:02:53 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2016-03-01 01:15:03 +00:00
|
|
|
|
|
|
|
client.start()
|
2014-05-24 04:02:53 +00:00
|
|
|
})
|
2016-03-01 01:15:03 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 01:54:41 +00:00
|
|
|
test('http: magnet: client.start/update/stop()', t => {
|
2016-03-01 01:15:03 +00:00
|
|
|
testMagnet(t, 'http')
|
|
|
|
})
|
|
|
|
|
2021-06-15 01:54:41 +00:00
|
|
|
test('udp: magnet: client.start/update/stop()', t => {
|
2016-03-01 01:15:03 +00:00
|
|
|
testMagnet(t, 'udp')
|
|
|
|
})
|
|
|
|
|
2021-06-15 01:54:41 +00:00
|
|
|
test('ws: magnet: client.start/update/stop()', t => {
|
2016-03-01 01:15:03 +00:00
|
|
|
testMagnet(t, 'ws')
|
2014-05-14 19:45:48 +00:00
|
|
|
})
|