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

Event metadata and ready not work #1580

Closed
rickylawson opened this issue Feb 7, 2019 · 2 comments
Closed

Event metadata and ready not work #1580

rickylawson opened this issue Feb 7, 2019 · 2 comments

Comments

@rickylawson
Copy link

@rickylawson rickylawson commented Feb 7, 2019

Latest webtorrent 0.103.0
Windows 10, v10.15.0

        const webtorrent = require('webtorrent');
        const client = new webtorrent();
            client.add('391881E62436BFE67EDCFA49E1580AF89D5F5038', torrent => {
                torrent.on('noPeers', () => {
                    console.log('noPeers');
                    torrent.files.forEach(function(file) {
                        console.log(file.name);
                    });
                });
                torrent.on('metadata', () => {
                    console.log('metadata');
                    torrent.files.forEach(function(file) {
                        console.log(file.name);
                    });
                });
                torrent.on('ready', () => {
                    console.log('ready');
                    torrent.files.forEach(function(file) {
                        console.log(file.name);
                    });
                });
                torrent.on('warning', () => {
                    console.log('warning');
                    torrent.files.forEach(function(file) {
                        console.log(file.name);
                    });
                });
                torrent.on('error', () => {
                    console.log('error');
                    torrent.files.forEach(function(file) {
                        console.log(file.name);
                    });
                });
                torrent.on('done', () => {
                    console.log('done');
                    torrent.files.forEach(function(file) {
                        console.log(file.name);
                    });
                });
            });

Result:

warning
...files...
warning
...files...
warning
...files...
done
...files...

Event metadata? Event ready?

@alxhotel

This comment has been minimized.

Copy link
Member

@alxhotel alxhotel commented Feb 21, 2019

In your code you are trying to listen for a metadata event already emitted. The same goes with the ready event. Try this code instead:

const webtorrent = require('webtorrent');
const client = new webtorrent();
var torrent = client.add('391881E62436BFE67EDCFA49E1580AF89D5F5038');
torrent.on('noPeers', () => {
    console.log('noPeers');
    torrent.files.forEach(function(file) {
		console.log(file.name);
    });
});
torrent.on('metadata', () => {
    console.log('metadata');
    torrent.files.forEach(function(file) {
		console.log(file.name);
    });
});
torrent.on('ready', () => {
    console.log('ready');
    torrent.files.forEach(function(file) {
		console.log(file.name);
    });
});
torrent.on('warning', () => {
    console.log('warning');
    torrent.files.forEach(function(file) {
		console.log(file.name);
    });
});
torrent.on('error', () => {
    console.log('error');
    torrent.files.forEach(function(file) {
		console.log(file.name);
    });
});
torrent.on('done', () => {
    console.log('done');
    torrent.files.forEach(function(file) {
		console.log(file.name);
    });
});
@rickylawson

This comment has been minimized.

Copy link
Author

@rickylawson rickylawson commented Feb 21, 2019

Thanks @alxhotel, it works.

@lock lock bot locked as resolved and limited conversation to collaborators May 22, 2019
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
2 participants
You can’t perform that action at this time.