forked from webtorrent/bittorrent-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client-magnet.js
66 lines (51 loc) · 1.7 KB
/
client-magnet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const Client = require('../')
const common = require('./common')
const fixtures = require('webtorrent-fixtures')
const magnet = require('magnet-uri')
const test = require('tape')
const peerId = Buffer.from('01234567890123456789')
function testMagnet (t, serverType) {
t.plan(9)
const parsedTorrent = magnet(fixtures.leaves.magnetURI)
common.createServer(t, serverType, function (server, announceUrl) {
const client = new Client({
infoHash: parsedTorrent.infoHash,
announce: announceUrl,
peerId,
port: 6881,
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: 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')
})