mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
connect updates
This commit is contained in:
parent
8cf3aba7e0
commit
132a02a48d
4 changed files with 151 additions and 108 deletions
|
@ -1,54 +1,21 @@
|
||||||
(function () {
|
(function () {
|
||||||
|
|
||||||
function onAuthFailure(data, textStatus, xhr) {
|
|
||||||
|
|
||||||
var url = (this.url || '').toLowerCase();
|
|
||||||
|
|
||||||
// Bounce to the login screen, but not if a password entry fails, obviously
|
|
||||||
if (url.indexOf('/password') == -1 &&
|
|
||||||
url.indexOf('/authenticate') == -1 &&
|
|
||||||
!$($.mobile.activePage).is('.standalonePage')) {
|
|
||||||
|
|
||||||
Dashboard.logout(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$.ajaxSetup({
|
$.ajaxSetup({
|
||||||
crossDomain: true,
|
crossDomain: true
|
||||||
|
|
||||||
statusCode: {
|
|
||||||
|
|
||||||
401: onAuthFailure
|
|
||||||
},
|
|
||||||
|
|
||||||
error: function (event) {
|
|
||||||
|
|
||||||
Dashboard.hideLoadingMsg();
|
|
||||||
|
|
||||||
if (!Dashboard.suppressAjaxErrors) {
|
|
||||||
setTimeout(function () {
|
|
||||||
|
|
||||||
var msg = event.getResponseHeader("X-Application-Error-Code") || Dashboard.defaultErrorMessage;
|
|
||||||
Dashboard.showError(msg);
|
|
||||||
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if ($.browser.msie) {
|
||||||
|
|
||||||
|
// This is unfortunately required due to IE's over-aggressive caching.
|
||||||
|
// https://github.com/MediaBrowser/MediaBrowser/issues/179
|
||||||
|
$.ajaxSetup({
|
||||||
|
cache: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
if ($.browser.msie) {
|
// TODO: Deprecated in 1.9
|
||||||
|
|
||||||
// This is unfortuantely required due to IE's over-aggressive caching.
|
|
||||||
// https://github.com/MediaBrowser/MediaBrowser/issues/179
|
|
||||||
$.ajaxSetup({
|
|
||||||
cache: false
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
$.support.cors = true;
|
$.support.cors = true;
|
||||||
|
|
||||||
$(document).one('click', WebNotifications.requestPermission);
|
$(document).one('click', WebNotifications.requestPermission);
|
||||||
|
@ -71,6 +38,50 @@ var Dashboard = {
|
||||||
//$.mobile.collapsible.prototype.options.contentTheme = "a";
|
//$.mobile.collapsible.prototype.options.contentTheme = "a";
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onRequestFail: function (e, data) {
|
||||||
|
|
||||||
|
if (data.status == 401) {
|
||||||
|
|
||||||
|
var url = data.url.toLowerCase();
|
||||||
|
|
||||||
|
// Bounce to the login screen, but not if a password entry fails, obviously
|
||||||
|
if (url.indexOf('/password') == -1 &&
|
||||||
|
url.indexOf('/authenticate') == -1 &&
|
||||||
|
!$($.mobile.activePage).is('.standalonePage')) {
|
||||||
|
|
||||||
|
if (data.errorCode == "ParentalControl") {
|
||||||
|
|
||||||
|
//alert(Globalize.translate('MessageLoggedOutParentalControl'));
|
||||||
|
|
||||||
|
|
||||||
|
Dashboard.alert({
|
||||||
|
message: Globalize.translate('MessageLoggedOutParentalControl'),
|
||||||
|
callback: function() {
|
||||||
|
Dashboard.logout(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Dashboard.logout(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dashboard.hideLoadingMsg();
|
||||||
|
|
||||||
|
if (!Dashboard.suppressAjaxErrors) {
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
|
||||||
|
var msg = data.errorCode || Dashboard.defaultErrorMessage;
|
||||||
|
|
||||||
|
Dashboard.showError(msg);
|
||||||
|
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
getCurrentUser: function () {
|
getCurrentUser: function () {
|
||||||
|
|
||||||
if (!Dashboard.getUserPromise) {
|
if (!Dashboard.getUserPromise) {
|
||||||
|
@ -161,6 +172,7 @@ var Dashboard = {
|
||||||
|
|
||||||
store.removeItem("userId");
|
store.removeItem("userId");
|
||||||
store.removeItem("token");
|
store.removeItem("token");
|
||||||
|
store.removeItem("serverAddress");
|
||||||
|
|
||||||
var loginPage = !Dashboard.isConnectMode() ?
|
var loginPage = !Dashboard.isConnectMode() ?
|
||||||
'login.html' :
|
'login.html' :
|
||||||
|
@ -1222,7 +1234,9 @@ var Dashboard = {
|
||||||
|
|
||||||
function initializeApiClient(apiClient) {
|
function initializeApiClient(apiClient) {
|
||||||
|
|
||||||
$(apiClient).off('.dashboard').on("websocketmessage.dashboard", Dashboard.onWebSocketMessageReceived);
|
$(apiClient).off('.dashboard')
|
||||||
|
.on("websocketmessage.dashboard", Dashboard.onWebSocketMessageReceived)
|
||||||
|
.on('requestfail.dashboard', Dashboard.onRequestFail);
|
||||||
|
|
||||||
// TODO: Improve with http://webpjs.appspot.com/
|
// TODO: Improve with http://webpjs.appspot.com/
|
||||||
apiClient.supportsWebP($.browser.chrome);
|
apiClient.supportsWebP($.browser.chrome);
|
||||||
|
@ -1255,7 +1269,7 @@ var Dashboard = {
|
||||||
|
|
||||||
initializeApiClient(ApiClient);
|
initializeApiClient(ApiClient);
|
||||||
|
|
||||||
ConnectionManager.addApiClient(ApiClient);
|
ConnectionManager.addApiClient(ApiClient, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -66,9 +66,6 @@
|
||||||
url: url + "/mediabrowser/system/info/public",
|
url: url + "/mediabrowser/system/info/public",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
|
||||||
error: function () {
|
|
||||||
},
|
|
||||||
|
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -92,17 +89,26 @@
|
||||||
return apiClients[0];
|
return apiClients[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
self.addApiClient = function (apiClient) {
|
self.addApiClient = function (apiClient, enableAutomaticNetworking) {
|
||||||
|
|
||||||
apiClients.push(apiClient);
|
apiClients.push(apiClient);
|
||||||
|
|
||||||
apiClient.getPublicSystemInfo().done(function (systemInfo) {
|
apiClient.getPublicSystemInfo().done(function (systemInfo) {
|
||||||
|
|
||||||
var server = {};
|
var server = credentialProvider.credentials().servers.filter(function (s) {
|
||||||
|
|
||||||
|
return s.Id == systemInfo.Id;
|
||||||
|
|
||||||
|
})[0] || {};
|
||||||
|
|
||||||
updateServerInfo(server, systemInfo);
|
updateServerInfo(server, systemInfo);
|
||||||
|
|
||||||
apiClient.serverInfo(server);
|
apiClient.serverInfo(server);
|
||||||
$(this).trigger('apiclientcreated', [apiClient]);
|
$(this).trigger('apiclientcreated', [apiClient]);
|
||||||
|
|
||||||
|
if (enableAutomaticNetworking) {
|
||||||
|
self.connectToServer(server);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -220,10 +226,6 @@
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
headers: {
|
headers: {
|
||||||
"X-Connect-UserToken": accessToken
|
"X-Connect-UserToken": accessToken
|
||||||
},
|
|
||||||
|
|
||||||
error: function () {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -241,10 +243,6 @@
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
headers: {
|
headers: {
|
||||||
"X-MediaBrowser-Token": server.ExchangeToken
|
"X-MediaBrowser-Token": server.ExchangeToken
|
||||||
},
|
|
||||||
|
|
||||||
error: function () {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}).done(function (auth) {
|
}).done(function (auth) {
|
||||||
|
@ -272,10 +270,6 @@
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
headers: {
|
headers: {
|
||||||
"X-MediaBrowser-Token": server.AccessToken
|
"X-MediaBrowser-Token": server.AccessToken
|
||||||
},
|
|
||||||
|
|
||||||
error: function () {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}).done(function (systemInfo) {
|
}).done(function (systemInfo) {
|
||||||
|
@ -291,10 +285,6 @@
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
headers: {
|
headers: {
|
||||||
"X-MediaBrowser-Token": server.AccessToken
|
"X-MediaBrowser-Token": server.AccessToken
|
||||||
},
|
|
||||||
|
|
||||||
error: function () {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}).done(function (user) {
|
}).done(function (user) {
|
||||||
|
@ -413,7 +403,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $.when(promises).done(function () {
|
var done = function () {
|
||||||
|
|
||||||
var credentials = credentialProvider.credentials();
|
var credentials = credentialProvider.credentials();
|
||||||
|
|
||||||
|
@ -431,8 +421,9 @@
|
||||||
connectUser = null;
|
connectUser = null;
|
||||||
|
|
||||||
$(self).trigger('signedout');
|
$(self).trigger('signedout');
|
||||||
|
};
|
||||||
|
|
||||||
});
|
return $.when(promises).done(done);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.connectUserId = function () {
|
self.connectUserId = function () {
|
||||||
|
@ -456,10 +447,6 @@
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
headers: {
|
headers: {
|
||||||
"X-Connect-UserToken": self.connectToken()
|
"X-Connect-UserToken": self.connectToken()
|
||||||
},
|
|
||||||
|
|
||||||
error: function () {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}).done(function (servers) {
|
}).done(function (servers) {
|
||||||
|
@ -758,11 +745,7 @@
|
||||||
password: md5
|
password: md5
|
||||||
},
|
},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
|
contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||||
|
|
||||||
error: function () {
|
|
||||||
// Don't show normal dashboard errors
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}).done(function (result) {
|
}).done(function (result) {
|
||||||
|
|
|
@ -94,6 +94,24 @@
|
||||||
return val.substring(val.indexOf('=') + 1).replace("'", '%27');
|
return val.substring(val.indexOf('=') + 1).replace("'", '%27');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function onRequestFail(e) {
|
||||||
|
|
||||||
|
$(self).trigger('requestfail', [
|
||||||
|
{
|
||||||
|
url: this.url,
|
||||||
|
status: e.status,
|
||||||
|
errorCode: e.getResponseHeader("X-Application-Error-Code")
|
||||||
|
}]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onRetryRequestFail(request) {
|
||||||
|
|
||||||
|
$(self).trigger('requestfail', [
|
||||||
|
{
|
||||||
|
url: request.url
|
||||||
|
}]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps around jQuery ajax methods to add additional info to the request.
|
* Wraps around jQuery ajax methods to add additional info to the request.
|
||||||
*/
|
*/
|
||||||
|
@ -122,20 +140,33 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self.enableAutomaticNetwork) {
|
if (!self.enableAutomaticNetwork || !self.serverInfo() || self.connectionMode == null) {
|
||||||
return $.ajax(request);
|
return $.ajax(request).fail(onRequestFail);
|
||||||
}
|
}
|
||||||
|
|
||||||
var deferred = $.Deferred();
|
var deferred = $.Deferred();
|
||||||
self.ajaxWithFailover(request, deferred);
|
self.ajaxWithFailover(request, deferred, true);
|
||||||
return deferred.promise();
|
return deferred.promise();
|
||||||
};
|
};
|
||||||
|
|
||||||
function tryReconnectInternal(deferred, connectionMode, currentRetryCount) {
|
function switchConnectionMode(connectionMode) {
|
||||||
|
|
||||||
if (connectionMode == null) {
|
var newConnectionMode;
|
||||||
connectionMode = self.connectionMode;
|
|
||||||
|
if (connectionMode == MediaBrowser.ConnectionMode.Local && serverInfo.RemoteAddress) {
|
||||||
|
newConnectionMode = MediaBrowser.ConnectionMode.Remote;
|
||||||
}
|
}
|
||||||
|
else if (connectionMode == MediaBrowser.ConnectionMode.Remote && serverInfo.LocalAddress) {
|
||||||
|
newConnectionMode = MediaBrowser.ConnectionMode.Local;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newConnectionMode = connectionMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newConnectionMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tryReconnectInternal(deferred, connectionMode, currentRetryCount) {
|
||||||
|
|
||||||
var url = connectionMode == MediaBrowser.ConnectionMode.Local ?
|
var url = connectionMode == MediaBrowser.ConnectionMode.Local ?
|
||||||
self.serverInfo().LocalAddress :
|
self.serverInfo().LocalAddress :
|
||||||
|
@ -147,36 +178,24 @@
|
||||||
url: url + "/mediabrowser/system/info/public",
|
url: url + "/mediabrowser/system/info/public",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
|
|
||||||
error: function () {
|
|
||||||
},
|
|
||||||
|
|
||||||
timeout: 3000
|
timeout: 3000
|
||||||
|
|
||||||
}).done(function () {
|
}).done(function () {
|
||||||
|
|
||||||
self.connectionMode = connectionMode;
|
self.connectionMode = connectionMode;
|
||||||
|
self.serverAddress(url);
|
||||||
|
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
|
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
|
|
||||||
currentRetryCount = currentRetryCount || 0;
|
|
||||||
|
|
||||||
if (currentRetryCount <= 6) {
|
if (currentRetryCount <= 6) {
|
||||||
|
|
||||||
var newConnectionMode;
|
var newConnectionMode = switchConnectionMode(connectionMode);
|
||||||
|
|
||||||
if (connectionMode == MediaBrowser.ConnectionMode.Local && serverInfo.RemoteAddress) {
|
setTimeout(function () {
|
||||||
newConnectionMode = MediaBrowser.ConnectionMode.Remote;
|
tryReconnectInternal(deferred, newConnectionMode, currentRetryCount + 1);
|
||||||
}
|
}, 500);
|
||||||
else if (connectionMode == MediaBrowser.ConnectionMode.Remote && serverInfo.LocalAddress) {
|
|
||||||
newConnectionMode = MediaBrowser.ConnectionMode.Local;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
newConnectionMode = connectionMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
tryReconnectInternal(deferred, newConnectionMode, currentRetryCount + 1);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
|
@ -187,7 +206,9 @@
|
||||||
function tryReconnect() {
|
function tryReconnect() {
|
||||||
|
|
||||||
var deferred = $.Deferred();
|
var deferred = $.Deferred();
|
||||||
tryReconnectInternal(deferred);
|
setTimeout(function () {
|
||||||
|
tryReconnectInternal(deferred, self.connectionMode, 0);
|
||||||
|
}, 500);
|
||||||
return deferred.promise();
|
return deferred.promise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,12 +225,9 @@
|
||||||
|
|
||||||
self.ajaxWithFailover = function (request, deferred, enableReconnection, replaceUrl) {
|
self.ajaxWithFailover = function (request, deferred, enableReconnection, replaceUrl) {
|
||||||
|
|
||||||
// Stop global error handlers
|
|
||||||
request.error = function () { };
|
|
||||||
|
|
||||||
if (replaceUrl) {
|
if (replaceUrl) {
|
||||||
|
|
||||||
var baseUrl = connectionMode == MediaBrowser.ConnectionMode.Local ?
|
var baseUrl = self.connectionMode == MediaBrowser.ConnectionMode.Local ?
|
||||||
self.serverInfo().LocalAddress :
|
self.serverInfo().LocalAddress :
|
||||||
self.serverInfo().RemoteAddress;
|
self.serverInfo().RemoteAddress;
|
||||||
|
|
||||||
|
@ -220,22 +238,23 @@
|
||||||
|
|
||||||
deferred.resolveWith(null, [response]);
|
deferred.resolveWith(null, [response]);
|
||||||
|
|
||||||
}).fail(function () {
|
}).fail(function (e, textStatus) {
|
||||||
|
|
||||||
if (enableReconnection !== false) {
|
// http://api.jquery.com/jQuery.ajax/
|
||||||
|
if (enableReconnection && textStatus == "timeout") {
|
||||||
tryReconnect().done(function () {
|
tryReconnect().done(function () {
|
||||||
|
|
||||||
self.ajaxWithFailover(request, deferred, false, true);
|
self.ajaxWithFailover(request, deferred, false, true);
|
||||||
|
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
|
|
||||||
// TODO: Make sure global ajax error handlers fire
|
onRetryRequestFail(request);
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// TODO: Make sure global ajax error handlers fire
|
onRetryRequestFail(request);
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -277,6 +296,12 @@
|
||||||
self.serverInfo(server);
|
self.serverInfo(server);
|
||||||
self.connectionMode = connectionMode;
|
self.connectionMode = connectionMode;
|
||||||
self.enableAutomaticNetwork = true;
|
self.enableAutomaticNetwork = true;
|
||||||
|
|
||||||
|
var url = connectionMode == MediaBrowser.ConnectionMode.Local ?
|
||||||
|
self.serverInfo().LocalAddress :
|
||||||
|
self.serverInfo().RemoteAddress;
|
||||||
|
|
||||||
|
self.serverAddress(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.isWebSocketSupported = function () {
|
self.isWebSocketSupported = function () {
|
||||||
|
|
21
dashboard-ui/thirdparty/apiclient/network.js
vendored
Normal file
21
dashboard-ui/thirdparty/apiclient/network.js
vendored
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
(function (globalScope, navigator) {
|
||||||
|
|
||||||
|
function networkStatus() {
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
self.isOnline = function () {
|
||||||
|
|
||||||
|
var online = navigator.onLine;
|
||||||
|
|
||||||
|
if (online == null) {
|
||||||
|
online = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return online;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
globalScope.NetworkStatus = new networkStatus();
|
||||||
|
|
||||||
|
})(window, window.navigator);
|
Loading…
Add table
Add a link
Reference in a new issue