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-01-28 07:15:22 +0400
committerFeross Aboukhadijeh <feross@feross.org>2014-01-28 07:15:22 +0400
commit337cd5d3971ca7d780ca8c1b99e747af6b3633d4 (patch)
tree2cd9c0ea5f58d9ca7bf207b2fb21c152529d9207
parentf93448d3a757abe9fe13e5d458e1046db9469dde (diff)
show torrent info in chrome app ui
-rw-r--r--chrome/background.js4
-rw-r--r--chrome/style.css4
-rw-r--r--chrome/window.html14
-rw-r--r--index.js94
-rw-r--r--package.json24
5 files changed, 79 insertions, 61 deletions
diff --git a/chrome/background.js b/chrome/background.js
index 9699018..d740b15 100644
--- a/chrome/background.js
+++ b/chrome/background.js
@@ -1,8 +1,8 @@
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('window.html', {
bounds: {
- width: 400,
- height: 500
+ width: 500,
+ height: 600
}
});
}); \ No newline at end of file
diff --git a/chrome/style.css b/chrome/style.css
new file mode 100644
index 0000000..cb019c5
--- /dev/null
+++ b/chrome/style.css
@@ -0,0 +1,4 @@
+#console {
+ height: 400px;
+ overflow: scroll;
+} \ No newline at end of file
diff --git a/chrome/window.html b/chrome/window.html
index 44339ee..63c2938 100644
--- a/chrome/window.html
+++ b/chrome/window.html
@@ -1,9 +1,21 @@
<!DOCTYPE html>
<html>
<head>
+ <title>WebTorrent</title>
+ <link rel="stylesheet" href="style.css">
</head>
<body>
+ <h3>Torrent Info</h4>
+ <ul>
+ <li class="displayName">Display Name: <span></span></li>
+ <li class="infoHash">Info Hash: <span></span></li>
+ <li class="dhtNodes">DHT Nodes: <span>0</span></li>
+ <li class="dhtPeers">DHT Peers: <span>0</span></li>
+ </ul>
+
+ <h3>Console</h4>
<div id="console"></div>
- <script src='bundle.js'></script>
+
+ <script src="bundle.js"></script>
</body>
</html> \ No newline at end of file
diff --git a/index.js b/index.js
index c28a4a8..84df327 100644
--- a/index.js
+++ b/index.js
@@ -1,78 +1,62 @@
-/* global chrome */
-
-// window.log = function (data) {
-// document.getElementById('console').innerHTML += data + '<br>'
-// }
-// window.log = function (/* ... */) {
-// if (process.env.DEBUG !== 'false') console.log.apply(console, arguments)
-// }
+window.log = function (data) {
+ var elem = document.getElementById('console')
+ elem.innerHTML += data + '<br>'
+ elem.scrollTop = elem.scrollHeight
+}
-var Protocol = require('bittorrent-protocol')
+var $ = require('jquery')
var DHT = require('bittorrent-dht')
var hat = require('hat')
var magnet = require('magnet-uri')
-var net = require('net')
var Swarm = require('bittorrent-swarm')
+var MAX_PEERS = 60
+var METADATA_BLOCK_SIZE = 16 * 1024
+
var isChromeApp = !!(typeof window !== 'undefined' && window.chrome &&
- chrome.app && chrome.app.runtime)
-if (isChromeApp) {
+ window.chrome.app && window.chrome.app.runtime)
+if (isChromeApp)
console.log('This is a Chrome App')
-}
var peerId = '-WW0001-' + hat(48)
-// var pride = '1E69917FBAA2C767BCA463A96B5572785C6D8A12'
-// var leaves = 'D2474E86C95B19B8BCFDB92BC12C9D44667CFA36'
+function magnetToInfoHash (uri) {
+ try {
+ return magnet(uri).xt.split('urn:btih:')[1]
+ } catch (e) {
+ return null
+ }
+}
+
+function magnetToDisplayName (uri) {
+ try {
+ return magnet(uri).dn
+ } catch (e) {
+ return null
+ }
+}
-var leavesMagnet = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.istole.it%3A6969&tr=udp%3A%2F%2Ftracker.ccc.de%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337'
+var magnetUri = 'magnet:?xt=urn:btih:d2474e86c95b19b8bcfdb92bc12c9d44667cfa36&dn=Leaves+of+Grass+by+Walt+Whitman.epub'
+var infoHash = magnetToInfoHash(magnetUri)
+var displayName = magnetToDisplayName(magnetUri)
-var infoHash
-try {
- infoHash = magnet(leavesMagnet).xt.split('urn:btih:')[1]
-} catch (e) {}
+$('.infoHash span').text(infoHash)
+$('.displayName span').text(displayName)
+var dht = new DHT(infoHash)
+dht.findPeers(MAX_PEERS)
-var dht = window.dht = new DHT(infoHash)
var swarm = new Swarm(infoHash, peerId)
dht.on('node', function (node, infoHash) {
- // console.log('node: ' + node)
+ var num = Number($('.dhtNodes span').text())
+ $('.dhtNodes span').text(num + 1)
})
dht.on('peer', function (peer, infoHash) {
- console.log('peer: ' + peer)
- swarm.add(peer)
+ var num = Number($('.dhtPeers span').text())
+ $('.dhtPeers span').text(num + 1)
- var parts = peer.split(':')
- var conn = net.connect(parts[1], parts[0])
-
- var wire = Protocol()
-
- conn.on('end', function() {
- conn.destroy()
- })
- conn.on('error', function() {
- conn.destroy()
- })
- conn.on('close', function() {
- wire.end()
- })
-
- wire.once('handshake', function(infoHash2, peerId, extensions) {
- console.log('HANDSHAKE SUCCESS')
- if (infoHash2.toString('hex') !== infoHash.toString('hex')) return conn.destroy()
- })
-
- conn.pipe(wire).pipe(conn)
-
- wire.on('end', function() {
- console.log('WIRE END')
- })
-
- wire.remoteAddress = peer
- wire.handshake(infoHash, peerId)
+ log('peer: ' + peer)
+ swarm.add(peer)
})
-dht.findPeers(300)
-
-var METADATA_BLOCK_SIZE = 1024*16
diff --git a/package.json b/package.json
index 4949b11..af20a25 100644
--- a/package.json
+++ b/package.json
@@ -13,11 +13,14 @@
"hat": "0.0.3",
"magnet-uri": "0.x",
"read-torrent": "~0.2.0",
- "speedometer": "~0.1.2"
+ "speedometer": "~0.1.2",
+ "jquery": "~2.1.0",
+ "browserify-shim": "~3.2.2"
},
"devDependencies": {
+ "nodemon": "1.x",
"tape": "2.x",
- "nodemon": "~1.0.13"
+ "watchify": "0.x"
},
"scripts": {
"build": "browserify --debug index.js > chrome/bundle.js",
@@ -25,6 +28,17 @@
"start": "npm run build && ./bin/start.js",
"test": "tape test/*.js"
},
+ "browser": {
+ "jquery": "./node_modules/jquery/dist/jquery.min.js"
+ },
+ "browserify": {
+ "transform": [
+ "browserify-shim"
+ ]
+ },
+ "browserify-shim": {
+ "jquery": "jQuery"
+ },
"repository": {
"type": "git",
"url": "git://github.com/feross/webtorrent.git"
@@ -38,7 +52,11 @@
"webtorrent",
"mad science"
],
- "author": "Feross Aboukhadijeh <feross@feross.org> (http://feross.org/)",
+ "author": {
+ "name": "Feross Aboukhadijeh",
+ "email": "feross@feross.org",
+ "url": "http://feross.org/"
+ },
"license": "MIT",
"bugs": {
"url": "https://github.com/feross/webtorrent/issues"