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