mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-17 19:08:18 -07:00
connect updates
This commit is contained in:
parent
90082ed4bc
commit
83d7b945d7
@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<title>${TitleSignIn}</title>
|
||||
</head>
|
||||
<body>
|
||||
<body class="serverlessPage">
|
||||
<div id="connectLoginPage" data-role="page" class="page standalonePage connectLoginPage">
|
||||
|
||||
<div data-role="content">
|
||||
|
@ -12,16 +12,16 @@
|
||||
margin-left: .5em;
|
||||
}
|
||||
|
||||
.libraryPage {
|
||||
.libraryPage[data-theme='b'] {
|
||||
background-color: #202020;
|
||||
}
|
||||
|
||||
.backdropPage {
|
||||
background-color: rgba(15, 15,15, .86) !important;
|
||||
background-color: rgba(20, 20,20, .86) !important;
|
||||
}
|
||||
|
||||
.backdropPage:not(.lightBackdropPage) {
|
||||
background-color: rgba(15, 15,15, .94) !important;
|
||||
background-color: rgba(20, 20,20, .94) !important;
|
||||
}
|
||||
|
||||
.backdropContainer {
|
||||
|
@ -3,7 +3,7 @@
|
||||
}
|
||||
|
||||
.libraryPage:not(.metadataEditorPage):not(.noSecondaryNavPage) {
|
||||
padding-top: 100px !important;
|
||||
padding-top: 95px !important;
|
||||
}
|
||||
|
||||
.libraryMenuDivider {
|
||||
@ -149,23 +149,19 @@
|
||||
left: 0;
|
||||
z-index: 1000;
|
||||
top: 0;
|
||||
background-image: linear-gradient(#262626,#111);
|
||||
border-bottom: 1px solid #111;
|
||||
border-top: 0;
|
||||
border-left: 0;
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.libraryViewNav {
|
||||
height: 48px;
|
||||
height: 45px;
|
||||
overflow: hidden;
|
||||
position: fixed;
|
||||
right: 0;
|
||||
left: 0;
|
||||
top: 51px;
|
||||
top: 50px;
|
||||
z-index: 1000;
|
||||
background-image: linear-gradient(#1a1a1a,#1a1a1a);
|
||||
border-bottom: 1px solid #111;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
white-space: nowrap;
|
||||
@ -175,6 +171,14 @@
|
||||
overflow: -moz-scrollbars-none;
|
||||
}
|
||||
|
||||
.viewMenuBar {
|
||||
background-color: #000;
|
||||
}
|
||||
|
||||
.libraryViewNav {
|
||||
background-color: #111;
|
||||
}
|
||||
|
||||
.libraryViewNav::-webkit-scrollbar {
|
||||
height: 0 !important;
|
||||
display: none;
|
||||
@ -182,7 +186,7 @@
|
||||
|
||||
.viewMenuLink {
|
||||
text-decoration: none;
|
||||
color: #ccc !important;
|
||||
color: #eee !important;
|
||||
padding: 7px .5em 6px;
|
||||
display: inline-block;
|
||||
vertical-align: middle;
|
||||
@ -213,13 +217,13 @@
|
||||
|
||||
.viewMenuTextLink {
|
||||
display: block;
|
||||
padding: .6em .5em .6em 38px !important;
|
||||
font-size: 15px;
|
||||
padding: .65em .5em .55em 38px !important;
|
||||
font-size: 14px;
|
||||
font-weight: 300 !important;
|
||||
font-family: Roboto;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 14px 14px;
|
||||
background-position: 13px center;
|
||||
background-size: 13px 13px;
|
||||
background-position: 12px center;
|
||||
}
|
||||
|
||||
.musicViewMenu {
|
||||
@ -227,7 +231,10 @@
|
||||
}
|
||||
|
||||
.homeViewMenu {
|
||||
background-image: url(images/items/folders/home.png);
|
||||
background-image: url(images/mblogoicon.png);
|
||||
background-size: 39px 26px;
|
||||
background-position: 10px center;
|
||||
padding-left: 60px !important;
|
||||
}
|
||||
|
||||
.tvshowsViewMenu, .livetvViewMenu {
|
||||
@ -315,7 +322,7 @@
|
||||
margin: 0 0;
|
||||
position: relative;
|
||||
font-weight: normal;
|
||||
border-bottom: 5px solid transparent;
|
||||
border-bottom: 4px solid transparent;
|
||||
}
|
||||
|
||||
.libraryViewNav a:not(.ui-btn-active):hover {
|
||||
@ -324,17 +331,7 @@
|
||||
|
||||
.libraryViewNavLinkContent {
|
||||
display: inline-block;
|
||||
padding: 2px 15px 2px 15px;
|
||||
}
|
||||
|
||||
.libraryViewNav a + a .libraryViewNavLinkContent {
|
||||
padding-left: 17px;
|
||||
}
|
||||
|
||||
.libraryViewNav a + a .libraryViewNavLinkContent {
|
||||
border-left: 1px solid #333;
|
||||
position: relative;
|
||||
left: -2px;
|
||||
padding: 1px 13px 1px 13px;
|
||||
}
|
||||
|
||||
@media all and (max-width: 500px) {
|
||||
|
@ -16,7 +16,7 @@
|
||||
-moz-border-radius: 2px;
|
||||
-webkit-border-radius: 2px;
|
||||
border-radius: 2px;
|
||||
padding: 4px 12px 5px;
|
||||
padding: 4px 12px 4px;
|
||||
text-align: center;
|
||||
text-decoration: none !important;
|
||||
-moz-user-select: none;
|
||||
|
@ -64,10 +64,7 @@ body {
|
||||
|
||||
h1, h1 a {
|
||||
font-weight: 300 !important;
|
||||
}
|
||||
|
||||
.libraryPage h1, .libraryPage h1 a {
|
||||
font-weight: 100 !important;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.ui-loader h1 {
|
||||
|
@ -4,12 +4,9 @@
|
||||
|
||||
var page = this;
|
||||
|
||||
ApiClient.getSystemInfo().done(function (info) {
|
||||
var elem = $('#appVersionNumber', page);
|
||||
|
||||
var elem = $('#appVersionNumber', page);
|
||||
|
||||
elem.html(elem.html().replace('{0}', info.Version));
|
||||
});
|
||||
elem.html(elem.html().replace('{0}', ConnectionManager.appVersion()));
|
||||
});
|
||||
|
||||
})(jQuery, document);
|
@ -2,89 +2,41 @@
|
||||
|
||||
function onLoggedIn() {
|
||||
|
||||
ConnectionManager.getServers().done(function (result) {
|
||||
ConnectionManager.connect().done(function (result) {
|
||||
|
||||
if (result.length) {
|
||||
Dashboard.hideLoadingMsg();
|
||||
|
||||
connectToServerInstance(result[0]);
|
||||
switch (result.State) {
|
||||
|
||||
} else {
|
||||
Dashboard.alert('Coming soon');
|
||||
case MediaBrowser.ConnectionState.Unavilable:
|
||||
// Login succeeded so this should never happen
|
||||
break;
|
||||
case MediaBrowser.ConnectionState.ServerSelection:
|
||||
window.location = 'selectserver.html';
|
||||
break;
|
||||
case MediaBrowser.ConnectionState.ServerSignIn:
|
||||
// This should never happen in connect mode
|
||||
break;
|
||||
case MediaBrowser.ConnectionState.SignedIn:
|
||||
window.location = 'selectserver.html';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function connectToServerInstance(server) {
|
||||
|
||||
connectToServerAtUrl(server, server.Url).fail(function () {
|
||||
|
||||
if (server.LocalAddress) {
|
||||
connectToServerAtUrl(server, server.LocalAddress).fail(showServerConnectionFailure);
|
||||
|
||||
} else {
|
||||
showServerConnectionFailure();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showServerConnectionFailure() {
|
||||
alert('Unable to communicate with your server.');
|
||||
}
|
||||
|
||||
function connectToServerAtUrl(server, url) {
|
||||
|
||||
var exchangeToken = server.AccessKey;
|
||||
|
||||
return $.ajax({
|
||||
|
||||
type: "GET",
|
||||
url: url + "/mediabrowser/Connect/Exchange?format=json&ConnectUserId=" + ConnectionManager.connectUserId(),
|
||||
dataType: "json",
|
||||
|
||||
error: function () {
|
||||
// Don't show normal dashboard errors
|
||||
},
|
||||
headers: {
|
||||
"X-MediaBrowser-Token": exchangeToken
|
||||
}
|
||||
|
||||
|
||||
}).done(function (result) {
|
||||
|
||||
Dashboard.serverAddress(url);
|
||||
Dashboard.setCurrentUser(result.LocalUserId, result.AccessToken);
|
||||
|
||||
window.location = 'index.html';
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function login(page, username, password) {
|
||||
|
||||
var md5 = CryptoJS.MD5(password).toString();
|
||||
Dashboard.showLoadingMsg();
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "https://connect.mediabrowser.tv/service/user/authenticate",
|
||||
data: {
|
||||
userName: username,
|
||||
password: md5
|
||||
},
|
||||
dataType: "json",
|
||||
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||
|
||||
error: function () {
|
||||
// Don't show normal dashboard errors
|
||||
}
|
||||
|
||||
|
||||
}).done(function (result) {
|
||||
|
||||
ConnectionManager.onConnectAuthenticated(result);
|
||||
ConnectionManager.loginToConnect(username, password).done(function () {
|
||||
|
||||
onLoggedIn();
|
||||
|
||||
}).fail(function (result) {
|
||||
}).fail(function () {
|
||||
|
||||
Dashboard.hideLoadingMsg();
|
||||
|
||||
Dashboard.alert({
|
||||
message: Globalize.translate('MessageInvalidUser'),
|
||||
|
@ -422,7 +422,7 @@
|
||||
|
||||
closePlayMenu();
|
||||
|
||||
var html = '<div data-role="popup" class="externalPlayerFlyout" data-history="false" data-theme="a">';
|
||||
var html = '<div data-role="popup" class="externalPlayerFlyout" data-theme="a">';
|
||||
|
||||
html += '<ul data-role="listview" style="min-width: 200px;">';
|
||||
html += '<li data-role="list-divider" style="padding: 1em;text-align:center;">' + Globalize.translate('HeaderSelectExternalPlayer') + '</li>';
|
||||
|
@ -438,7 +438,7 @@
|
||||
loadlibraryButtons: loadlibraryButtons
|
||||
};
|
||||
|
||||
})(jQuery, document, ApiClient);
|
||||
})(jQuery, document);
|
||||
|
||||
(function ($, document) {
|
||||
|
||||
@ -595,4 +595,4 @@
|
||||
|
||||
});
|
||||
|
||||
})(jQuery, document);
|
||||
})(jQuery, document);
|
||||
|
@ -873,7 +873,7 @@
|
||||
function onUserDataChanged(userData) {
|
||||
|
||||
var cssClass = LibraryBrowser.getUserDataCssClass(userData.Key);
|
||||
|
||||
|
||||
if (!cssClass) {
|
||||
return;
|
||||
}
|
||||
@ -904,6 +904,16 @@
|
||||
|
||||
}
|
||||
|
||||
$(ApiClient).on('websocketmessage', onWebSocketMessage);
|
||||
function initializeApiClient(apiClient) {
|
||||
$(apiClient).off('websocketmessage.librarylist', onWebSocketMessage).on('websocketmessage.librarylist', onWebSocketMessage);
|
||||
}
|
||||
|
||||
$(function () {
|
||||
|
||||
$(ConnectionManager).on('apiclientcreated', function (e, apiClient) {
|
||||
|
||||
initializeApiClient(apiClient);
|
||||
});
|
||||
});
|
||||
|
||||
})(jQuery, document, window);
|
@ -23,25 +23,31 @@
|
||||
html += '<span class="icon-bar"></span>';
|
||||
html += '</div>';
|
||||
html += '</button>';
|
||||
|
||||
|
||||
html += '<div class="libraryMenuButtonText headerButton"><span>MEDIA</span><span class="mediaBrowserAccent">BROWSER</span></div>';
|
||||
|
||||
html += '<div class="viewMenuSecondary">';
|
||||
|
||||
html += '<button id="btnCast" class="btnCast btnDefaultCast headerButton headerButtonRight" type="button" data-role="none"><div class="headerSelectedPlayer"></div><div class="btnCastImage"></div></button>';
|
||||
if (user.localUser) {
|
||||
|
||||
html += '<button onclick="Search.showSearchPanel($.mobile.activePage);" type="button" data-role="none" class="headerButton headerButtonRight headerSearchButton"><img src="css/images/headersearch.png" /></button>';
|
||||
html += '<button id="btnCast" class="btnCast btnDefaultCast headerButton headerButtonRight" type="button" data-role="none"><div class="headerSelectedPlayer"></div><div class="btnCastImage"></div></button>';
|
||||
|
||||
html += '<button onclick="Search.showSearchPanel($.mobile.activePage);" type="button" data-role="none" class="headerButton headerButtonRight headerSearchButton"><img src="css/images/headersearch.png" /></button>';
|
||||
} else {
|
||||
html += '<button id="btnCast" class="btnCast btnDefaultCast headerButton headerButtonRight" type="button" data-role="none" style="visibility:hidden;"><div class="headerSelectedPlayer"></div><div class="btnCastImage"></div></button>';
|
||||
|
||||
}
|
||||
|
||||
html += '<a class="headerButton headerButtonRight headerUserButton" href="#" onclick="Dashboard.showUserFlyout(this);">';
|
||||
|
||||
var userButtonHeight = 21;
|
||||
if (user.PrimaryImageTag) {
|
||||
if (user.imageUrl) {
|
||||
|
||||
var url = ApiClient.getUserImageUrl(user.Id, {
|
||||
height: userButtonHeight,
|
||||
tag: user.PrimaryImageTag,
|
||||
type: "Primary"
|
||||
});
|
||||
var url = user.imageUrl;
|
||||
|
||||
if (user.supportsImageParams) {
|
||||
url += "height=" + userButtonHeight;
|
||||
}
|
||||
|
||||
html += '<img src="' + url + '" style="height:' + userButtonHeight + 'px;" />';
|
||||
} else {
|
||||
@ -50,7 +56,7 @@
|
||||
|
||||
html += '</a>';
|
||||
|
||||
if (user.Configuration.IsAdministrator) {
|
||||
if (user.canManageServer) {
|
||||
html += '<a href="dashboard.html" class="headerButton headerButtonRight"><img src="css/images/items/folders/settings.png" /></a>';
|
||||
}
|
||||
|
||||
@ -118,9 +124,17 @@
|
||||
|
||||
function updateLibraryMenu(panel) {
|
||||
|
||||
var apiClient = ConnectionManager.currentApiClient();
|
||||
|
||||
if (!apiClient) {
|
||||
|
||||
$('.adminMenuOptions').hide();
|
||||
return;
|
||||
}
|
||||
|
||||
var userId = Dashboard.getCurrentUserId();
|
||||
|
||||
ApiClient.getUserViews(userId).done(function (result) {
|
||||
apiClient.getUserViews(userId).done(function (result) {
|
||||
|
||||
var items = result.Items;
|
||||
|
||||
@ -136,7 +150,7 @@
|
||||
else if (i.CollectionType == "livetv") {
|
||||
itemId = "livetv";
|
||||
}
|
||||
|
||||
|
||||
if (i.Type == 'Channel') {
|
||||
viewMenuCssClass = 'channelsViewMenu';
|
||||
}
|
||||
@ -166,7 +180,7 @@
|
||||
|
||||
var requiresLibraryMenuRefresh = false;
|
||||
|
||||
function getLibraryMenu() {
|
||||
function getLibraryMenu(user) {
|
||||
|
||||
var panel = $('#libraryPanel');
|
||||
|
||||
@ -178,7 +192,10 @@
|
||||
|
||||
html += '<div style="margin: 0 -1em;">';
|
||||
|
||||
html += '<a class="lnkMediaFolder viewMenuLink viewMenuTextLink homeViewMenu" href="index.html">' + Globalize.translate('ButtonHome') + '</a>';
|
||||
var homeHref = ConnectionManager.currentApiClient() ? 'index.html' : 'selectserver.html';
|
||||
|
||||
html += '<a class="lnkMediaFolder viewMenuLink viewMenuTextLink homeViewMenu" href="' + homeHref + '">' + Globalize.translate('ButtonHome') + '</a>';
|
||||
|
||||
html += '<div class="libraryMenuDivider"></div>';
|
||||
|
||||
html += getViewsHtml();
|
||||
@ -364,7 +381,7 @@
|
||||
var page = this;
|
||||
if (!$('.viewMenuBar').length) {
|
||||
|
||||
Dashboard.getCurrentUser().done(function (user) {
|
||||
ConnectionManager.user().done(function (user) {
|
||||
|
||||
renderHeader(user);
|
||||
|
||||
@ -379,7 +396,7 @@
|
||||
}
|
||||
|
||||
var jpage = $(page);
|
||||
|
||||
|
||||
if (jpage.hasClass('libraryPage')) {
|
||||
$(document.body).addClass('libraryDocument').removeClass('dashboardDocument');
|
||||
}
|
||||
@ -413,13 +430,20 @@
|
||||
}
|
||||
});
|
||||
|
||||
function initializeApiClient(apiClient) {
|
||||
$(apiClient).off('websocketmessage.librarymenu', onWebSocketMessage).on('websocketmessage.librarymenu', onWebSocketMessage);
|
||||
}
|
||||
|
||||
$(function () {
|
||||
|
||||
$(MediaController).on('playerchange', function () {
|
||||
updateCastIcon();
|
||||
});
|
||||
|
||||
$(ApiClient).on('websocketmessage', onWebSocketMessage);
|
||||
$(ConnectionManager).on('apiclientcreated', function (e, apiClient) {
|
||||
|
||||
initializeApiClient(apiClient);
|
||||
});
|
||||
});
|
||||
|
||||
})(window, document, jQuery);
|
||||
|
@ -335,4 +335,4 @@
|
||||
programs = null;
|
||||
});
|
||||
|
||||
})(jQuery, document, ApiClient);
|
||||
})(jQuery, document);
|
@ -437,7 +437,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
$(ApiClient).on("websocketmessage", onWebSocketMessageReceived);
|
||||
|
||||
|
||||
function initializeApiClient(apiClient) {
|
||||
$(apiClient).on("websocketmessage", onWebSocketMessageReceived);
|
||||
}
|
||||
|
||||
$(function () {
|
||||
|
||||
$(ConnectionManager).on('apiclientcreated', function (e, apiClient) {
|
||||
|
||||
initializeApiClient(apiClient);
|
||||
});
|
||||
});
|
||||
|
||||
function getTargetsHtml(targets) {
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
var targets = [{
|
||||
name: 'My Browser',
|
||||
id: ApiClient.deviceId(),
|
||||
id: ConnectionManager.deviceId(),
|
||||
playerName: self.name,
|
||||
playableMediaTypes: ['Audio', 'Video'],
|
||||
isLocalPlayer: true,
|
||||
|
@ -10,7 +10,13 @@
|
||||
|
||||
self.getNotificationsSummary = function () {
|
||||
|
||||
self.getNotificationsSummaryPromise = self.getNotificationsSummaryPromise || ApiClient.getNotificationSummary(Dashboard.getCurrentUserId());
|
||||
var apiClient = ConnectionManager.currentApiClient();
|
||||
|
||||
if (!apiClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.getNotificationsSummaryPromise = self.getNotificationsSummaryPromise || apiClient.getNotificationSummary(Dashboard.getCurrentUserId());
|
||||
|
||||
return self.getNotificationsSummaryPromise;
|
||||
};
|
||||
@ -21,7 +27,13 @@
|
||||
return;
|
||||
}
|
||||
|
||||
self.getNotificationsSummary().done(function (summary) {
|
||||
var promise = self.getNotificationsSummary();
|
||||
|
||||
if (!promise) {
|
||||
return;
|
||||
}
|
||||
|
||||
promise.done(function (summary) {
|
||||
|
||||
var item = $('.btnNotificationsInner').removeClass('levelNormal').removeClass('levelWarning').removeClass('levelError').html(summary.UnreadCount);
|
||||
|
||||
@ -95,11 +107,15 @@
|
||||
|
||||
function refreshNotifications(startIndex, limit, elem, btn, showPaging) {
|
||||
|
||||
return ApiClient.getNotifications(Dashboard.getCurrentUserId(), { StartIndex: startIndex, Limit: limit }).done(function (result) {
|
||||
var apiClient = ConnectionManager.currentApiClient();
|
||||
|
||||
listUnreadNotifications(result.Notifications, result.TotalRecordCount, startIndex, limit, elem, btn, showPaging);
|
||||
if (apiClient) {
|
||||
return apiClient.getNotifications(Dashboard.getCurrentUserId(), { StartIndex: startIndex, Limit: limit }).done(function (result) {
|
||||
|
||||
});
|
||||
listUnreadNotifications(result.Notifications, result.TotalRecordCount, startIndex, limit, elem, btn, showPaging);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function listUnreadNotifications(list, totalRecordCount, startIndex, limit, elem, btn, showPaging) {
|
||||
@ -201,22 +217,33 @@
|
||||
|
||||
$(document).on('headercreated', function (e) {
|
||||
|
||||
$('<a class="headerButton headerButtonRight btnNotifications" href="#" title="Notifications"><div class="btnNotificationsInner">0</div></a>').insertAfter($('.headerUserButton')).on('click', Notifications.showNotificationsFlyout);
|
||||
|
||||
Notifications.updateNotificationCount();
|
||||
});
|
||||
|
||||
$(ApiClient).on("websocketmessage", function (e, msg) {
|
||||
|
||||
|
||||
if (msg.MessageType === "NotificationUpdated" || msg.MessageType === "NotificationAdded" || msg.MessageType === "NotificationsMarkedRead") {
|
||||
|
||||
Notifications.getNotificationsSummaryPromise = null;
|
||||
if (ConnectionManager.currentApiClient()) {
|
||||
$('<a class="headerButton headerButtonRight btnNotifications" href="#" title="Notifications"><div class="btnNotificationsInner">0</div></a>').insertAfter($('.headerUserButton')).on('click', Notifications.showNotificationsFlyout);
|
||||
|
||||
Notifications.updateNotificationCount();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
function initializeApiClient(apiClient) {
|
||||
$(apiClient).on("websocketmessage", function (e, msg) {
|
||||
|
||||
|
||||
if (msg.MessageType === "NotificationUpdated" || msg.MessageType === "NotificationAdded" || msg.MessageType === "NotificationsMarkedRead") {
|
||||
|
||||
Notifications.getNotificationsSummaryPromise = null;
|
||||
|
||||
Notifications.updateNotificationCount();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
$(function () {
|
||||
|
||||
$(ConnectionManager).on('apiclientcreated', function (e, apiClient) {
|
||||
|
||||
initializeApiClient(apiClient);
|
||||
});
|
||||
});
|
||||
|
||||
})(jQuery, document, Dashboard, LibraryBrowser);
|
@ -19,6 +19,18 @@
|
||||
});
|
||||
},
|
||||
|
||||
showNoConfigurationMessage: function() {
|
||||
Dashboard.alert({
|
||||
message: Globalize.translate('NoPluginConfigurationMessage')
|
||||
});
|
||||
},
|
||||
|
||||
showConnectMessage: function () {
|
||||
Dashboard.alert({
|
||||
message: Globalize.translate('MessagePluginConfigurationRequiresLocalAccess')
|
||||
});
|
||||
},
|
||||
|
||||
populateList: function (page, plugins, pluginConfigurationPages) {
|
||||
|
||||
plugins = plugins.sort(function (plugin1, plugin2) {
|
||||
@ -39,10 +51,14 @@
|
||||
|
||||
html += "<li>";
|
||||
|
||||
if (configPage) {
|
||||
if (Dashboard.isConnectMode()) {
|
||||
html += "<a onclick='PluginsPage.showConnectMessage();' href='#'>";
|
||||
}
|
||||
else if (configPage) {
|
||||
html += "<a href='" + Dashboard.getConfigurationPageUrl(configPage.Name) + "'>";
|
||||
} else {
|
||||
html += "<a onclick='Dashboard.alert(\"" + Globalize.translate('NoPluginConfigurationMessage') + "\");' href='#'>";
|
||||
}
|
||||
else {
|
||||
html += "<a onclick='PluginsPage.showNoConfigurationMessage();' href='#'>";
|
||||
}
|
||||
|
||||
html += "<h3>" + plugin.Name + "</h3>";
|
||||
|
@ -164,22 +164,28 @@
|
||||
|
||||
var deferred = $.Deferred();
|
||||
|
||||
ApiClient.getSessions().done(function (sessions) {
|
||||
var apiClient = ConnectionManager.currentApiClient();
|
||||
|
||||
var currentTargetId = MediaController.getPlayerInfo().id;
|
||||
if (apiClient) {
|
||||
apiClient.getSessions().done(function (sessions) {
|
||||
|
||||
// Update existing data
|
||||
//updateSessionInfo(popup, msg.Data);
|
||||
var session = sessions.filter(function (s) {
|
||||
return s.Id == currentTargetId;
|
||||
})[0];
|
||||
var currentTargetId = MediaController.getPlayerInfo().id;
|
||||
|
||||
if (session) {
|
||||
session = getPlayerState(session);
|
||||
}
|
||||
// Update existing data
|
||||
//updateSessionInfo(popup, msg.Data);
|
||||
var session = sessions.filter(function (s) {
|
||||
return s.Id == currentTargetId;
|
||||
})[0];
|
||||
|
||||
deferred.resolveWith(null, [session]);
|
||||
});
|
||||
if (session) {
|
||||
session = getPlayerState(session);
|
||||
}
|
||||
|
||||
deferred.resolveWith(null, [session]);
|
||||
});
|
||||
} else {
|
||||
deferred.resolveWith(null, [{}]);
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
};
|
||||
@ -236,31 +242,37 @@
|
||||
ControllableByUserId: Dashboard.getCurrentUserId()
|
||||
};
|
||||
|
||||
ApiClient.getSessions(sessionQuery).done(function (sessions) {
|
||||
var apiClient = ConnectionManager.currentApiClient();
|
||||
|
||||
var targets = sessions.filter(function (s) {
|
||||
if (apiClient) {
|
||||
apiClient.getSessions(sessionQuery).done(function (sessions) {
|
||||
|
||||
return s.DeviceId != ApiClient.deviceId();
|
||||
var targets = sessions.filter(function (s) {
|
||||
|
||||
}).map(function (s) {
|
||||
return {
|
||||
name: s.DeviceName,
|
||||
deviceName: s.DeviceName,
|
||||
id: s.Id,
|
||||
playerName: self.name,
|
||||
appName: s.Client,
|
||||
playableMediaTypes: s.PlayableMediaTypes,
|
||||
isLocalPlayer: false,
|
||||
supportedCommands: s.SupportedCommands
|
||||
};
|
||||
return s.DeviceId != apiClient.deviceId();
|
||||
|
||||
}).map(function (s) {
|
||||
return {
|
||||
name: s.DeviceName,
|
||||
deviceName: s.DeviceName,
|
||||
id: s.Id,
|
||||
playerName: self.name,
|
||||
appName: s.Client,
|
||||
playableMediaTypes: s.PlayableMediaTypes,
|
||||
isLocalPlayer: false,
|
||||
supportedCommands: s.SupportedCommands
|
||||
};
|
||||
});
|
||||
|
||||
deferred.resolveWith(null, [targets]);
|
||||
|
||||
}).fail(function () {
|
||||
|
||||
deferred.reject();
|
||||
});
|
||||
|
||||
deferred.resolveWith(null, [targets]);
|
||||
|
||||
}).fail(function () {
|
||||
|
||||
deferred.reject();
|
||||
});
|
||||
} else {
|
||||
deferred.resolveWith(null, []);
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
};
|
||||
@ -290,6 +302,8 @@
|
||||
|
||||
function onWebSocketMessageReceived(e, msg) {
|
||||
|
||||
var apiClient = this;
|
||||
|
||||
if (msg.MessageType === "Sessions") {
|
||||
|
||||
var currentTargetId = MediaController.getPlayerInfo().id;
|
||||
@ -314,7 +328,7 @@
|
||||
}
|
||||
else if (msg.MessageType === "PlaybackStart") {
|
||||
|
||||
if (msg.Data.DeviceId != ApiClient.deviceId()) {
|
||||
if (msg.Data.DeviceId != apiClient.deviceId()) {
|
||||
if (MediaController.getPlayerInfo().id == msg.Data.Id) {
|
||||
firePlaybackEvent('playbackstart', msg.Data);
|
||||
}
|
||||
@ -322,7 +336,7 @@
|
||||
}
|
||||
else if (msg.MessageType === "PlaybackStopped") {
|
||||
|
||||
if (msg.Data.DeviceId != ApiClient.deviceId()) {
|
||||
if (msg.Data.DeviceId != apiClient.deviceId()) {
|
||||
if (MediaController.getPlayerInfo().id == msg.Data.Id) {
|
||||
firePlaybackEvent('playbackstop', msg.Data);
|
||||
}
|
||||
@ -330,6 +344,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
$(ApiClient).on("websocketmessage", onWebSocketMessageReceived).on("websocketopen", onWebSocketConnectionChange);
|
||||
|
||||
function initializeApiClient(apiClient) {
|
||||
$(apiClient).on("websocketmessage", onWebSocketMessageReceived).on("websocketopen", onWebSocketConnectionChange);
|
||||
}
|
||||
|
||||
$(function () {
|
||||
|
||||
$(ConnectionManager).on('apiclientcreated', function (e, apiClient) {
|
||||
|
||||
initializeApiClient(apiClient);
|
||||
});
|
||||
});
|
||||
|
||||
})(window, document, jQuery);
|
120
dashboard-ui/scripts/selectserver.js
Normal file
120
dashboard-ui/scripts/selectserver.js
Normal file
@ -0,0 +1,120 @@
|
||||
(function () {
|
||||
|
||||
function connectToServer(page, server) {
|
||||
|
||||
Dashboard.showLoadingMsg();
|
||||
|
||||
ConnectionManager.connectToServer(server).done(function (result) {
|
||||
|
||||
Dashboard.hideLoadingMsg();
|
||||
|
||||
switch (result.State) {
|
||||
|
||||
case MediaBrowser.ConnectionState.Unavilable:
|
||||
showServerConnectionFailure();
|
||||
break;
|
||||
case MediaBrowser.ConnectionState.SignedIn:
|
||||
{
|
||||
var apiClient = result.ApiClient;
|
||||
|
||||
Dashboard.serverAddress(apiClient.serverAddress());
|
||||
Dashboard.setCurrentUser(apiClient.getCurrentUserId(), apiClient.accessToken());
|
||||
window.location = 'index.html';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
function showServerConnectionFailure() {
|
||||
|
||||
Dashboard.alert({
|
||||
message: Globalize.translate("MessageUnableToConnectToServer"),
|
||||
title: Globalize.translate("HeaderConnectionFailure")
|
||||
});
|
||||
}
|
||||
|
||||
function renderServers(page, servers) {
|
||||
|
||||
if (servers.length) {
|
||||
$('.noServersMessage', page).hide();
|
||||
} else {
|
||||
$('.noServersMessage', page).show();
|
||||
}
|
||||
|
||||
var html = '<ul data-role="listview" data-inset="true">';
|
||||
|
||||
html += servers.map(function (s) {
|
||||
|
||||
var serverHtml = '';
|
||||
|
||||
serverHtml += '<li>';
|
||||
|
||||
serverHtml += '<a class="lnkServer" data-serverid="' + s.Id + '" href="#">';
|
||||
serverHtml += '<h3>';
|
||||
serverHtml += s.Name;
|
||||
serverHtml += '</h3>';
|
||||
serverHtml += '</a>';
|
||||
|
||||
serverHtml += '</li>';
|
||||
|
||||
return serverHtml;
|
||||
|
||||
}).join('');
|
||||
|
||||
html += '</ul>';
|
||||
|
||||
var elem = $('.serverList', page).html(html).trigger('create');
|
||||
|
||||
$('.lnkServer', elem).on('click', function () {
|
||||
|
||||
var id = this.getAttribute('data-serverid');
|
||||
var server = servers.filter(function (s) {
|
||||
return s.Id == id;
|
||||
})[0];
|
||||
|
||||
connectToServer(page, server);
|
||||
});
|
||||
}
|
||||
|
||||
function loadPage(page) {
|
||||
|
||||
Dashboard.showLoadingMsg();
|
||||
|
||||
ConnectionManager.getServers().done(function (servers) {
|
||||
|
||||
renderServers(page, servers);
|
||||
|
||||
Dashboard.hideLoadingMsg();
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on('pageshow', "#selectServerPage", function () {
|
||||
|
||||
var page = this;
|
||||
|
||||
loadPage(page);
|
||||
|
||||
});
|
||||
|
||||
window.SelectServerPage = {
|
||||
|
||||
onServerAddressEntrySubmit: function () {
|
||||
|
||||
Dashboard.showLoadingMsg();
|
||||
|
||||
var form = this;
|
||||
var page = $(form).parents('.page');
|
||||
|
||||
|
||||
// Disable default form submission
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
})();
|
@ -77,7 +77,7 @@ var Dashboard = {
|
||||
|
||||
var userId = Dashboard.getCurrentUserId();
|
||||
|
||||
Dashboard.getUserPromise = ApiClient.getUser(userId).fail(Dashboard.logout);
|
||||
Dashboard.getUserPromise = ConnectionManager.currentApiClient().getUser(userId).fail(Dashboard.logout);
|
||||
}
|
||||
|
||||
return Dashboard.getUserPromise;
|
||||
@ -108,7 +108,7 @@ var Dashboard = {
|
||||
|
||||
var address = store.getItem('serverAddress');
|
||||
|
||||
if (!address) {
|
||||
if (!address && !Dashboard.isConnectMode()) {
|
||||
var loc = window.location;
|
||||
|
||||
address = loc.protocol + '//' + loc.hostname;
|
||||
@ -146,7 +146,11 @@ var Dashboard = {
|
||||
store.setItem("userId", userId);
|
||||
store.setItem("token", token);
|
||||
|
||||
ApiClient.setCurrentUserId(userId, token);
|
||||
var apiClient = ConnectionManager.currentApiClient();
|
||||
|
||||
if (apiClient) {
|
||||
apiClient.setCurrentUserId(userId, token);
|
||||
}
|
||||
Dashboard.getUserPromise = null;
|
||||
},
|
||||
|
||||
@ -157,7 +161,6 @@ var Dashboard = {
|
||||
|
||||
logout: function (logoutWithServer) {
|
||||
|
||||
ConnectionManager.logoutFromConnect();
|
||||
store.removeItem("userId");
|
||||
store.removeItem("token");
|
||||
|
||||
@ -168,7 +171,7 @@ var Dashboard = {
|
||||
if (logoutWithServer === false) {
|
||||
window.location = loginPage;
|
||||
} else {
|
||||
ApiClient.logout().done(function () {
|
||||
ConnectionManager.logout().done(function () {
|
||||
window.location = loginPage;
|
||||
});
|
||||
|
||||
@ -529,30 +532,28 @@ var Dashboard = {
|
||||
|
||||
showUserFlyout: function (context) {
|
||||
|
||||
Dashboard.getCurrentUser().done(function (user) {
|
||||
ConnectionManager.user().done(function (user) {
|
||||
|
||||
var html = '<div data-role="panel" data-position="right" data-display="overlay" id="userFlyout" data-position-fixed="true" data-theme="a">';
|
||||
|
||||
html += '<h3>';
|
||||
|
||||
if (user.PrimaryImageTag) {
|
||||
var imageUrl = ApiClient.getUserImageUrl(user.Id, {
|
||||
if (user.imageUrl) {
|
||||
var url = user.imageUrl;
|
||||
|
||||
width: 28,
|
||||
tag: user.PrimaryImageTag,
|
||||
type: "Primary"
|
||||
if (user.supportsImageParams) {
|
||||
url += "width=" + 28;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
html += '<img style="max-width:28px;vertical-align:middle;margin-right:5px;" src="' + imageUrl + '" />';
|
||||
html += '<img style="max-width:28px;vertical-align:middle;margin-right:5px;" src="' + url + '" />';
|
||||
}
|
||||
html += user.Name;
|
||||
html += user.name;
|
||||
html += '</h3>';
|
||||
|
||||
html += '<form>';
|
||||
|
||||
if (user.Configuration.EnableUserPreferenceAccess) {
|
||||
html += '<p><a data-mini="true" data-role="button" href="mypreferencesdisplay.html?userId=' + user.Id + '" data-icon="gear">' + Globalize.translate('ButtonMyPreferences') + '</button></a>';
|
||||
if (user.localUser && user.localUser.Configuration.EnableUserPreferenceAccess) {
|
||||
html += '<p><a data-mini="true" data-role="button" href="mypreferencesdisplay.html?userId=' + user.localUser.Id + '" data-icon="gear">' + Globalize.translate('ButtonMyPreferences') + '</button></a>';
|
||||
}
|
||||
|
||||
html += '<p><button data-mini="true" type="button" onclick="Dashboard.logout();" data-icon="lock">' + Globalize.translate('ButtonSignOut') + '</button></p>';
|
||||
@ -633,10 +634,6 @@ var Dashboard = {
|
||||
|
||||
ensureToolsMenu: function (page, user) {
|
||||
|
||||
if (!page.hasClass('type-interior')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var sidebar = $('.toolsSidebar', page);
|
||||
|
||||
if (!sidebar.length) {
|
||||
@ -785,16 +782,6 @@ var Dashboard = {
|
||||
ApiClient.openWebSocket();
|
||||
},
|
||||
|
||||
onWebSocketOpened: function () {
|
||||
|
||||
ApiClient.reportCapabilities({
|
||||
PlayableMediaTypes: "Audio,Video",
|
||||
|
||||
SupportedCommands: Dashboard.getSupportedRemoteCommands().join(',')
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
processGeneralCommand: function (cmd) {
|
||||
|
||||
// Full list
|
||||
@ -1189,6 +1176,11 @@ var Dashboard = {
|
||||
"DisplayMessage"
|
||||
];
|
||||
|
||||
},
|
||||
|
||||
isServerlessPage: function() {
|
||||
var url = getWindowUrl().toLowerCase();
|
||||
return url.indexOf('connectlogin.html') != -1 || url.indexOf('selectserver.html') != -1;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1231,43 +1223,57 @@ var Dashboard = {
|
||||
alert(Globalize.translate('MessageBrowserDoesNotSupportWebSockets'));
|
||||
}
|
||||
|
||||
function initializeApiClient(apiClient) {
|
||||
|
||||
$(apiClient).off('.dashboard').on("websocketmessage.dashboard", Dashboard.onWebSocketMessageReceived);
|
||||
|
||||
// TODO: Improve with http://webpjs.appspot.com/
|
||||
apiClient.supportsWebP($.browser.chrome);
|
||||
}
|
||||
|
||||
var appName = "Dashboard";
|
||||
var appVersion = window.dashboardVersion;
|
||||
var deviceName = generateDeviceName();
|
||||
var deviceId = MediaBrowser.ApiClient.generateDeviceId();
|
||||
var credentialProvider = new MediaBrowser.CredentialProvider();
|
||||
|
||||
window.ApiClient = new MediaBrowser.ApiClient(Dashboard.serverAddress(), appName, appVersion, deviceName, deviceId);
|
||||
window.ConnectionManager = new MediaBrowser.ConnectionManager(new MediaBrowser.CredentialProvider(), appName, appVersion, deviceName, deviceId);
|
||||
var capabilities = {
|
||||
PlayableMediaTypes: "Audio,Video",
|
||||
|
||||
$(ApiClient).on("websocketopen", Dashboard.onWebSocketOpened)
|
||||
.on("websocketmessage", Dashboard.onWebSocketMessageReceived);
|
||||
SupportedCommands: Dashboard.getSupportedRemoteCommands().join(',')
|
||||
};
|
||||
|
||||
// TODO: Improve with http://webpjs.appspot.com/
|
||||
ApiClient.supportsWebP($.browser.chrome);
|
||||
window.ConnectionManager = new MediaBrowser.ConnectionManager(credentialProvider, appName, appVersion, deviceName, deviceId, capabilities);
|
||||
if (Dashboard.isConnectMode()) {
|
||||
|
||||
ApiClient.setCurrentUserId(Dashboard.getCurrentUserId(), Dashboard.getAccessToken());
|
||||
$(ConnectionManager).on('apiclientcreated', function (e, apiClient) {
|
||||
|
||||
//test();
|
||||
initializeApiClient(apiClient);
|
||||
});
|
||||
|
||||
if (Dashboard.serverAddress() && Dashboard.getCurrentUserId() && Dashboard.getAccessToken() && !Dashboard.isServerlessPage()) {
|
||||
window.ApiClient = new MediaBrowser.ApiClient(Dashboard.serverAddress(), appName, appVersion, deviceName, deviceId, capabilities);
|
||||
|
||||
ApiClient.setCurrentUserId(Dashboard.getCurrentUserId(), Dashboard.getAccessToken());
|
||||
|
||||
initializeApiClient(ApiClient);
|
||||
|
||||
ConnectionManager.addApiClient(ApiClient);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
window.ApiClient = new MediaBrowser.ApiClient(Dashboard.serverAddress(), appName, appVersion, deviceName, deviceId, capabilities);
|
||||
|
||||
ApiClient.setCurrentUserId(Dashboard.getCurrentUserId(), Dashboard.getAccessToken());
|
||||
|
||||
initializeApiClient(ApiClient);
|
||||
|
||||
ConnectionManager.addApiClient(ApiClient);
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
function test() {
|
||||
|
||||
ConnectionManager.loginToConnect("luke", "ac501ac7111a1e5").done(function (result) {
|
||||
|
||||
var promise = ConnectionManager.connect();
|
||||
|
||||
promise.done(function (r) {
|
||||
alert(JSON.stringify(r));
|
||||
|
||||
}).fail(function() {
|
||||
|
||||
alert('fail');
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
$(function () {
|
||||
|
||||
var videoPlayerHtml = '<div id="mediaPlayer" data-theme="b" class="ui-bar-b" style="display: none;">';
|
||||
@ -1352,11 +1358,13 @@ $(function () {
|
||||
|
||||
$(window).on("beforeunload", function () {
|
||||
|
||||
var apiClient = ConnectionManager.currentApiClient();
|
||||
|
||||
// Close the connection gracefully when possible
|
||||
if (ApiClient.isWebSocketOpen() && !MediaPlayer.isPlaying()) {
|
||||
if (apiClient && apiClient.isWebSocketOpen() && !MediaPlayer.isPlaying()) {
|
||||
|
||||
console.log('Sending close web socket command');
|
||||
ApiClient.closeWebSocket();
|
||||
apiClient.closeWebSocket();
|
||||
}
|
||||
});
|
||||
|
||||
@ -1397,19 +1405,28 @@ $(document).on('pagebeforeshow', ".page", function () {
|
||||
}
|
||||
}
|
||||
|
||||
var apiClient = ConnectionManager.currentApiClient();
|
||||
|
||||
if (Dashboard.getAccessToken() && Dashboard.getCurrentUserId()) {
|
||||
|
||||
Dashboard.getCurrentUser().done(function (user) {
|
||||
if (apiClient) {
|
||||
Dashboard.getCurrentUser().done(function (user) {
|
||||
|
||||
if (!user.Configuration.IsAdministrator && page.hasClass('type-interior') && !page.hasClass('publicUserPage')) {
|
||||
window.location.replace("index.html");
|
||||
return;
|
||||
}
|
||||
var isSettingsPage = page.hasClass('type-interior');
|
||||
|
||||
Dashboard.ensureToolsMenu(page, user);
|
||||
Dashboard.ensureHeader(page);
|
||||
Dashboard.ensurePageTitle(page);
|
||||
});
|
||||
if (!user.Configuration.IsAdministrator && isSettingsPage) {
|
||||
window.location.replace("index.html");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isSettingsPage) {
|
||||
Dashboard.ensureToolsMenu(page, user);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Dashboard.ensureHeader(page);
|
||||
Dashboard.ensurePageTitle(page);
|
||||
}
|
||||
|
||||
else {
|
||||
@ -1425,7 +1442,7 @@ $(document).on('pagebeforeshow', ".page", function () {
|
||||
Dashboard.ensurePageTitle(page);
|
||||
}
|
||||
|
||||
if (!ApiClient.isWebSocketOpen()) {
|
||||
if (apiClient && !apiClient.isWebSocketOpen()) {
|
||||
Dashboard.refreshSystemInfoFromServer();
|
||||
}
|
||||
});
|
@ -31,7 +31,7 @@
|
||||
|
||||
$('.userMenu', page).popup("close").remove();
|
||||
|
||||
var html = '<div data-role="popup" class="userMenu" data-history="false" data-theme="a">';
|
||||
var html = '<div data-role="popup" class="userMenu" data-theme="a">';
|
||||
|
||||
html += '<ul data-role="listview" style="min-width: 180px;">';
|
||||
html += '<li data-role="list-divider">' + Globalize.translate('HeaderMenu') + '</li>';
|
||||
@ -174,7 +174,7 @@
|
||||
|
||||
$('.userMenu', page).popup("close").remove();
|
||||
|
||||
var html = '<div data-role="popup" class="userMenu" data-history="false" data-theme="a">';
|
||||
var html = '<div data-role="popup" class="userMenu" data-theme="a">';
|
||||
|
||||
html += '<ul data-role="listview" style="min-width: 180px;">';
|
||||
html += '<li data-role="list-divider">' + Globalize.translate('HeaderMenu') + '</li>';
|
||||
|
24
dashboard-ui/selectserver.html
Normal file
24
dashboard-ui/selectserver.html
Normal file
@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>${TitleMediaBrowser}</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="selectServerPage" data-role="page" class="page libraryPage" data-theme="b">
|
||||
|
||||
<div data-role="content">
|
||||
|
||||
<div class="readOnlyContent" style="margin: 0 auto;">
|
||||
<h1>${HeaderSelectServer}</h1>
|
||||
|
||||
<div class="serverList"></div>
|
||||
<br />
|
||||
<div class="noServersMessage" style="display:none;">
|
||||
${MessageNoServersAvailableToConnect}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -16,7 +16,7 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
Remote: 1
|
||||
};
|
||||
|
||||
return function (credentialProvider, appName, applicationVersion, deviceName, deviceId) {
|
||||
return function (credentialProvider, appName, applicationVersion, deviceName, deviceId, capabilities) {
|
||||
|
||||
var self = this;
|
||||
var apiClients = [];
|
||||
@ -77,6 +77,34 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
return connectUser;
|
||||
};
|
||||
|
||||
self.appVersion = function() {
|
||||
return applicationVersion;
|
||||
};
|
||||
|
||||
self.deviceId = function () {
|
||||
return deviceId;
|
||||
};
|
||||
|
||||
self.currentApiClient = function () {
|
||||
|
||||
return apiClients[0];
|
||||
};
|
||||
|
||||
self.addApiClient = function (apiClient) {
|
||||
|
||||
apiClients.push(apiClient);
|
||||
|
||||
apiClient.getPublicSystemInfo().done(function (systemInfo) {
|
||||
|
||||
var server = {};
|
||||
updateServerInfo(server, systemInfo);
|
||||
|
||||
apiClient.serverInfo(server);
|
||||
$(this).trigger('apiclientcreated', [apiClient]);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
function onConnectAuthenticated(user) {
|
||||
|
||||
connectUser = user;
|
||||
@ -91,23 +119,27 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
|
||||
var url = connectionMode == MediaBrowser.ConnectionMode.Local ? server.LocalAddress : server.RemoteAddress;
|
||||
|
||||
apiClient = new MediaBrowser.ApiClient(url, appName, applicationVersion, deviceName, deviceId);
|
||||
apiClient = new MediaBrowser.ApiClient(url, appName, applicationVersion, deviceName, deviceId, capabilities);
|
||||
|
||||
apiClients.push(apiClient);
|
||||
|
||||
apiClient.serverInfo(server);
|
||||
|
||||
$(apiClient).on('authenticated', function (e, result) {
|
||||
onLocalAuthenticated(this, result);
|
||||
});
|
||||
|
||||
$(this).trigger('apiclientcreated', [apiClient]);
|
||||
|
||||
}
|
||||
|
||||
if (!server.accessToken) {
|
||||
if (!server.AccessToken) {
|
||||
|
||||
apiClient.clearAuthenticationInfo();
|
||||
}
|
||||
else {
|
||||
|
||||
apiClient.setAuthenticationInfo(server.accessToken, server.userId);
|
||||
apiClient.setAuthenticationInfo(server.AccessToken, server.UserId);
|
||||
}
|
||||
|
||||
return apiClient;
|
||||
@ -152,10 +184,7 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
|
||||
if (self.isLoggedIntoConnect()) {
|
||||
deferred.resolveWith(null, [[]]);
|
||||
|
||||
} else {
|
||||
if (self.isLoggedIntoConnect() && !connectUser) {
|
||||
getConnectUser(credentials.ConnectUserId, credentials.ConnectAccessToken).done(function (user) {
|
||||
|
||||
onConnectAuthenticated(user);
|
||||
@ -165,6 +194,9 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
|
||||
deferred.resolveWith(null, [[]]);
|
||||
});
|
||||
|
||||
} else {
|
||||
deferred.resolveWith(null, [[]]);
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
@ -172,7 +204,7 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
|
||||
function getConnectUser(userId, accessToken) {
|
||||
|
||||
var url = "https://connect.mediabrowser.tv/service/user?userId=" + userId;
|
||||
var url = "https://connect.mediabrowser.tv/service/user?id=" + userId;
|
||||
|
||||
return $.ajax({
|
||||
type: "GET",
|
||||
@ -281,6 +313,79 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
return deferred.promise();
|
||||
}
|
||||
|
||||
function getImageUrl(localUser) {
|
||||
|
||||
if (connectUser && connectUser.ImageUrl) {
|
||||
return {
|
||||
url: connectUser.ImageUrl
|
||||
};
|
||||
}
|
||||
if (localUser.PrimaryImageTag) {
|
||||
|
||||
var apiClient = self.getApiClient(localUser);
|
||||
|
||||
var url = apiClient.getUserImageUrl(localUser.Id, {
|
||||
tag: localUser.PrimaryImageTag,
|
||||
type: "Primary"
|
||||
});
|
||||
|
||||
return {
|
||||
url: url,
|
||||
supportsImageParams: true
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
url: null,
|
||||
supportsImageParams: false
|
||||
};
|
||||
}
|
||||
|
||||
self.user = function() {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
|
||||
var localUser;
|
||||
|
||||
function onLocalUserDone() {
|
||||
|
||||
var image = getImageUrl(localUser);
|
||||
|
||||
deferred.resolveWith(null, [
|
||||
{
|
||||
connectUser: connectUser,
|
||||
localUser: localUser,
|
||||
name: connectUser ? connectUser.Name : localUser.Name,
|
||||
canManageServer: localUser && localUser.Configuration.IsAdministrator,
|
||||
imageUrl: image.url,
|
||||
supportsImageParams: image.supportsParams
|
||||
}]);
|
||||
}
|
||||
|
||||
function onEnsureConnectUserDone() {
|
||||
|
||||
var apiClient = self.currentApiClient();
|
||||
if (apiClient && apiClient.getCurrentUserId()) {
|
||||
apiClient.getUser(apiClient.getCurrentUserId()).done(function (u) {
|
||||
localUser = u;
|
||||
}).always(onLocalUserDone);
|
||||
} else {
|
||||
onLocalUserDone();
|
||||
}
|
||||
}
|
||||
|
||||
var credentials = credentialProvider.credentials();
|
||||
|
||||
if (credentials.ConnectUserId && credentials.ConnectAccessToken) {
|
||||
ensureConnectUser(credentials).always(onEnsureConnectUserDone);
|
||||
} else {
|
||||
onEnsureConnectUserDone();
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
|
||||
};
|
||||
|
||||
self.isLoggedIntoConnect = function () {
|
||||
|
||||
return self.connectToken() && self.connectUserId();
|
||||
@ -383,6 +488,10 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
|
||||
var newList = mergeServers(servers, result);
|
||||
|
||||
newList.sort(function (a, b) {
|
||||
return b.DateLastAccessed - a.DateLastAccessed;
|
||||
});
|
||||
|
||||
deferred.resolveWith(null, [newList]);
|
||||
|
||||
credentials.servers = newList;
|
||||
@ -413,12 +522,10 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
|
||||
var deferred = $.Deferred();
|
||||
|
||||
servers.sort(function (a, b) {
|
||||
return b.DateLastAccessed - a.DateLastAccessed;
|
||||
});
|
||||
|
||||
if (servers.length == 1) {
|
||||
if (!servers[0].DateLastAccessed && !self.connectUser()) {
|
||||
|
||||
if (!servers[0].DateLastAccessed && !self.connectUserId()) {
|
||||
|
||||
deferred.resolveWith(null, [
|
||||
{
|
||||
Servers: servers,
|
||||
@ -426,24 +533,30 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
ConnectUser: self.connectUser()
|
||||
}
|
||||
]);
|
||||
|
||||
} else {
|
||||
|
||||
self.connectToServer(servers[0]).done(function (result) {
|
||||
|
||||
if (result.State == MediaBrowser.ConnectionState.Unavailable) {
|
||||
result.State = MediaBrowser.ConnectionState.ServerSelection;
|
||||
}
|
||||
|
||||
deferred.resolveWith(null, [result]);
|
||||
|
||||
}).fail(function () {
|
||||
|
||||
deferred.resolveWith(null, [
|
||||
{
|
||||
Servers: servers,
|
||||
State: MediaBrowser.ConnectionState.ServerSelection,
|
||||
ConnectUser: self.connectUser()
|
||||
}
|
||||
]);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
self.connectToServer(servers[0]).done(function (result) {
|
||||
|
||||
deferred.resolveWith(null, [result]);
|
||||
|
||||
}).fail(function () {
|
||||
|
||||
deferred.resolveWith(null, [
|
||||
{
|
||||
Servers: servers,
|
||||
State: MediaBrowser.ConnectionState.ServerSelection,
|
||||
ConnectUser: self.connectUser()
|
||||
}
|
||||
]);
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
// Find the first server with a saved access token
|
||||
@ -468,10 +581,11 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
|
||||
});
|
||||
} else {
|
||||
|
||||
deferred.resolveWith(null, [
|
||||
{
|
||||
Servers: servers,
|
||||
State: servers.length ? MediaBrowser.ConnectionState.ServerSelection : MediaBrowser.ConnectionState.Unavailable,
|
||||
State: (!servers.length && !self.connectUser()) ? MediaBrowser.ConnectionState.Unavailable : MediaBrowser.ConnectionState.ServerSelection,
|
||||
ConnectUser: self.connectUser()
|
||||
}]);
|
||||
}
|
||||
@ -576,6 +690,7 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
|
||||
if (server.LocalAddress) {
|
||||
|
||||
//onLocalTestDone();
|
||||
// Try to connect to the local address
|
||||
tryConnect(server.LocalAddress).done(function (result) {
|
||||
|
||||
@ -657,8 +772,16 @@ MediaBrowser.ConnectionManager = function (store) {
|
||||
|
||||
self.getApiClient = function (item) {
|
||||
|
||||
// TODO: accept string + objet
|
||||
return apiClients[0];
|
||||
// Accept string + object
|
||||
if (item.ServerId) {
|
||||
item = item.ServerId;
|
||||
}
|
||||
|
||||
return apiClients.filter(function (a) {
|
||||
|
||||
return a.serverInfo().Id = item;
|
||||
|
||||
})[0];
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,11 @@ MediaBrowser.CredentialProvider = function (store) {
|
||||
store.setItem('servercredentials', JSON.stringify(get()));
|
||||
}
|
||||
|
||||
self.clear = function() {
|
||||
credentials = null;
|
||||
store.removeItem('servercredentials');
|
||||
};
|
||||
|
||||
self.credentials = function (data) {
|
||||
|
||||
if (data) {
|
||||
|
@ -10,7 +10,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
|
||||
* @param {String} clientName
|
||||
* @param {String} applicationVersion
|
||||
*/
|
||||
return function (serverAddress, clientName, applicationVersion, deviceName, deviceId) {
|
||||
return function (serverAddress, clientName, applicationVersion, deviceName, deviceId, capabilities) {
|
||||
|
||||
if (!serverAddress) {
|
||||
throw new Error("Must supply a serverAddress");
|
||||
@ -26,6 +26,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
|
||||
var currentUserId;
|
||||
var accessToken;
|
||||
var webSocket;
|
||||
var serverInfo;
|
||||
|
||||
/**
|
||||
* Gets the server address.
|
||||
@ -40,6 +41,13 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
|
||||
return "/mediabrowser";
|
||||
};
|
||||
|
||||
self.serverInfo = function (info) {
|
||||
|
||||
serverInfo = info || serverInfo;
|
||||
|
||||
return serverInfo;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets or sets the current user id.
|
||||
*/
|
||||
@ -89,27 +97,29 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
|
||||
/**
|
||||
* Wraps around jQuery ajax methods to add additional info to the request.
|
||||
*/
|
||||
self.ajax = function (request) {
|
||||
self.ajax = function (request, includeAuthorization) {
|
||||
|
||||
if (!request) {
|
||||
throw new Error("Request cannot be null");
|
||||
}
|
||||
|
||||
if (clientName) {
|
||||
if (includeAuthorization !== false) {
|
||||
if (clientName) {
|
||||
|
||||
var auth = 'MediaBrowser Client="' + clientName + '", Device="' + deviceName + '", DeviceId="' + deviceId + '", Version="' + applicationVersion + '"';
|
||||
var auth = 'MediaBrowser Client="' + clientName + '", Device="' + deviceName + '", DeviceId="' + deviceId + '", Version="' + applicationVersion + '"';
|
||||
|
||||
if (currentUserId) {
|
||||
auth += ', UserId="' + currentUserId + '"';
|
||||
if (currentUserId) {
|
||||
auth += ', UserId="' + currentUserId + '"';
|
||||
}
|
||||
|
||||
request.headers = {
|
||||
Authorization: auth
|
||||
};
|
||||
}
|
||||
|
||||
request.headers = {
|
||||
Authorization: auth
|
||||
};
|
||||
}
|
||||
|
||||
if (accessToken) {
|
||||
request.headers['X-MediaBrowser-Token'] = accessToken;
|
||||
if (accessToken) {
|
||||
request.headers['X-MediaBrowser-Token'] = accessToken;
|
||||
}
|
||||
}
|
||||
|
||||
return $.ajax(request);
|
||||
@ -146,7 +156,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
|
||||
return url;
|
||||
};
|
||||
|
||||
self.enableAutomaticNetworking = function(server, connectionMode) {
|
||||
self.enableAutomaticNetworking = function (server, connectionMode) {
|
||||
|
||||
};
|
||||
|
||||
@ -171,6 +181,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
|
||||
|
||||
self.sendWebSocketMessage("Identity", clientName + "|" + deviceId + "|" + applicationVersion + "|" + deviceName);
|
||||
|
||||
self.reportCapabilities(capabilities);
|
||||
|
||||
$(self).trigger("websocketopen");
|
||||
|
||||
}, 500);
|
||||
@ -848,6 +860,21 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the current server status
|
||||
*/
|
||||
self.getPublicSystemInfo = function () {
|
||||
|
||||
var url = self.getUrl("System/Info/Public");
|
||||
|
||||
return self.ajax({
|
||||
type: "GET",
|
||||
url: url,
|
||||
dataType: "json"
|
||||
|
||||
}, false);
|
||||
};
|
||||
|
||||
self.getInstantMixFromSong = function (itemId, options) {
|
||||
|
||||
var url = self.getUrl("Songs/" + itemId + "/InstantMix", options);
|
||||
@ -2049,7 +2076,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
|
||||
type: "GET",
|
||||
url: url,
|
||||
dataType: "json"
|
||||
});
|
||||
|
||||
}, false);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2081,7 +2109,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
|
||||
};
|
||||
|
||||
var supportsWebP = false;
|
||||
self.supportsWebP = function(val) {
|
||||
self.supportsWebP = function (val) {
|
||||
|
||||
if (val != null) {
|
||||
supportsWebP = val;
|
||||
@ -2264,7 +2292,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
|
||||
dataType: "json",
|
||||
contentType: "application/json"
|
||||
|
||||
}).done(function(result) {
|
||||
}).done(function (result) {
|
||||
|
||||
|
||||
$(self).trigger('authenticated', [result]);
|
||||
@ -3170,7 +3198,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
|
||||
|
||||
(function (store) {
|
||||
|
||||
MediaBrowser.ApiClient.generateDeviceId = function() {
|
||||
MediaBrowser.ApiClient.generateDeviceId = function () {
|
||||
|
||||
var keys = [];
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="editUserPage" data-role="page" class="page type-interior userProfilesPage publicUserPage">
|
||||
<div id="editUserPage" data-role="page" class="page type-interior userProfilesPage">
|
||||
|
||||
<div data-role="content">
|
||||
<div class="content-primary">
|
||||
|
Loading…
Reference in New Issue
Block a user