Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeross Aboukhadijeh <feross@feross.org>2014-09-21 05:41:24 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-09-21 05:41:24 +0400
commit93686505fbc90522c75b6c151ec7261aa76098de (patch)
tree5b474b920e79b7b39b6804fac5e6a641de6ae843 /test/metadata.js
parent2e14192c311f64c20496a72af7ffce36495be92b (diff)
merge `bittorrent-client` into this module
When I started the WebTorrent project I thought there were going to need to be two separate client implementations (bittorrent-client and webtorrent-client) that would get tied together in a higher-level module. Fortunately, this was not necessary because of the awesome “browser” field support in browserify. By substituting just a few modules, we can make the same module (webtorrent) work in node AND the browser, with the same codebase! So, from now on, you can just `require(‘webtorrent’)` in node or the browser, and it will just work. You can also `npm install webtorrent` if you want to use bittorrent in a node app or script. Lastly, you can `npm install webtorrent -g` if you want to use webtorrent as a command line app (it installs a `webtorrent` command).
Diffstat (limited to 'test/metadata.js')
-rw-r--r--test/metadata.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/metadata.js b/test/metadata.js
new file mode 100644
index 0000000..5c86b79
--- /dev/null
+++ b/test/metadata.js
@@ -0,0 +1,47 @@
+var BitTorrentClient = require('../')
+var parseTorrent = require('parse-torrent')
+var test = require('tape')
+var fs = require('fs')
+
+var leaves = fs.readFileSync(__dirname + '/torrents/leaves.torrent')
+var leavesTorrent = parseTorrent(leaves)
+
+test('ut_metadata transfer', function (t) {
+ t.plan(5)
+
+ var client1 = new BitTorrentClient({ dht: false, trackers: false })
+ var client2 = new BitTorrentClient({ dht: false, trackers: false })
+
+ client1.on('torrent', function (torrent) {
+ t.pass('client1 emits torrent event') // even though it started with metadata
+ })
+
+ // client1 starts with metadata from torrent file
+ client1.add(leaves)
+
+ client1.on('error', function (err) { t.fail(err) })
+ client2.on('error', function (err) { t.fail(err) })
+
+ client1.on('torrent', function (torrent1) {
+ t.deepEqual(torrent1.parsedTorrent.info, leavesTorrent.info)
+
+ // client2 starts with infohash
+ client2.add(leavesTorrent.infoHash)
+
+ client2.on('listening', function (port, torrent2) {
+ // manually add the peer
+ torrent2.addPeer('127.0.0.1:' + client1.torrentPort)
+
+ client2.on('torrent', function () {
+ t.deepEqual(torrent1.parsedTorrent.info, torrent2.parsedTorrent.info)
+
+ client1.destroy(function () {
+ t.pass('client1 destroyed')
+ })
+ client2.destroy(function () {
+ t.pass('client2 destroyed')
+ })
+ })
+ })
+ })
+})