mirror of
https://github.com/fluencelabs/dweb-transports
synced 2025-03-15 18:30:49 +00:00
Set window.WEBTORRENT_FILE in addition to WEBTORRENT_TORRENT
This commit is contained in:
parent
9cd3dce3b3
commit
19ab719478
@ -141,13 +141,6 @@ class TransportWEBTORRENT extends Transport {
|
|||||||
resolve(torrent);
|
resolve(torrent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof window !== "undefined") { // Check running in browser
|
|
||||||
window.WEBTORRENT_TORRENT = torrent;
|
|
||||||
torrent.once('close', () => {
|
|
||||||
window.WEBTORRENT_TORRENT = null
|
|
||||||
})
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,9 +201,18 @@ class TransportWEBTORRENT extends Transport {
|
|||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
const {torrentId, path} = this.webtorrentparseurl(url);
|
const {torrentId, path} = this.webtorrentparseurl(url);
|
||||||
let torrent = await this.p_webtorrentadd(torrentId);
|
const torrent = await this.p_webtorrentadd(torrentId);
|
||||||
torrent.deselect(0, torrent.pieces.length - 1, false); // Dont download entire torrent as will pull just the file we want (warning - may give problems if multiple reads from same webtorrent)
|
torrent.deselect(0, torrent.pieces.length - 1, false); // Dont download entire torrent as will pull just the file we want (warning - may give problems if multiple reads from same webtorrent)
|
||||||
return this.webtorrentfindfile(torrent, path);
|
const file = this.webtorrentfindfile(torrent, path);
|
||||||
|
if (typeof window !== "undefined") { // Check running in browser
|
||||||
|
window.WEBTORRENT_TORRENT = torrent;
|
||||||
|
window.WEBTORRENT_FILE = file;
|
||||||
|
torrent.once('close', () => {
|
||||||
|
window.WEBTORRENT_TORRENT = null;
|
||||||
|
window.WEBTORRENT_FILE = null;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return file
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.log(`p_fileFrom failed on ${url} ${err.message}`);
|
console.log(`p_fileFrom failed on ${url} ${err.message}`);
|
||||||
throw(err);
|
throw(err);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user