Skip to content

Commit 8187c4a

Browse files
committed
fix(webtorrent): Allow duplicate torrents to be on the page.
1 parent 5c651cc commit 8187c4a

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
const ZComponent = require('zcomponent')
22
const WebTorrent = require('webtorrent')
3+
const magnetURL = require('magnet-uri')
34

45
const client = new WebTorrent()
56

7+
const getTorrent = (magnet, fn) => {
8+
let decoded = magnetURL(magnet)
9+
for (let torrent of client.torrents) {
10+
if (torrent.infoHash === decoded.infoHash) {
11+
// TODO: make sure all trackers and web seeds are added
12+
return fn(torrent)
13+
}
14+
}
15+
client.add(magnet, fn)
16+
}
17+
618
class WebTorrentElement extends ZComponent {
719
set file (file) {
820
this._file = file
921
}
1022
set src (magnet) {
11-
client.add(magnet, torrent => {
23+
getTorrent(magnet, torrent => {
1224
torrent.files.forEach(file => {
1325
if (this._file) {
1426
if (file.name === this._file || file.path === this._file) {
1527
file.appendTo(this)
1628
}
29+
} else {
30+
file.appendTo(this)
1731
}
1832
})
1933
})

package.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"start": "budo dist.js:bundle.js",
1010
"precommit": "npm test",
1111
"prepush": "npm test",
12-
"prepublish": "mkdir -p dist && browserify dist.js > dist/webtorrent-element.js && cat dist/webtorrent-element.js | minify > dist/webtorrent-element.min.js",
12+
"prepublishOnly": "distjs",
1313
"commitmsg": "validate-commit-msg",
1414
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
1515
},
@@ -18,17 +18,25 @@
1818
"dist"
1919
]
2020
},
21+
"config": {
22+
"commitizen": {
23+
"path": "./node_modules/cz-conventional-changelog"
24+
}
25+
},
2126
"keywords": [],
2227
"author": "Mikeal Rogers <[email protected]> (http://www.mikealrogers.com)",
2328
"license": "Apache-2.0",
2429
"dependencies": {
30+
"distjs": "^1.0.0",
31+
"magnet-uri": "^5.1.7",
2532
"webtorrent": "^0.98.19",
2633
"zcomponent": "^1.0.4"
2734
},
2835
"devDependencies": {
2936
"babel-minify": "^0.2.0",
3037
"browserify": "^14.4.0",
3138
"budo": "^10.0.4",
39+
"cz-conventional-changelog": "^2.0.0",
3240
"husky": "^0.14.3",
3341
"load-js": "^2.0.0",
3442
"standard": "^10.0.3",
@@ -38,4 +46,4 @@
3846
"type": "git",
3947
"url": "https://github.com/mikeal/webtorrent-component.git"
4048
}
41-
}
49+
}

0 commit comments

Comments
 (0)