-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
client.get does not take the same "torrentId" that client.add does #2222
Comments
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? |
Yes - its still relevant, I'm not sure if its an API bug or at the very least a documentation bug. AFAIK noon familiar with the project has looked at it, so that's the blockr. |
When creating a torrent with a link (in this case), parse torrent uses the remote method: https://github.com/webtorrent/webtorrent/blob/master/lib/torrent.js#L218 But this is not the case when using Happy to review a PR if you are up for it |
I've found the codebase hard to get my head around, especially since functions aren't commented so its hard to know what they are intended to do, and therefore how to fix them without breaking something. I've took a but the solution to me seems different .... Line 306 in b62514c
this.torrents.push(torrent)
In client.get at Line 255 in b62514c
(this.torrents.includes(torrentId))
I don't think client.get should do an asynchronous https request for the torrent at this point (as is done in parse torrent), especially as this would make client.get asynchronous and complicate all kinds of client code. Instead, I think either:
The use case by the way is simple. I have a simple WebComponent that is a WebTorrentVideo that is passed a torrent URL and file name, and displays the video. (it has been added to a more comprehensive WebComponent that already displays other kinds of video, such as YouTube) client.add throws an error if passed a duplicate (which in itself I think is a design flaw), so my first design was to do a client.get and skip the add if the torrent has already being loaded, but that fails on URLs so ... Now what I do is within my WebComponent keep a mapping so the code effectively looks like ...
|
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? |
Why was this closed - it looks like it was closed by a bot, which suggests there are a bunch of other issues reported closed without being fixed ? |
What version of this package are you using?
1.5.6
What operating system, Node.js, and npm version?
OSX node 14.7.2 npm 7.24.1
What happened?
I did a client.add('http://localhost:4250/video/uptake blip video.torrent') which worked fine since the URL of the torrent is a valid torrentId for the "add" function
However client.get('http://localhost:4250/video/uptake blip video.torrent') returns null, even after the add has called its callback.
client.get(infoHash) works
STR
const torrentId = 'http://localhost:4250/video/uptake blip video.torrent'; # I'm using a local server for testing
WTclient.add(torrentId, function (torrent) {
console.log('T1=',WTclient.get(torrentId)) # null
console.log('T2=',WTclient.get(torrent.infoHash)) # Torrent
});
What did you expect to happen?
I would have expected that a valid torrentId passed to add, would also work for get
Are you willing to submit a pull request to fix this bug?
I'm not sure how to fix this while keeping with the design philosophy, the key challenge is that the "torrentId" used for client.add does not seem to be stored on either the torrent or the client.
I think .... that keeping a object on the client that hashes from torrentId to torrent would work, the key could be anything passed to torrent.add, so it would be a quick lookup,
Note - I can work around this - now I've realized why its not working, its not urgent for me, but if this is desired behavior, or not going to be fixed quickly, then I'd suggest change the API doc to make it clear that "torrentId" when passed to client.get is different from torrentId passed to client.add
The text was updated successfully, but these errors were encountered: