add fetch timeout

This commit is contained in:
Luke Pulverenti 2015-12-06 23:57:04 -05:00
parent 7c3fa06651
commit ba5afc0ae2
14 changed files with 98 additions and 41 deletions

View File

@ -205,9 +205,25 @@
headers['Content-Type'] = contentType;
}
if (!request.timeout) {
return fetch(request.url, fetchRequest);
}
return new Promise(function (resolve, reject) {
var timeout = setTimeout(reject, request.timeout);
fetch(request.url, fetchRequest).then(function (response) {
clearTimeout(timeout);
resolve(response);
}, function (error) {
clearTimeout(timeout);
throw error;
});
});
}
function paramsToString(params) {
var values = [];
@ -256,9 +272,9 @@
return Promise.reject(response);
}
}, function () {
}, function (error) {
onFetchFail(request.url, {});
return Promise.reject({});
throw error;
});
}
@ -379,7 +395,7 @@
return Promise.reject(response);
}
}, function () {
}, function (error) {
logger.log("Request failed to " + request.url);
@ -390,26 +406,26 @@
var previousServerAddress = self.serverAddress();
tryReconnect().then(function () {
return tryReconnect().then(function () {
logger.log("Reconnect succeesed");
request.url = request.url.replace(previousServerAddress, self.serverAddress());
self.fetchWithFailover(request, false);
return self.fetchWithFailover(request, false);
}, function () {
}, function (innerError) {
logger.log("Reconnect failed");
onFetchFail(request.url, {});
return Promise.reject({});
throw innerError;
});
} else {
logger.log("Reporting request failure");
onFetchFail(request.url, {});
return Promise.reject({});
throw error;
}
});
};
@ -590,7 +606,13 @@
var now = new Date().getTime();
return self.get(url).then(function () {
return self.ajax({
type: "GET",
url: url,
timeout: 5000
}).then(function () {
var responseTimeSeconds = (new Date().getTime() - now) / 1000;
var bytesPerSecond = byteSize / responseTimeSeconds;

View File

@ -113,9 +113,25 @@
headers['Content-Type'] = contentType;
}
if (!request.timeout) {
return fetch(request.url, fetchRequest);
}
return new Promise(function (resolve, reject) {
var timeout = setTimeout(reject, request.timeout);
fetch(request.url, fetchRequest).then(function (response) {
clearTimeout(timeout);
resolve(response);
}, function (error) {
clearTimeout(timeout);
throw error;
});
});
}
function paramsToString(params) {
var values = [];
@ -154,8 +170,8 @@
return Promise.reject(response);
}
}, function () {
return Promise.reject({});
}, function (error) {
throw error;
});
}

View File

@ -340,7 +340,7 @@
}
.overflowBackdropCard {
width: 80%;
width: 84%;
max-width: 400px;
}

View File

@ -463,6 +463,10 @@ span.itemCommunityRating:not(:empty) + .userDataIcons {
}
.itemDetailImage {
border: solid 1px transparent;
}
.itemDetailImage.loaded {
-moz-box-shadow: 0px 0 20px #000;
-webkit-box-shadow: 0px 0 20px #000;
box-shadow: 0px 0 20px #000;

View File

@ -781,7 +781,10 @@
self.endSession = function () {
self.stop();
setTimeout(function () {
castPlayer.stopApp();
}, 1000);
};
self.volumeUp = function () {

View File

@ -167,7 +167,7 @@
function playInternalPostMediaSourceSelection(item, mediaSource, startPosition, deferred) {
Dashboard.hideModalLoadingMsg();
Dashboard.hideLoadingMsg();
currentItem = item;
currentMediaSource = mediaSource;

View File

@ -644,7 +644,7 @@
}
function enableScrollX() {
return browserInfo.mobile && AppInfo.enableAppLayouts;
return browserInfo.mobile && AppInfo.enableAppLayouts && screen.availWidth <= 1000;
}
function getPortraitShape() {
@ -899,7 +899,7 @@
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: getPortraitShape(),
showTitle: false,
showTitle: true,
centerText: true,
lazy: true
});

View File

@ -3260,6 +3260,11 @@
}
var img = elem.querySelector('img');
img.onload = function () {
if (img.src.indexOf('empty.png') == -1) {
img.classList.add('loaded');
}
};
ImageLoader.lazyImage(img, url);
},

View File

@ -763,10 +763,9 @@
curr.addEventListener('click', onCardClick);
if (AppInfo.isTouchPreferred) {
curr.removeEventListener('contextmenu', disableEvent);
curr.addEventListener('contextmenu', disableEvent);
//this.off('contextmenu', onContextMenu);
//this.on('contextmenu', onContextMenu);
}
else {
curr.removeEventListener('contextmenu', onContextMenu);
@ -820,6 +819,7 @@
hammertime.on('press', onTapHold);
hammertime.on('pressup', onTapHoldUp);
});
showTapHoldHelp(element);
}
@ -863,9 +863,16 @@
showSelections(card);
if (s.stopPropagation) {
e.stopPropagation();
}
e.preventDefault();
e.stopPropagation();
return false;
}
e.preventDefault();
e.stopPropagation();
return false;
}
function onTapHoldUp(e) {

View File

@ -272,7 +272,7 @@
var userAtTop = showUserAtTop();
var homeHref = window.ApiClient ? 'index.html' : 'selectserver.html';
var homeHref = window.ApiClient ? 'index.html' : 'selectserver.html?showuser=1';
var hasUserImage = user.imageUrl && AppInfo.enableUserImage;
@ -376,7 +376,7 @@
html += '<a class="sidebarLink lnkMediaFolder lnkMySync" data-itemid="mysync" onclick="return LibraryMenu.onLinkClicked(event, this);" href="mysync.html"><iron-icon icon="sync" class="sidebarLinkIcon"></iron-icon><span class="sidebarLinkText">' + Globalize.translate('ButtonSync') + '</span></a>';
if (Dashboard.isConnectMode()) {
html += '<a class="sidebarLink lnkMediaFolder" data-itemid="selectserver" onclick="return LibraryMenu.onLinkClicked(event, this);" href="selectserver.html"><iron-icon icon="wifi" class="sidebarLinkIcon"></iron-icon><span class="sidebarLinkText">' + Globalize.translate('ButtonSelectServer') + '</span></a>';
html += '<a class="sidebarLink lnkMediaFolder" data-itemid="selectserver" onclick="return LibraryMenu.onLinkClicked(event, this);" href="selectserver.html?showuser=1"><iron-icon icon="wifi" class="sidebarLinkIcon"></iron-icon><span class="sidebarLinkText">' + Globalize.translate('ButtonSelectServer') + '</span></a>';
}
if (showUserAtTop()) {
@ -790,7 +790,7 @@
}
}
pageClassOn('pageinit', 'page', function () {
pageClassOn('pagebeforeshow', 'page', function () {
var page = this;

View File

@ -845,7 +845,7 @@
if (firstItem.MediaType === "Video") {
Dashboard.showModalLoadingMsg();
Dashboard.showLoadingMsg();
}
if (options.startPositionTicks || firstItem.MediaType !== 'Video' || !AppSettings.enableCinemaMode()) {
@ -1064,7 +1064,7 @@
}
if (item.IsPlaceHolder) {
Dashboard.hideModalLoadingMsg();
Dashboard.hideLoadingMsg();
MediaController.showPlaybackInfoErrorMessage('PlaceHolder');
return;
}
@ -1073,7 +1073,7 @@
if (item.MediaType == 'Video' && AppSettings.enableAutomaticBitrateDetection() && (new Date().getTime() - (self.lastBitrateDetections[bitrateDetectionKey] || 0)) > 300000) {
Dashboard.showModalLoadingMsg();
Dashboard.showLoadingMsg();
ApiClient.detectBitrate().then(function (bitrate) {
Logger.log('Max bitrate auto detected to ' + bitrate);
@ -1096,7 +1096,7 @@
if (item.MediaType === "Video") {
Dashboard.showModalLoadingMsg();
Dashboard.showLoadingMsg();
}
MediaController.getPlaybackInfo(item.Id, deviceProfile, startPosition).then(function (playbackInfoResult) {
@ -1122,7 +1122,7 @@
callback(mediaSource);
}
} else {
Dashboard.hideModalLoadingMsg();
Dashboard.hideLoadingMsg();
MediaController.showPlaybackInfoErrorMessage('NoCompatibleStream');
}
});
@ -1140,7 +1140,7 @@
function playInternalPostMediaSourceSelection(item, mediaSource, startPosition, callback) {
Dashboard.hideModalLoadingMsg();
Dashboard.hideLoadingMsg();
self.currentMediaSource = mediaSource;
self.currentItem = item;

View File

@ -334,24 +334,24 @@
function updatePageStyle(page) {
if (ConnectionManager.isLoggedIntoConnect()) {
if (getParameterByName('showuser') == '1') {
$(page).addClass('libraryPage').addClass('noSecondaryNavPage').removeClass('standalonePage');
} else {
$(page).removeClass('libraryPage').removeClass('noSecondaryNavPage').addClass('standalonePage');
}
}
$(document).on('pageinit pagebeforeshow', "#selectServerPage", function () {
pageIdOn('pagebeforeshow', "selectServerPage", function () {
var page = this;
updatePageStyle(page);
});
}).on('pageshow', "#selectServerPage", function () {
pageIdOn('pageshow', "selectServerPage", function () {
var page = this;
loadPage(page);
});
})();

View File

@ -1757,7 +1757,7 @@ var AppInfo = {};
function initRequire() {
var urlArgs = "v=" + window.dashboardVersion;
var urlArgs = "v=" + (window.dashboardVersion || new Date().getDate());
var paths = {
velocity: "bower_components/velocity/velocity.min",
@ -2209,7 +2209,7 @@ var AppInfo = {};
postInitDependencies.push('scripts/nowplayingbar');
}
//postInitDependencies.push('components/testermessage');
postInitDependencies.push('components/testermessage');
require(postInitDependencies);
});

View File

@ -4,7 +4,7 @@
<title>Emby</title>
</head>
<body>
<div id="selectServerPage" data-role="page" class="page libraryPage noSecondaryNavPage" data-theme="b" data-require="scripts/selectserver,paper-fab,paper-item-body,paper-icon-item">
<div id="selectServerPage" data-role="page" class="page noSecondaryNavPage standalonePage" data-theme="b" data-require="scripts/selectserver,paper-fab,paper-item-body,paper-icon-item">
<div data-role="content">