webtorrent / webtorrent-hybrid

WebTorrent (with WebRTC support in Node.js)
https://webtorrent.io
MIT License
519 stars 98 forks source link

Webtorrent-hybrid not working in my browser *Help* #106

Closed adamwoo2444 closed 4 years ago

adamwoo2444 commented 5 years ago

Thank you @feross for this wonderful project. Please help me,actually I am using webtorrent-hybrid and its not showing anything. This is my code for node-js

var WebTorrent = require('webtorrent-hybrid')

var client = new WebTorrent()

        client.on('error', function (err) {
          console.error('ERROR: ' + err.message)
        })

        document.querySelector('form').addEventListener('submit', function (e) {
          e.preventDefault() // Prevent page refresh

          var torrentId = document.querySelector('form input[name=torrentId]').value
          log('Adding ' + torrentId)
          client.add(torrentId, onTorrent)
        })

        function onTorrent (torrent) {
          log('Got torrent metadata!')
          log(
            'Torrent info hash: ' + torrent.infoHash + ' ' +
            '<a href="' + torrent.magnetURI + '" target="_blank">[Magnet URI]</a> ' +
            '<a href="' + torrent.torrentFileBlobURL + '" target="_blank" download="' + torrent.name + '.torrent">[Download .torrent]</a>'
          )

          // Print out progress every 5 seconds
          var interval = setInterval(function () {
            log('Progress: ' + (torrent.progress * 100).toFixed(1) + '%')
          }, 5000)

          torrent.on('done', function () {
            log('Progress: 100%')
            clearInterval(interval)
          })

          // Render all files into to the page
          torrent.files.forEach(function (file) {
            file.appendTo('.log')
            log('(Blob URLs only work if the file is loaded from a server. "http//localhost" works. "file://" does not.)')
            file.getBlobURL(function (err, url) {
              if (err) return log(err.message)
              log('File done.')
              log('<a href="' + url + '">Download full file: ' + file.name + '</a>')
            })
          })
        }

        function log (str) {
          var p = document.createElement('p')
          p.innerHTML = str
          document.querySelector('.log').appendChild(p)
        }

After browserify server_.js > bundle.js and putting the bundle.js in HTML. Its not showing anything.Please let me know where I am wrong.

<!doctype html>
<html>

<body>
    <h1>Download files using the WebTorrent protocol (BitTorrent over WebRTC).</h1>

    <form>
        <label for="torrentId">Download from a magnet link: </label>
        <input name="torrentId" , placeholder="magnet:"
            value="magnet:?xt=">
        <button type="submit">Download</button>
    </form>

    <h2>Log</h2>
    <div class="log"></div>

    <!-- Include the latest version of WebTorrent -->
    <script src="/Users/apple/Documents/instant.io/bundle.js"></script>
</body>

</html>

</script>
feross commented 4 years ago

Do not use WebTorrent for copyright infringement. No one will be able to assist you.