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

Magnet link with web seed does not work #376

Closed
marianobrc opened this issue Jul 16, 2015 · 23 comments
Closed

Magnet link with web seed does not work #376

marianobrc opened this issue Jul 16, 2015 · 23 comments

Comments

@marianobrc
Copy link

@marianobrc marianobrc commented Jul 16, 2015

Hi, i'm trying to make streaming to a HTML5 video tag. Here is my full code:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Web Torrent Player</title>
    <script src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js"></script>

</head>
<body style="background-color: black">

    <script>
        var showPlayer = function (){

            console.log('Creating WebTorrent Client..');
            var client = new WebTorrent();
            var magnetUri = 'magnet:?xt=urn:btih:4cb67059ed6bd08362da625b3ae77f6f4a075705&dn=bl001-introduction.webm&tr=http%3A%2F%2Ft.bitlove.org%2Fannounce&ws=http%3A%2F%2Fspaceboyz.net%2F%7Eastro%2Fbitlove-show%2Fbl001-introduction.webm';

            if(!client){
                console.log('ERROR creating WebTorrent Client!');
                return;
            }

            console.log('Adding torrent url..');
            client.add(magnetUri, function (torrent) {
                // Got torrent metadata!
                console.log('Torrent info hash:', torrent.infoHash);

                // Let's say the first file is a webm (vp8) or mp4 (h264) video...
                var file = torrent.files[0];

                // Create a video element
                var video = document.createElement('video');
                video.controls = true;
                document.body.appendChild(video);

                // Stream the video into the video tag
                file.createReadStream().pipe(video);
            });
        }

        // loads the player
        showPlayer();

    </script>
</body>
</html>

I'm getting different errors on the client.add(..) call, on firefox and chrome:

On firefox 38.0 on Ubuntu, i get this on the console:

"TypeError: a.parsedTorrent.pieces is undefined webtorrent.min.js:2:930"

On chrome 43.0.2357.125 on Ubuntu, i get this other error on the console:

"webtorrent.min.js:2 Uncaught TypeError: Cannot read property 'length' of undefined"

As the client.add(..) call fails, the video tag can't even load.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jul 17, 2015

Your code sample is out of date. file.createReadStream().pipe(video) doesn't work anymore.

Please update to the latest version of WebTorrent:

npm i webtorrent@latest --save

And update your code sample:

var WebTorrent = require('webtorrent')

var client = new WebTorrent()
var magnetUri = '...'

client.add(magnetUri, function (torrent) {
  // Got torrent metadata!
  console.log('Client is downloading:', torrent.infoHash)

  torrent.files.forEach(function (file) {
    // Display the file by appending it to the DOM. Supports video, audio, images, and
    // more. Specify a container element (CSS selector or reference to DOM node).
    file.appendTo('body')
  })
})
@feross feross closed this Jul 17, 2015
@marianobrc

This comment has been minimized.

Copy link
Author

@marianobrc marianobrc commented Jul 23, 2015

Hi, i'm not trying to use webtorrent on node.js. I'm trying to use is on
the browser at client-side, including the .js cdn link. Is that working?

Thanks, regards

2015-07-17 3:52 GMT-03:00 Feross Aboukhadijeh notifications@github.com:

Your code sample is out of date. file.createReadStream().pipe(video)
doesn't work anymore.

Please update to the latest version of WebTorrent:

npm i webtorrent@latest --save

And update your code sample:

var WebTorrent = require('webtorrent')
var client = new WebTorrent()var magnetUri = '...'

client.add(magnetUri, function (torrent) {
// Got torrent metadata!
console.log('Client is downloading:', torrent.infoHash)

torrent.files.forEach(function (file) {
// Display the file by appending it to the DOM. Supports video, audio, images, and
// more. Specify a container element (CSS selector or reference to DOM node).
file.appendTo('body')
})
})


Reply to this email directly or view it on GitHub
#376 (comment).

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jul 24, 2015

The code sample I pasted above was for the browser, just assuming browserify (which provides the require function). If you're using the script file from the CDN, then you can just delete the first line var WebTorrent = require('webtorrent').

The webtorrent script will set a WebTorrent function on the global window object.

So the new code snippet would be:

var client = new WebTorrent()
var magnetUri = '...'

client.add(magnetUri, function (torrent) {
  // Got torrent metadata!
  console.log('Client is downloading:', torrent.infoHash)

  torrent.files.forEach(function (file) {
    // Display the file by appending it to the DOM. Supports video, audio, images, and
    // more. Specify a container element (CSS selector or reference to DOM node).
    file.appendTo('body')
  })
})
@marianobrc

This comment has been minimized.

Copy link
Author

@marianobrc marianobrc commented Jul 24, 2015

Hi, thanks for your answer, and your patience.

I'm still getting the same error. This is the complete code now:

<title>Web Torrent Player</title> <script src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js"></script>
<script>
    var showPlayer = function (){

        console.log('Creating WebTorrent Client..')
        var client = new WebTorrent()
        var magnetUri = 'magnet:?xt=urn:btih:4cb67059ed6bd08362da625b3ae77f6f4a075705&dn=bl001-introduction.webm&tr=http%3A%2F%2Ft.bitlove.org%2Fannounce&ws=http%3A%2F%2Fspaceboyz.net%2F%7Eastro%2Fbitlove-show%2Fbl001-introduction.webm'

        if(!client){
            console.log('ERROR creating WebTorrent Client!')
            return;
        }

        console.log('Adding torrent url..');

    client.add(magnetUri, function (torrent) {
      // Got torrent metadata!
      console.log('Client is downloading:', torrent.infoHash)

      torrent.files.forEach(function (file) {
        // Display the file by appending it to the DOM. Supports video, audio, images, and
        // more. Specify a container element (CSS selector or reference to DOM node).
        file.appendTo('body')
      })
    })
    }

    // loads the player
    showPlayer();

</script>

It happens on the the client.add(..) call. The callback function does never executes.
Maybe de file.js on the CDN link isn't the right one?
I copied it from github examples.
https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js

Thanks

@deamme

This comment has been minimized.

Copy link

@deamme deamme commented Jul 25, 2015

Got the same issue, the callback function does never execute.

@feross feross reopened this Jul 26, 2015
@deamme

This comment has been minimized.

Copy link

@deamme deamme commented Jul 26, 2015

I've maybe misunderstood something? It works for instant.io torrents (magnet URI) but not normal torrents from other trackers. So just for webtorrents?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jul 26, 2015

@deamme

This comment has been minimized.

Copy link

@deamme deamme commented Jul 26, 2015

@feross Thank you!

@marianobrc

This comment has been minimized.

Copy link
Author

@marianobrc marianobrc commented Jul 26, 2015

I've tryed with the magnet uri of a torrent file that i took from the example torrent files on the repo.
Could you send me a magnet URI compatible with webtorrents to test it?

Thanks

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jul 26, 2015

@marianobrc I confirmed that the BitLove magnet link is not working. Magnet links with web seeds apparently cause WebTorrent to crash. I just confirmed this and wrote a test. Next, I'll fix it.

@feross feross changed the title Error trying to get video streaming on the browser Magnet link with web seed does not work Jul 26, 2015
@marianobrc

This comment has been minimized.

Copy link
Author

@marianobrc marianobrc commented Jul 26, 2015

@feross if you need any other info let me know. Thanks!

@deamme

This comment has been minimized.

Copy link

@deamme deamme commented Jul 26, 2015

@feross Shouldn't it work with http/https links also? Can't seem to get it working, says "invalid torrent identifier".

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jul 26, 2015

@deamme Please open a new issue. This issue thread is already quite long.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jul 27, 2015

@marianobrc Okay, the issue with the bitlove .torrent should be fixed in webtorrent 0.53.4.

@marianobrc

This comment has been minimized.

Copy link
Author

@marianobrc marianobrc commented Jul 27, 2015

Thank you @feross . Where can i get the lastest .js file?
Is it https://github.com/feross/webtorrent/webtorrent.min.js ?

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jul 27, 2015

@marianobrc

This comment has been minimized.

Copy link
Author

@marianobrc marianobrc commented Jul 27, 2015

Hi @feross . I've dowloaded the js and tested again my webpage.

Now i don't see any errors on the console. I only see the following warnings on Chrome, but not in Firefox:

webtorrent.min.js:7: The provided value 'ms-stream' is not a valid enum value of interface XMLHttpRequestResponseType.
webtorrent.min.js:7: The provided value 'moz-chunked-arraybuffer' is not a valid enum value of interface XMLHttpRequestResponseType.

But i still seeing that the callback funcion on the client.add(..) method isn't called, so the video isn't appended to the body. Is it something else that am i missing?

Thanks, regards

@feross

This comment has been minimized.

@marianobrc

This comment has been minimized.

Copy link
Author

@marianobrc marianobrc commented Jul 27, 2015

Thanks @feross, i get it now. I've seeded the torrent first using instant.io and then copied that magnet link and it works great!

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jul 27, 2015

@marianobrc Glad you got it figured out!

@vikrambarnwal

This comment has been minimized.

Copy link

@vikrambarnwal vikrambarnwal commented Jan 27, 2017

i want to store infoHash of torrent after start seeding (after drag & drop a file into browser generated MagnetURI) in mongodb in nodejs using webtorrent.
please help me @feross

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Jan 27, 2017

@vikrambarnwal Please don't ask for help in a random issue. Open a new issue.

@Nashorn

This comment has been minimized.

Copy link

@Nashorn Nashorn commented Apr 7, 2018

Hi, when .torrent file is created in the browser runtime, where are the .torrents stored? On instant.io?

@webtorrent webtorrent locked as off topic and limited conversation to collaborators May 15, 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
5 participants
You can’t perform that action at this time.