mirror of
https://github.com/twisterarmy/twister-html.git
synced 2025-01-13 16:37:52 +00:00
fix issues trying to use WebTorrent before it was properly loaded/initialized
This commit is contained in:
parent
758f18fa73
commit
b762c645ee
@ -962,6 +962,15 @@ function applyShortenedURI(short, uriAndMimetype) {
|
||||
}
|
||||
|
||||
function startTorrentDownloadAndPreview(torrentId, previewContainer, isMedia) {
|
||||
if (typeof WebTorrentClient !== 'undefined') {
|
||||
_startTorrentDownloadAndPreview(torrentId, previewContainer, isMedia);
|
||||
} else {
|
||||
// delay execution until WebTorrent is loaded/initialized
|
||||
setTimeout(_startTorrentDownloadAndPreview,1000,torrentId, previewContainer, isMedia)
|
||||
}
|
||||
}
|
||||
|
||||
function _startTorrentDownloadAndPreview(torrentId, previewContainer, isMedia) {
|
||||
var torrent = WebTorrentClient.get(torrentId);
|
||||
if( torrent === null )
|
||||
torrent = WebTorrentClient.add(torrentId);
|
||||
|
@ -309,6 +309,9 @@ function initWebTorrent() {
|
||||
//localStorage.debug = '*'
|
||||
localStorage.removeItem('debug')
|
||||
|
||||
if ($.localStorage.isSet('torrentIds'))
|
||||
twister.torrentIds = $.localStorage.get('torrentIds');
|
||||
|
||||
WEBTORRENT_ANNOUNCE = $.Options.WebTorrentTrackers.val.split(/[ ,]+/)
|
||||
$.getScript('js/webtorrent.min.js', function() {
|
||||
WebTorrentClient = new WebTorrent();
|
||||
@ -320,9 +323,6 @@ function initWebTorrent() {
|
||||
console.error('WARNING: ' + err.message);
|
||||
});
|
||||
|
||||
if ($.localStorage.isSet('torrentIds'))
|
||||
twister.torrentIds = $.localStorage.get('torrentIds');
|
||||
|
||||
$.getScript('js/localforage.min.js', function() {
|
||||
localforage.setDriver([localforage.INDEXEDDB,localforage.WEBSQL]).then(function() {
|
||||
for (var torrentId in twister.torrentIds) {
|
||||
|
Loading…
Reference in New Issue
Block a user