Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'noPeers' event to torrents #775

Merged
merged 3 commits into from May 5, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -413,6 +413,10 @@ See the `bittorrent-protocol`
[extension api docs](https://github.com/feross/bittorrent-protocol#extension-api) for more
information on how to define a protocol extension.

## `torrent.on('noPeers', function (announceType) {})`

Emitted whenever a DHT or tracker announce occurs, but no peers have been found. `announceType` is either `'tracker'` or `'dht'` depending on which announce occurred to trigger this event. Note that if you're attempting to discover peers from both a tracker and a DHT, you'll see this event separately for each.

# File API

## `file.name`
@@ -333,10 +333,12 @@ Torrent.prototype._onListening = function () {

function onTrackerAnnounce () {
self.emit('trackerAnnounce')
if (self.numPeers === 0) self.emit('noPeers', 'tracker')
}

function onDHTAnnounce () {
self.emit('dhtAnnounce')
if (self.numPeers === 0) self.emit('noPeers', 'dht')
}

function onWarning (err) {
@@ -6,7 +6,7 @@ var test = require('tape')
var WebTorrent = require('../../')

test('Download using DHT (via .torrent file)', function (t) {
t.plan(9)
t.plan(10)

var dhtServer = new DHT({ bootstrap: false })

@@ -53,10 +53,17 @@ test('Download using DHT (via .torrent file)', function (t) {
maybeDone(null)
})

torrent.on('noPeers', function (announceType) {
t.equal(announceType, 'dht', 'noPeers event seen with correct announceType')
noPeersFound = true
maybeDone(null)
})

var announced = false
var loaded = false
var noPeersFound = false
function maybeDone (err) {
if ((announced && loaded) || err) cb(err, client1)
if ((announced && loaded && noPeersFound) || err) cb(err, client1)
}
},

@@ -15,7 +15,7 @@ test('Download using HTTP tracker (via magnet uri)', function (t) {
})

function magnetDownloadTest (t, serverType) {
t.plan(9)
t.plan(10)

var tracker = new TrackerServer(
serverType === 'udp' ? { http: false, ws: false } : { udp: false, ws: false }
@@ -59,6 +59,10 @@ function magnetDownloadTest (t, serverType) {
'Leaves of Grass by Walt Whitman.epub'
]

torrent.on('noPeers', function (announceType) {
t.equal(announceType, 'tracker', 'noPeers event seen with correct announceType')
})

t.deepEqual(torrent.files.map(function (file) { return file.name }), names)

torrent.load(fs.createReadStream(fixtures.leaves.contentPath), function (err) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.