Browse Source

fix issues trying to use WebTorrent before it was properly loaded/initialized

readme-update
Miguel Freitas 9 years ago
parent
commit
b762c645ee
  1. 9
      js/interface_common.js
  2. 6
      js/interface_home.js

9
js/interface_common.js

@ -962,6 +962,15 @@ function applyShortenedURI(short, uriAndMimetype) {
} }
function startTorrentDownloadAndPreview(torrentId, previewContainer, isMedia) { 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); var torrent = WebTorrentClient.get(torrentId);
if( torrent === null ) if( torrent === null )
torrent = WebTorrentClient.add(torrentId); torrent = WebTorrentClient.add(torrentId);

6
js/interface_home.js

@ -309,6 +309,9 @@ function initWebTorrent() {
//localStorage.debug = '*' //localStorage.debug = '*'
localStorage.removeItem('debug') localStorage.removeItem('debug')
if ($.localStorage.isSet('torrentIds'))
twister.torrentIds = $.localStorage.get('torrentIds');
WEBTORRENT_ANNOUNCE = $.Options.WebTorrentTrackers.val.split(/[ ,]+/) WEBTORRENT_ANNOUNCE = $.Options.WebTorrentTrackers.val.split(/[ ,]+/)
$.getScript('js/webtorrent.min.js', function() { $.getScript('js/webtorrent.min.js', function() {
WebTorrentClient = new WebTorrent(); WebTorrentClient = new WebTorrent();
@ -320,9 +323,6 @@ function initWebTorrent() {
console.error('WARNING: ' + err.message); console.error('WARNING: ' + err.message);
}); });
if ($.localStorage.isSet('torrentIds'))
twister.torrentIds = $.localStorage.get('torrentIds');
$.getScript('js/localforage.min.js', function() { $.getScript('js/localforage.min.js', function() {
localforage.setDriver([localforage.INDEXEDDB,localforage.WEBSQL]).then(function() { localforage.setDriver([localforage.INDEXEDDB,localforage.WEBSQL]).then(function() {
for (var torrentId in twister.torrentIds) { for (var torrentId in twister.torrentIds) {

Loading…
Cancel
Save