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

List all torrents api #1028

Closed
atmoner opened this issue Jan 25, 2017 · 9 comments
Closed

List all torrents api #1028

atmoner opened this issue Jan 25, 2017 · 9 comments

Comments

@atmoner
Copy link

@atmoner atmoner commented Jan 25, 2017

What version of WebTorrent?
WebTorrent 1.9.0 (0.98.3)

What operating system and Node.js version?
Ubuntu 16.04 & Node v7.4.0

What browser and version? (if using WebTorrent in the browser)
No browser, in electron

What did you expect to happen?

  1. I would like to know if it is possible to access the list of torrents?
    For now, I try the function client.torrents but it returns me only the name of the torrent currently in action
  2. Why does the client.torrents function only work in client.add?
      client.add(torrentId, function (torrent) {
  		log(util.inspect(client.torrents)) // Work, get 1 torrent
      }
      log(util.inspect(client.torrents)) // Not Work, get 'undefinied'
      client.add(torrentId, function (torrent) {
  		
      }
@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Jan 26, 2017

You should be getting an empty array. Do you really get undefined???

See index.js#L86

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 26, 2017

@atmoner Can you share your complete code? Without that we can't really help you.

@feross feross closed this Jan 26, 2017
@atmoner

This comment has been minimized.

Copy link
Author

@atmoner atmoner commented Jan 26, 2017

@feross of course!

The context

I code from electron
When I do my tests, I run a torrent with webtorrent-cli and a torrent from my software (which runs with webtorrent too)

The code is very basic:

<script src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js"></script>
<script>
	 var torrentId = 'https://webtorrent.io/torrents/sintel.torrent'
	 var client = new WebTorrent()
	 var util = require('util')
	
	client.add(torrentId, function (torrent) {
	    console.log(Array.isArray(client.torrents)); // return true
	    client.torrents.forEach(function(element) {
	    console.log(element.name); // Return only sintel.mp4
	});		 		      
})
</script>

Webtorrent + my soft so 2 torrents runing but out of log give just one

1

In my example, I try to log the torrents from the add function but I would like to be able to call it outside of this function.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 26, 2017

I believe you're using the wrong terminology. You are trying to print the number of peers, but what you are actually printing is the number of torrents.

A torrent is a set of files that are shared via the BitTorrent protocol.
A peer is a computer that your BitTorrent client connects to, in order to retrieve files

Try this:

var client = new WebTorrent()
var torrentId = 'https://webtorrent.io/torrents/sintel.torrent'
var torrent = client.add(torrentId)

// Note: we refer to "peers" as "wires" in the WebTorrent codebase sometimes
torrent.on('wire', function (wire) {
  console.log('Now connected to ' + torrent.numPeers + ' peers')
  if (wire.remoteAddress) {
    console.log(wire.remoteAddress + ':' + wire.remotePort)
  }
})
@atmoner

This comment has been minimized.

Copy link
Author

@atmoner atmoner commented Jan 26, 2017

I believe you're using the wrong terminology. You are trying to print the number of peers, but what you are actually printing is the number of torrents.

No no ^^ I am really trying to display the list of torrents active in webtorrent (if it is possible obviously) ...

A torrent is a set of files that are shared via the BitTorrent protocol.
A peer is a computer that your BitTorrent client connects to, in order to retrieve files

For the connect peers it's ok, Webtorrent does very well this spot on a torrent but my final goal would be to create a mini torrent client with the simple functionality of webtorrent.

  • Adding torrent (s)
  • List the torrents
  • Edit / delete
  • ....

I almost do everything except the list of torrents!
Thanks for your snip, It will be useful to me later ;)

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 26, 2017

I don't understand why you expect your snippet to return more than 1 torrent. You're only adding 1 torrent to the client.

	 var torrentId = 'https://webtorrent.io/torrents/sintel.torrent'
	 var client = new WebTorrent()
	 var util = require('util')
	
	client.add(torrentId, function (torrent) {
	    console.log(Array.isArray(client.torrents)); // return true
	    client.torrents.forEach(function(element) {
	    console.log(element.name); // Return only sintel.mp4
	});	
@atmoner

This comment has been minimized.

Copy link
Author

@atmoner atmoner commented Jan 26, 2017

On my screen I add a torrent from my software and a torrent with webtorrent-cli. But return only 1 torrent

You're only adding 1 torrent to the client.

Ah! it's my another question, Can I add several torrent at once?

@atmoner

This comment has been minimized.

Copy link
Author

@atmoner atmoner commented Jan 26, 2017

Done for me! You had pointed out The right mistake, It was enough to add a second torrent as a result
Thank you very much for your work !! 👍

Code work:

var client = new WebTorrent()
var torrentId = 'https://webtorrent.io/torrents/sintel.torrent'
var torrent = client.add(torrentId)
var torrentId2 = 'https://website.io/another.torrent'
var torrent2 = client.add(torrentId2)
	
// Note: we refer to "peers" as "wires" in the WebTorrent codebase sometimes
torrent.on('wire', function (wire) {
	 // console.log('Now connected to ' + torrent.numPeers + ' peers')
	client.torrents.forEach(function(element) {
			console.log(element.name); // Return only sintel.mp4
	});
})

2

@lock

This comment has been minimized.

Copy link

@lock lock bot commented May 4, 2018

This thread has been automatically locked because it has not had recent activity. To discuss futher, please open a new issue.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.