mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
connectivity fixes
This commit is contained in:
parent
705a817b12
commit
79fa61fa33
6 changed files with 116 additions and 90 deletions
|
@ -58,25 +58,32 @@
|
|||
return serverInfo;
|
||||
};
|
||||
|
||||
var currentUserPromise;
|
||||
var currentUser;
|
||||
/**
|
||||
* Gets or sets the current user id.
|
||||
*/
|
||||
self.getCurrentUser = function () {
|
||||
|
||||
var promise = currentUserPromise;
|
||||
if (currentUser) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
if (promise == null) {
|
||||
|
||||
promise = self.getUser(self.getCurrentUserId()).catch(function (err) {
|
||||
currentUserPromise = null;
|
||||
throw err;
|
||||
resolve(currentUser);
|
||||
});
|
||||
|
||||
currentUserPromise = promise;
|
||||
}
|
||||
|
||||
return promise;
|
||||
var userId = self.getCurrentUserId();
|
||||
|
||||
if (!userId) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
reject();
|
||||
});
|
||||
}
|
||||
|
||||
return self.getUser(userId).then(function (user) {
|
||||
currentUser = user;
|
||||
return user;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -112,7 +119,7 @@
|
|||
};
|
||||
|
||||
self.setAuthenticationInfo = function (accessKey, userId) {
|
||||
currentUserPromise = null;
|
||||
currentUser = null;
|
||||
|
||||
serverInfo.AccessToken = accessKey;
|
||||
serverInfo.UserId = userId;
|
||||
|
@ -209,18 +216,22 @@
|
|||
return fetch(request.url, fetchRequest);
|
||||
}
|
||||
|
||||
return fetchWithTimeout(request.url, fetchRequest, request.timeout);
|
||||
}
|
||||
|
||||
function fetchWithTimeout(url, options, timeoutMs) {
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
var timeout = setTimeout(reject, request.timeout);
|
||||
var timeout = setTimeout(reject, timeoutMs);
|
||||
|
||||
fetch(request.url, fetchRequest).then(function (response) {
|
||||
fetch(url, options).then(function (response) {
|
||||
clearTimeout(timeout);
|
||||
resolve(response);
|
||||
}, function (error) {
|
||||
clearTimeout(timeout);
|
||||
throw error;
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -330,7 +341,7 @@
|
|||
|
||||
var timeout = connectionMode == MediaBrowser.ConnectionMode.Local ? 7000 : 15000;
|
||||
|
||||
fetch(url + "/system/info/public", {
|
||||
fetchWithTimeout(url + "/system/info/public", {
|
||||
|
||||
method: 'GET',
|
||||
accept: 'application/json'
|
||||
|
@ -338,7 +349,7 @@
|
|||
// Commenting this out since the fetch api doesn't have a timeout option yet
|
||||
//timeout: timeout
|
||||
|
||||
}).then(function () {
|
||||
}, timeout).then(function () {
|
||||
|
||||
logger.log("Reconnect succeeded to " + url);
|
||||
|
||||
|
@ -357,7 +368,7 @@
|
|||
|
||||
setTimeout(function () {
|
||||
tryReconnectInternal(resolve, reject, newConnectionMode, currentRetryCount + 1);
|
||||
}, 500);
|
||||
}, 300);
|
||||
|
||||
} else {
|
||||
reject();
|
||||
|
@ -371,7 +382,7 @@
|
|||
|
||||
setTimeout(function () {
|
||||
tryReconnectInternal(resolve, reject, self.serverInfo().LastConnectionMode, 0);
|
||||
}, 500);
|
||||
}, 300);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -551,14 +562,14 @@
|
|||
function onWebSocketMessage(msg) {
|
||||
|
||||
if (msg.MessageType === "UserDeleted") {
|
||||
currentUserPromise = null;
|
||||
currentUser = null;
|
||||
}
|
||||
else if (msg.MessageType === "UserUpdated" || msg.MessageType === "UserConfigurationUpdated") {
|
||||
|
||||
var user = msg.Data;
|
||||
if (user.Id == self.getCurrentUserId()) {
|
||||
|
||||
currentUserPromise = null;
|
||||
currentUser = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -117,18 +117,31 @@
|
|||
return fetch(request.url, fetchRequest);
|
||||
}
|
||||
|
||||
return fetchWithTimeout(request.url, fetchRequest, request.timeout);
|
||||
}
|
||||
|
||||
function fetchWithTimeout(url, options, timeoutMs) {
|
||||
|
||||
logger.log('fetchWithTimeout: timeoutMs: ' + timeoutMs + ', url: ' + url);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
var timeout = setTimeout(reject, request.timeout);
|
||||
var timeout = setTimeout(reject, timeoutMs);
|
||||
|
||||
fetch(request.url, fetchRequest).then(function (response) {
|
||||
fetch(url, options).then(function (response) {
|
||||
clearTimeout(timeout);
|
||||
|
||||
logger.log('fetchWithTimeout: succeeded connecting to url: ' + url);
|
||||
|
||||
resolve(response);
|
||||
}, function (error) {
|
||||
|
||||
clearTimeout(timeout);
|
||||
|
||||
logger.log('fetchWithTimeout: timed out connecting to url: ' + url);
|
||||
|
||||
throw error;
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -155,10 +168,12 @@
|
|||
|
||||
request.headers = request.headers || {};
|
||||
|
||||
logger.log('Requesting url without automatic networking: ' + request.url);
|
||||
logger.log('ConnectionManager requesting url: ' + request.url);
|
||||
|
||||
return getFetchPromise(request).then(function (response) {
|
||||
|
||||
logger.log('ConnectionManager response status: ' + response.status + ', url: ' + request.url);
|
||||
|
||||
if (response.status < 400) {
|
||||
|
||||
if (request.dataType == 'json' || request.headers.accept == 'application/json') {
|
||||
|
@ -170,8 +185,10 @@
|
|||
return Promise.reject(response);
|
||||
}
|
||||
|
||||
}, function (error) {
|
||||
throw error;
|
||||
}, function (err) {
|
||||
|
||||
logger.log('ConnectionManager request failed to url: ' + request.url);
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -238,11 +238,13 @@
|
|||
|
||||
setPeopleHeader(page, item);
|
||||
|
||||
$(page).trigger('displayingitem', [{
|
||||
|
||||
page.dispatchEvent(new CustomEvent("displayingitem", {
|
||||
detail: {
|
||||
item: item,
|
||||
context: context
|
||||
}]);
|
||||
},
|
||||
bubbles: true
|
||||
}));
|
||||
|
||||
Dashboard.hideLoadingMsg();
|
||||
}
|
||||
|
|
|
@ -196,10 +196,12 @@
|
|||
|
||||
LibraryMenu.setTitle(name);
|
||||
|
||||
$(page).trigger('displayingitem', [{
|
||||
|
||||
page.dispatchEvent(new CustomEvent("displayingitem", {
|
||||
detail: {
|
||||
item: item
|
||||
}]);
|
||||
},
|
||||
bubbles: true
|
||||
}));
|
||||
|
||||
LibraryBrowser.setLastRefreshed(page);
|
||||
Dashboard.hideLoadingMsg();
|
||||
|
|
|
@ -1008,8 +1008,7 @@
|
|||
$(apiClient).off("websocketmessage", onWebSocketMessageReceived).on("websocketmessage", onWebSocketMessageReceived);
|
||||
}
|
||||
|
||||
Dashboard.ready(function () {
|
||||
|
||||
MediaController.init = function () {
|
||||
if (window.ApiClient) {
|
||||
initializeApiClient(window.ApiClient);
|
||||
}
|
||||
|
@ -1017,7 +1016,7 @@
|
|||
$(ConnectionManager).on('apiclientcreated', function (e, apiClient) {
|
||||
initializeApiClient(apiClient);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function onCastButtonClicked() {
|
||||
|
||||
|
@ -1027,7 +1026,6 @@
|
|||
document.addEventListener('headercreated', function () {
|
||||
|
||||
$('.btnCast').off('click', onCastButtonClicked).on('click', onCastButtonClicked);
|
||||
|
||||
});
|
||||
|
||||
pageClassOn('pagebeforeshow', "page", function () {
|
||||
|
@ -1035,11 +1033,11 @@
|
|||
var page = this;
|
||||
|
||||
currentDisplayInfo = null;
|
||||
|
||||
});
|
||||
|
||||
pageClassOn('displayingitem', "libraryPage", function (e, info) {
|
||||
pageClassOn('displayingitem', "libraryPage", function (e) {
|
||||
|
||||
var info = e.detail.info;
|
||||
currentDisplayInfo = info;
|
||||
|
||||
mirrorIfEnabled(info);
|
||||
|
|
|
@ -767,12 +767,15 @@ var Dashboard = {
|
|||
});
|
||||
}
|
||||
|
||||
if (!Dashboard.getPluginSecurityInfoPromise) {
|
||||
var cachedInfo = Dashboard.pluginSecurityInfo;
|
||||
if (cachedInfo) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
resolve(cachedInfo);
|
||||
});
|
||||
}
|
||||
|
||||
// Don't let this blow up the dashboard when it fails
|
||||
apiClient.ajax({
|
||||
return apiClient.ajax({
|
||||
type: "GET",
|
||||
url: apiClient.getUrl("Plugins/SecurityInfo"),
|
||||
dataType: 'json',
|
||||
|
@ -782,17 +785,13 @@ var Dashboard = {
|
|||
}
|
||||
|
||||
}).then(function (result) {
|
||||
deferred.resolveWith(null, [result]);
|
||||
Dashboard.pluginSecurityInfo = result;
|
||||
return result;
|
||||
});
|
||||
|
||||
Dashboard.getPluginSecurityInfoPromise = deferred;
|
||||
}
|
||||
|
||||
return Dashboard.getPluginSecurityInfoPromise;
|
||||
},
|
||||
|
||||
resetPluginSecurityInfo: function () {
|
||||
Dashboard.getPluginSecurityInfoPromise = null;
|
||||
Dashboard.pluginSecurityInfo = null;
|
||||
},
|
||||
|
||||
ensureHeader: function (page) {
|
||||
|
@ -1466,11 +1465,6 @@ var Dashboard = {
|
|||
}
|
||||
},
|
||||
|
||||
ready: function (fn) {
|
||||
|
||||
Dashboard.initPromise.then(fn);
|
||||
},
|
||||
|
||||
loadExternalPlayer: function () {
|
||||
|
||||
var deferred = DeferredBuilder.Deferred();
|
||||
|
@ -1648,7 +1642,11 @@ var AppInfo = {};
|
|||
if (!Dashboard.isServerlessPage()) {
|
||||
|
||||
if (server && server.UserId && server.AccessToken) {
|
||||
Dashboard.showLoadingMsg();
|
||||
|
||||
ConnectionManager.connectToServer(server).then(function (result) {
|
||||
Dashboard.showLoadingMsg();
|
||||
|
||||
if (result.State == MediaBrowser.ConnectionState.SignedIn) {
|
||||
window.ApiClient = result.ApiClient;
|
||||
}
|
||||
|
@ -1871,7 +1869,7 @@ var AppInfo = {};
|
|||
define('native-promise-only', [bowerPath + '/native-promise-only/lib/npo.src']);
|
||||
}
|
||||
|
||||
function init(promiseResolve, hostingAppInfo) {
|
||||
function init(hostingAppInfo) {
|
||||
|
||||
if (Dashboard.isRunningInCordova() && browserInfo.android) {
|
||||
define("appstorage", ["cordova/android/appstorage"]);
|
||||
|
@ -1978,7 +1976,7 @@ var AppInfo = {};
|
|||
AppInfo[i] = hostingAppInfo[i];
|
||||
}
|
||||
|
||||
initAfterDependencies(promiseResolve);
|
||||
initAfterDependencies();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1990,7 +1988,7 @@ var AppInfo = {};
|
|||
});
|
||||
}
|
||||
|
||||
function initAfterDependencies(promiseResolve) {
|
||||
function initAfterDependencies() {
|
||||
|
||||
var drawer = document.querySelector('.mainDrawerPanel');
|
||||
drawer.classList.remove('mainDrawerPanelPreInit');
|
||||
|
@ -2075,6 +2073,8 @@ var AppInfo = {};
|
|||
|
||||
Promise.all(promises).then(function () {
|
||||
|
||||
MediaController.init();
|
||||
|
||||
document.title = Globalize.translateDocument(document.title, 'html');
|
||||
|
||||
var mainDrawerPanelContent = document.querySelector('.mainDrawerPanelContent');
|
||||
|
@ -2111,17 +2111,17 @@ var AppInfo = {};
|
|||
|
||||
// Don't like having to use jQuery here, but it takes care of making sure that embedded script executes
|
||||
$(mainDrawerPanelContent).html(Globalize.translateDocument(newHtml, 'html'));
|
||||
onAppReady(promiseResolve);
|
||||
onAppReady();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
onAppReady(promiseResolve);
|
||||
onAppReady();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onAppReady(promiseResolve) {
|
||||
function onAppReady() {
|
||||
|
||||
var deps = [];
|
||||
|
||||
|
@ -2178,7 +2178,6 @@ var AppInfo = {};
|
|||
$.mobile.filterHtml = Dashboard.filterHtml;
|
||||
|
||||
$.mobile.initializePage();
|
||||
promiseResolve();
|
||||
|
||||
var postInitDependencies = [];
|
||||
|
||||
|
@ -2407,8 +2406,6 @@ var AppInfo = {};
|
|||
|
||||
require(initialDependencies, function (isMobile) {
|
||||
|
||||
Dashboard.initPromise = new Promise(function (resolve, reject) {
|
||||
|
||||
function onWebComponentsReady() {
|
||||
|
||||
var polymerDependencies = [];
|
||||
|
@ -2416,7 +2413,7 @@ var AppInfo = {};
|
|||
require(polymerDependencies, function () {
|
||||
|
||||
getHostingAppInfo().then(function (hostingAppInfo) {
|
||||
init(resolve, hostingAppInfo);
|
||||
init(hostingAppInfo);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -2431,7 +2428,6 @@ var AppInfo = {};
|
|||
document.addEventListener('WebComponentsReady', onWebComponentsReady);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue