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

On duplicate torrent add, don't emit 'infoHash' #798

Merged
merged 1 commit into from May 12, 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

On duplicate torrent add, don't emit 'infoHash'

Private 'infoHash' event allows client.add to check for duplicate
torrents and destroy them before the normal 'infoHash' event is
emitted. Prevents user applications from needing to deal with duplicate
'infoHash' events.
  • Loading branch information
feross committed May 11, 2016
commit 5ebba786d50077365b55c193df2d570bf5498b6e
@@ -1,5 +1,9 @@
# WebTorrent Version History

## UNRELEASED

- When a duplicate torrent is added, don't emit the 'infoHash' event after 'error'. The 'error' event should be the last event.

## v0.93.1 - 2016-05-08

- Remove `path-exists` dependency.
@@ -240,7 +240,7 @@ WebTorrent.prototype.add = function (torrentId, opts, ontorrent) {
var torrent = new Torrent(torrentId, self, opts)
self.torrents.push(torrent)

torrent.once('infoHash', onInfoHash)
torrent.once('_infoHash', onInfoHash)
torrent.once('ready', onReady)
torrent.once('close', onClose)

@@ -262,7 +262,7 @@ WebTorrent.prototype.add = function (torrentId, opts, ontorrent) {
}

function onClose () {
torrent.removeListener('infoHash', onInfoHash)
torrent.removeListener('_infoHash', onInfoHash)
torrent.removeListener('ready', onReady)
torrent.removeListener('close', onClose)
}
@@ -253,8 +253,14 @@ Torrent.prototype._onParsedTorrent = function (parsedTorrent) {
}, RECHOKE_INTERVAL)
if (self._rechokeIntervalId.unref) self._rechokeIntervalId.unref()

// Private 'infoHash' event allows client.add to check for duplicate torrents and
// destroy them before the normal 'infoHash' event is emitted. Prevents user
// applications from needing to deal with duplicate 'infoHash' events.
self.emit('_infoHash', self.infoHash)
if (self.destroyed) return

self.emit('infoHash', self.infoHash)
if (self.destroyed) return // user might destroy torrent in `infoHash` event handler
if (self.destroyed) return // user might destroy torrent in event handler

if (self.client.listening) {
self._onListening()
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.