Added WebTorrent add and remove events and docs update #2766
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the purpose of this pull request? (put an "X" next to item)
[X] Documentation update
[ ] Bug fix
[X] New feature
[ ] Other, please explain:
What changes did you make? (Give an overview)
Added the events 'add' and 'remove' that are fired when a torrent is added to or removed from client.torrents.
This allows attaching to torrent events that may be emitted before the client 'torrent' event is emitted.
I am in a situation where I want to use a custom wire extension on every torrent. I initially tried to listen on the client.on('torrent') event but sometimes the Torrent 'wire' event was firing before the 'torrent' event so it was missed, and my wire extension could not be added via wire.use(). Attaching a 'wire' event handler to the torrent immediately after getting it from client.add() and client.seed() avoided this issue but it meant this had to be done to the torrent after calling client.add or client.seed. Which makes using and sharing custom wire extensions more cumbersome than it needs to be.
Is there anything you'd like reviewers to focus on?
This is a very simple modification. I have added an update to the docs and the code.