1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

connect updates

This commit is contained in:
Luke Pulverenti 2014-10-25 14:32:58 -04:00
parent 90082ed4bc
commit 83d7b945d7
25 changed files with 686 additions and 312 deletions

View file

@ -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);

View file

@ -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'),

View file

@ -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>';

View file

@ -438,7 +438,7 @@
loadlibraryButtons: loadlibraryButtons
};
})(jQuery, document, ApiClient);
})(jQuery, document);
(function ($, document) {
@ -595,4 +595,4 @@
});
})(jQuery, document);
})(jQuery, document);

View file

@ -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);

View file

@ -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);

View file

@ -335,4 +335,4 @@
programs = null;
});
})(jQuery, document, ApiClient);
})(jQuery, document);

View file

@ -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) {

View file

@ -27,7 +27,7 @@
var targets = [{
name: 'My Browser',
id: ApiClient.deviceId(),
id: ConnectionManager.deviceId(),
playerName: self.name,
playableMediaTypes: ['Audio', 'Video'],
isLocalPlayer: true,

View file

@ -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);

View file

@ -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>";

View file

@ -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);

View 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;
}
};
})();

View file

@ -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();
}
});

View file

@ -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>';