Skip to content

Commit

Permalink
Fix for issue webtorrent#2767 WebTorrent.remove bug
Browse files Browse the repository at this point in the history
  • Loading branch information
LostBeard committed Mar 27, 2024
1 parent b5735b4 commit e6e9497
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ export default class WebTorrent extends EventEmitter {
torrent.once('_infoHash', onInfoHash)
torrent.once('ready', onReady)
torrent.once('close', onClose)

this.emit('add', torrent)
return torrent
}
Expand Down Expand Up @@ -412,7 +412,9 @@ export default class WebTorrent extends EventEmitter {
_remove (torrent, opts, cb) {
if (!torrent) return
if (typeof opts === 'function') return this._remove(torrent, null, opts)
this.torrents.splice(this.torrents.indexOf(torrent), 1)
var index = this.torrents.indexOf(torrent);
if (index === -1) return
this.torrents.splice(index, 1)
torrent.destroy(opts, cb)
if (this.dht) {
this.dht._tables.remove(torrent.infoHash)
Expand Down

0 comments on commit e6e9497

Please sign in to comment.