2014-06-07 22:15:00 +00:00
|
|
|
var Client = require('../')
|
2016-03-01 01:15:03 +00:00
|
|
|
var common = require('./common')
|
2016-03-16 19:22:33 +00:00
|
|
|
var fixtures = require('webtorrent-fixtures')
|
2014-05-14 19:45:48 +00:00
|
|
|
var magnet = require('magnet-uri')
|
|
|
|
var test = require('tape')
|
|
|
|
|
|
|
|
var peerId = new Buffer('01234567890123456789')
|
|
|
|
|
2016-03-01 01:15:03 +00:00
|
|
|
function testMagnet (t, serverType) {
|
|
|
|
t.plan(9)
|
2014-05-14 19:45:48 +00:00
|
|
|
|
2016-03-16 19:22:33 +00:00
|
|
|
var parsedTorrent = magnet(fixtures.leaves.magnetURI)
|
|
|
|
|
2016-03-01 01:15:03 +00:00
|
|
|
common.createServer(t, serverType, function (server, announceUrl) {
|
2014-05-24 04:02:53 +00:00
|
|
|
parsedTorrent.announce = [ announceUrl ]
|
|
|
|
|
2016-03-01 01:15:03 +00:00
|
|
|
var client = new Client(peerId, 6881, parsedTorrent, { wrtc: {} })
|
2014-05-24 04:02:53 +00:00
|
|
|
|
2016-03-01 01:15:03 +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-14 19:45:48 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
client.update()
|
2014-05-14 19:45:48 +00:00
|
|
|
|
|
|
|
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
|
|
|
client.stop()
|
2014-05-14 19:45:48 +00:00
|
|
|
|
2014-05-24 04:02:53 +00:00
|
|
|
client.once('update', function (data) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
test('http: magnet: client.start/update/stop()', function (t) {
|
|
|
|
testMagnet(t, 'http')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('udp: magnet: client.start/update/stop()', function (t) {
|
|
|
|
testMagnet(t, 'udp')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('ws: magnet: client.start/update/stop()', function (t) {
|
|
|
|
testMagnet(t, 'ws')
|
2014-05-14 19:45:48 +00:00
|
|
|
})
|