8

https://github.com/feross/webtorrent#usageに示されている例に問題があり ます。ブラウザーでコードを使用しようとしています。そこで、最初に app.js というファイルを作成します

app.js

var WebTorrent = require('webtorrent')
var concat = require('concat-stream')

var client = new WebTorrent()
console.log('Hi there');
client.download('magnet:?xt=urn:btih:XXXXXXXX', function (torrent) {
  // Got torrent metadata!
  console.log('Torrent info hash:', torrent.infoHash)

  torrent.files.forEach(function (file) {
    // Get the file data as a Buffer (Uint8Array typed array)
    file.createReadStream().pipe(concat(function (buf) {

      // Append a link to download the file
      var a = document.createElement('a')
      a.download = file.name
      a.href = URL.createObjectURL(new Blob([ buf ]))
      a.textContent = 'download ' + file.name
      document.body.appendChild(a)
    }))
  })
})

次に、コマンドを入力browserify app.js > bundle.jsして、ブラウザでコードを機能させることができます。index.html という別のファイルを作成します。

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>test</title>
    <script src="bundle.js"></script>
</head>

<body id="home">

    <h1>test</h1>


</body>
</html>

コンソールからは「こんにちは」しか見えません。client.download() 関数が機能しなかったようです。なぜこれが起こったのですか?私は browserify を初めて使用します。使用しているコマンドに問題はありますか?

4

1 に答える 1

9

WebTorrent は、WebTorrent ネットワークに明示的にシードされたトレントのみをダウンロードできます。トレント クライアントは、Web ブラウザーとピアリングするために WebRTC をサポートする必要があります。現在、これをサポートするクライアントはありませんが、http://instant.io を使用して新しい torrent のシードを開始し、アプリケーションで WebTorrent ライブラリを使用してダウンロードを試みることができます。トレントの情報ハッシュを取得するには、`localStorage.debug = '*' を設定して、 http://instant.ioでデバッグ ログを有効にします。

ここでも詳細を確認できます。

于 2014-11-29T09:50:39.573 に答える