File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 11const ZComponent = require ( 'zcomponent' )
22const WebTorrent = require ( 'webtorrent' )
3+ const magnetURL = require ( 'magnet-uri' )
34
45const 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+
618class 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 } )
Original file line number Diff line number Diff line change 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 },
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" ,
3846 "type" : " git" ,
3947 "url" : " https://github.com/mikeal/webtorrent-component.git"
4048 }
41- }
49+ }
You can’t perform that action at this time.
0 commit comments