4

I have some idea for WebTorrent. I have some experience with JavaScript and jQuery, but I never use Node.js or Browserify. Could someone explain me how to use the following simple code?

var client = new WebTorrent()

var torrentId = 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d'

client.add(torrentId, function (torrent) {
  // Torrents can contain many files. Let's use the first.
  var file = torrent.files[0]

  // Display the file by adding it to the DOM. Supports video, audio, image, etc. files
  file.appendTo('body')
})

Should I attach a <script src="webtorrent.min.js"></script> and convert the code from above by Browserify (browserify app.js > bundle.js)? Or maybe I need to use npm install webtorrent and attach some Browserify code?

After using the code npm install webtorrent and just doing Ctrl + c + Ctrl + v, this example from above in <script> tag showed up player. Magic :) But I do something in my VM and now Chrome say that the require('webtorrent') is not definied.

It would be great if I could use WebTorrent as simple as jQuery.

1
  • If you use the standalone js file (<script src="webtorrent.min.js"></script>), you don't need browserify or require.
    – Shanoor
    Dec 25, 2015 at 11:33

1 Answer 1

3

With the code you posted, you don't need to require. If you use the standalone minified version, you can use use var client = WebTorrent()and start using it.

Here's an old example: http://jsfiddle.net/fr090taa/ when I answered this: How to use webtorrent.io

Don't use node/npm/browserify. Just use the minified version.

Check https://github.com/DiegoRBaquero/BTorrent (there's also a clean compiled version to view in JS instead of Coffee)

I'm a WebTorrent project contributor.

4
  • Thx. So Webtorrent is very simple in use :) How about Webtorrent-hybrid? There is no standalone version, and I have to use all peers. I must install webtorrent-hybrid in node? Wrtc (unfortunately) is big problem, especially on Azure.
    – Sokołow
    Dec 26, 2015 at 19:43
  • 1
    webtorrent-hybrid imho is broken. There's nothing bridging the two torrenting networks yet that works as it should. Dec 30, 2015 at 2:04
  • Is there any alternative for bittorrent-hybrid? I would like to use bittorrent, not webtorrent. I do not need a hybrid solution, just bittorrent.
    – Sokołow
    Dec 30, 2015 at 21:16
  • For the time being, no. The thing is, if you want to use BitTorrent you can, in the browser, only with extensions; not purely as one would like. Dec 31, 2015 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.