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

Added WebTorrent add and remove events and docs update #2766

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ buf.name = 'Some file name'
client.seed(buf, cb)
```

## `client.on('add', function (torrent) {})`

Emitted when a torrent is added to client.torrents. This allows attaching to torrent events that may be emitted before the client 'torrent' event is emitted. See the torrent section for more info on what methods a `torrent` has.

## `client.on('remove', function (torrent) {})`

Emitted when a torrent is removed from client.torrents. See the torrent section for more info on what methods a `torrent` has.

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

Emitted when a torrent is ready to be used (i.e. metadata is available and store is
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
torrent.once('ready', onReady)
torrent.once('close', onClose)

this.emit('add', torrent)
return torrent
}

Expand Down Expand Up @@ -411,11 +412,14 @@
_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);

Check warning on line 415 in index.js

View workflow job for this annotation

GitHub Actions / Node 18 / ubuntu-latest

Unexpected var, use let or const instead

Check failure on line 415 in index.js

View workflow job for this annotation

GitHub Actions / Node 18 / ubuntu-latest

Extra semicolon

Check warning on line 415 in index.js

View workflow job for this annotation

GitHub Actions / Node 16 / ubuntu-latest

Unexpected var, use let or const instead

Check failure on line 415 in index.js

View workflow job for this annotation

GitHub Actions / Node 16 / ubuntu-latest

Extra semicolon
LostBeard marked this conversation as resolved.
Show resolved Hide resolved
if (index === -1) return
this.torrents.splice(index, 1)
torrent.destroy(opts, cb)
if (this.dht) {
this.dht._tables.remove(torrent.infoHash)
}
this.emit('remove', torrent);

Check failure on line 422 in index.js

View workflow job for this annotation

GitHub Actions / Node 18 / ubuntu-latest

Extra semicolon

Check failure on line 422 in index.js

View workflow job for this annotation

GitHub Actions / Node 16 / ubuntu-latest

Extra semicolon
LostBeard marked this conversation as resolved.
Show resolved Hide resolved
}

address () {
Expand Down