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

Keep the torrents in memory after close #1030

Closed
atmoner opened this issue Jan 28, 2017 · 5 comments
Closed

Keep the torrents in memory after close #1030

atmoner opened this issue Jan 28, 2017 · 5 comments

Comments

@atmoner
Copy link

@atmoner atmoner commented Jan 28, 2017

This is not really a question but more a request for help.
I would like to know if it is possible to keep in memory the torrents add?
Let me explain:

I create a software based on webtorrent with several different page and on each page I am obliged to declare the function add (and I think at the resource level it is not very good to do this for my software)

An example of this concept, retrieving the stats of each torrent in a graph

sans titre

In this example, whenever I call the stats.html page, I call the add() function and I add the torrent from hard code like:

 <script>

var Highcharts = require('highcharts');
const storage = require('electron-json-storage');
 
// Load module after Highcharts is loaded
require('highcharts/modules/exporting')(Highcharts);
require('highcharts/highcharts-3d')(Highcharts);
require('highcharts/highcharts-more.js')(Highcharts);

var WebTorrent = require('webtorrent')
var client = new WebTorrent()
var torrentId = 'https://webtorrent.io/torrents/sintel.torrent'
var torrent = client.add(torrentId,{ path: '/home/atmoner/Bureau/netix/' })
var torrentId2 = 'http://atmoner.fr/BigBuckBunny.torrent'
var torrent2 = client.add(torrentId2,{ path: '/home/atmoner/Bureau/netix/' })
 
torrent.on('ready', function (bytes) {
var outputStats = [];
var outputPeers = [];
client.torrents.forEach(function(element) { 
  outputStats.push(element.name);
  outputPeers.push(element.numPeers);
});	 
				
 
$(function () {
    Highcharts.chart('container', {
        chart: {
            type: 'column',
            options3d: {
                enabled: true,
                alpha: 10,
                beta: 25,
                depth: 70
            }
        },
        title: {
            text: 'Peers per torrent'
        },
        subtitle: {
            text: 'Get all torrents and assign peers value'
        },
        plotOptions: {
            column: {
                depth: 25
            }
        },
        xAxis: {
            categories: outputStats
        },
        yAxis: {
            title: {
                text: null
            }
        },
        series: [{
            name: 'Peers',
            data: outputPeers
        }]
    });
 
});
})  
 </script>

I thought I would use something like electron-json-storage
But it will not fix my problem of adding torrent to each page.

I take the problem from the other direction.
I assume that when you close webtorrent, the function destroy is calling to destroy the client, no?
Thanks in advance

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Jan 28, 2017

Share the client across your software, it will keep the torrents in memory

@atmoner

This comment has been minimized.

Copy link
Author

@atmoner atmoner commented Jan 28, 2017

Share the client across your software, it will keep the torrents in memory

Yep, i have did it on upload page:

// Get session of all torrents added and start it
storage.keys(function(error, keys) {
  if (error) throw error;

  for (var key of keys) {
	storage.get(key, function(error, data) {
	 if (error) throw error;
	 addTorrent(data.infoHash)
	});
  }
});	

And my function addTorrent:

var WebTorrent = require('webtorrent')
var client = new WebTorrent()
	function addTorrent(t){
		

		// Get error and log it

		// Add torrent(s)
		client.add(t,{ path: '/home/atmoner/Bureau/netix/' }, function (torrent,error) {
			$('#statuTorrent').append( '<br /><span class="icon icon-record" style="color:#22f900"></span> ' + torrent.name );
				        
			storage.set(torrent.infoHash, { pathFile: torrent.path+torrent.name, infoHash: torrent.infoHash }, function(error) {
			  if (error) throw error; 
			}); 
		})	
		client.on('error', function (err) {
				console.log(err)		 
		})
	}

Too bad for me that there is no internal session to webtorrent

@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Jan 28, 2017

You are creating a new client each time you add a torrent.

Create ONE client and use it across your app.

@atmoner

This comment has been minimized.

Copy link
Author

@atmoner atmoner commented Jan 28, 2017

You are creating a new client each time you add a torrent.

oups! yes thanks, code edited

@feross feross closed this Jan 29, 2017
@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.