mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
extracted connectionManager from site.js
new module ServerConnections for ConnectionManager all code adapted to this new module removed Events and ConnectionManager from eslintrc
This commit is contained in:
parent
923d53bb71
commit
5071aedcea
81 changed files with 446 additions and 397 deletions
|
@ -1,13 +1,14 @@
|
|||
import * as userSettings from './settings/userSettings';
|
||||
import * as webSettings from './settings/webSettings';
|
||||
import skinManager from './themeManager';
|
||||
import { ConnectionManager, Events } from 'jellyfin-apiclient';
|
||||
import { Events } from 'jellyfin-apiclient';
|
||||
import ServerConnections from '../components/ServerConnections';
|
||||
|
||||
// set the default theme when loading
|
||||
skinManager.setTheme(userSettings.theme());
|
||||
|
||||
// set the saved theme once a user authenticates
|
||||
Events.on(ConnectionManager, 'localusersignedin', function (e, user) {
|
||||
Events.on(ServerConnections, 'localusersignedin', function (e, user) {
|
||||
skinManager.setTheme(userSettings.theme());
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import AppInfo from '../components/AppInfo';
|
||||
import ServerConnections from '../components/ServerConnections';
|
||||
|
||||
export function getCurrentUser() {
|
||||
return window.ApiClient.getCurrentUser(false);
|
||||
|
@ -44,12 +45,11 @@ export function getCurrentUserId() {
|
|||
}
|
||||
|
||||
export function onServerChanged(userId, accessToken, apiClient) {
|
||||
apiClient = apiClient || window.ApiClient;
|
||||
window.ApiClient = apiClient;
|
||||
ServerConnections.setLocalApiClient(apiClient);
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
window.connectionManager.logout().then(function () {
|
||||
ServerConnections.logout().then(function () {
|
||||
let loginPage;
|
||||
|
||||
if (AppInfo.isNativeApp) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
import { ConnectionManager } from 'jellyfin-apiclient';
|
||||
import confirm from '../components/confirm/confirm';
|
||||
import { appRouter } from '../components/appRouter';
|
||||
import globalize from './globalize';
|
||||
import ServerConnections from '../components/ServerConnections';
|
||||
|
||||
function alertText(options) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
@ -16,7 +16,7 @@ export function deleteItem(options) {
|
|||
const item = options.item;
|
||||
const parentId = item.SeasonId || item.SeriesId || item.ParentId;
|
||||
|
||||
const apiClient = ConnectionManager.getApiClient(item.ServerId);
|
||||
const apiClient = ServerConnections.getApiClient(item.ServerId);
|
||||
|
||||
return confirm({
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { ConnectionManager } from 'jellyfin-apiclient';
|
||||
import listView from '../components/listview/listview';
|
||||
import cardBuilder from '../components/cardbuilder/cardBuilder';
|
||||
import imageLoader from '../components/images/imageLoader';
|
||||
import globalize from './globalize';
|
||||
import '../elements/emby-itemscontainer/emby-itemscontainer';
|
||||
import '../elements/emby-button/emby-button';
|
||||
import ServerConnections from '../components/ServerConnections';
|
||||
|
||||
function renderItems(page, item) {
|
||||
const sections = [];
|
||||
|
@ -358,7 +358,7 @@ function getItemsFunction(options, item) {
|
|||
query.Fields += ',' + fields;
|
||||
}
|
||||
|
||||
const apiClient = ConnectionManager.getApiClient(item.ServerId);
|
||||
const apiClient = ServerConnections.getApiClient(item.ServerId);
|
||||
|
||||
if (query.IncludeItemTypes === 'MusicArtist') {
|
||||
query.IncludeItemTypes = null;
|
||||
|
|
|
@ -16,6 +16,7 @@ import 'material-design-icons-iconfont';
|
|||
import '../assets/css/scrollstyles.css';
|
||||
import '../assets/css/flexstyles.css';
|
||||
import Dashboard from './clientUtils';
|
||||
import ServerConnections from '../components/ServerConnections';
|
||||
|
||||
/* eslint-disable indent */
|
||||
|
||||
|
@ -61,10 +62,10 @@ import Dashboard from './clientUtils';
|
|||
|
||||
function getCurrentApiClient() {
|
||||
if (currentUser && currentUser.localUser) {
|
||||
return window.ConnectionManager.getApiClient(currentUser.localUser.ServerId);
|
||||
return ServerConnections.getApiClient(currentUser.localUser.ServerId);
|
||||
}
|
||||
|
||||
return window.ConnectionManager.currentApiClient();
|
||||
return ServerConnections.currentApiClient();
|
||||
}
|
||||
|
||||
function lazyLoadViewMenuBarImages() {
|
||||
|
@ -775,7 +776,7 @@ import Dashboard from './clientUtils';
|
|||
}
|
||||
|
||||
if (requiresUserRefresh) {
|
||||
window.ConnectionManager.user(getCurrentApiClient()).then(updateUserInHeader);
|
||||
ServerConnections.user(getCurrentApiClient()).then(updateUserInHeader);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -813,7 +814,7 @@ import Dashboard from './clientUtils';
|
|||
if (user) {
|
||||
Promise.resolve(user);
|
||||
} else {
|
||||
window.ConnectionManager.user(getCurrentApiClient()).then(function (user) {
|
||||
ServerConnections.user(getCurrentApiClient()).then(function (user) {
|
||||
refreshLibraryInfoInDrawer(user);
|
||||
updateLibraryMenu(user.localUser);
|
||||
});
|
||||
|
@ -979,8 +980,8 @@ import Dashboard from './clientUtils';
|
|||
|
||||
renderHeader();
|
||||
|
||||
Events.on(window.ConnectionManager, 'localusersignedin', function (e, user) {
|
||||
const currentApiClient = window.ConnectionManager.getApiClient(user.ServerId);
|
||||
Events.on(ServerConnections, 'localusersignedin', function (e, user) {
|
||||
const currentApiClient = ServerConnections.getApiClient(user.ServerId);
|
||||
|
||||
currentDrawerType = null;
|
||||
currentUser = {
|
||||
|
@ -989,13 +990,13 @@ import Dashboard from './clientUtils';
|
|||
|
||||
loadNavDrawer();
|
||||
|
||||
window.ConnectionManager.user(currentApiClient).then(function (user) {
|
||||
ServerConnections.user(currentApiClient).then(function (user) {
|
||||
currentUser = user;
|
||||
updateUserInHeader(user);
|
||||
});
|
||||
});
|
||||
|
||||
Events.on(window.ConnectionManager, 'localusersignedout', function () {
|
||||
Events.on(ServerConnections, 'localusersignedout', function () {
|
||||
currentUser = {};
|
||||
updateUserInHeader();
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ import { Events } from 'jellyfin-apiclient';
|
|||
import inputManager from '../scripts/inputManager';
|
||||
import focusManager from '../components/focusManager';
|
||||
import { appRouter } from '../components/appRouter';
|
||||
import ServerConnections from '../components/ServerConnections';
|
||||
|
||||
const serverNotifications = {};
|
||||
|
||||
|
@ -207,8 +208,8 @@ function bindEvents(apiClient) {
|
|||
Events.on(apiClient, 'message', onMessageReceived);
|
||||
}
|
||||
|
||||
window.ConnectionManager.getApiClients().forEach(bindEvents);
|
||||
Events.on(window.ConnectionManager, 'apiclientcreated', function (e, newApiClient) {
|
||||
ServerConnections.getApiClients().forEach(bindEvents);
|
||||
Events.on(ServerConnections, 'apiclientcreated', function (e, newApiClient) {
|
||||
bindEvents(newApiClient);
|
||||
});
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ import 'resize-observer-polyfill';
|
|||
import 'jellyfin-noto';
|
||||
import '../assets/css/site.css';
|
||||
import AppInfo from '../components/AppInfo';
|
||||
import Dashboard from './clientUtils';
|
||||
import { Events } from 'jellyfin-apiclient';
|
||||
import ServerConnections from '../components/ServerConnections';
|
||||
|
||||
// TODO: Move this elsewhere
|
||||
window.getWindowLocationSearch = function(win) {
|
||||
|
@ -69,109 +70,35 @@ if (self.appMode === 'cordova' || self.appMode === 'android' || self.appMode ===
|
|||
Object.freeze(AppInfo);
|
||||
|
||||
function initClient() {
|
||||
function bindConnectionManagerEvents(connectionManager, events, userSettings) {
|
||||
window.Events = events;
|
||||
function init() {
|
||||
ServerConnections.initApiClient();
|
||||
|
||||
window.connectionManager.currentApiClient = function () {
|
||||
if (!localApiClient) {
|
||||
const server = window.connectionManager.getLastUsedServer();
|
||||
console.debug('initAfterDependencies promises resolved');
|
||||
|
||||
if (server) {
|
||||
localApiClient = window.connectionManager.getApiClient(server.Id);
|
||||
}
|
||||
}
|
||||
|
||||
return localApiClient;
|
||||
};
|
||||
|
||||
window.connectionManager.onLocalUserSignedIn = function (user) {
|
||||
localApiClient = window.connectionManager.getApiClient(user.ServerId);
|
||||
window.ApiClient = localApiClient;
|
||||
return userSettings.setUserInfo(user.Id, localApiClient);
|
||||
};
|
||||
|
||||
events.on(connectionManager, 'localusersignedout', function () {
|
||||
userSettings.setUserInfo(null, null);
|
||||
});
|
||||
}
|
||||
|
||||
function createConnectionManager() {
|
||||
return Promise.all([
|
||||
import('jellyfin-apiclient'),
|
||||
import('../components/apphost'),
|
||||
import('./settings/userSettings')
|
||||
Promise.all([
|
||||
import('./globalize'),
|
||||
import('./browser')
|
||||
])
|
||||
.then(([{ ConnectionManager, Credentials, Events }, { appHost }, userSettings]) => {
|
||||
var credentialProviderInstance = new Credentials();
|
||||
var promises = [appHost.init()];
|
||||
|
||||
return Promise.all(promises).then(function (responses) {
|
||||
const capabilities = Dashboard.capabilities(appHost);
|
||||
|
||||
window.ConnectionManager = new ConnectionManager(credentialProviderInstance, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId(), capabilities);
|
||||
|
||||
bindConnectionManagerEvents(window.ConnectionManager, Events, userSettings);
|
||||
|
||||
if (!AppInfo.isNativeApp) {
|
||||
console.debug('loading ApiClient singleton');
|
||||
|
||||
return Promise.all([
|
||||
import('jellyfin-apiclient')
|
||||
])
|
||||
.then(([{ ApiClient }]) => {
|
||||
console.debug('creating ApiClient singleton');
|
||||
|
||||
var apiClient = new ApiClient(Dashboard.serverAddress(), appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId());
|
||||
|
||||
apiClient.enableAutomaticNetworking = false;
|
||||
apiClient.manualAddressOnly = true;
|
||||
|
||||
window.ConnectionManager.addApiClient(apiClient);
|
||||
|
||||
window.ApiClient = apiClient;
|
||||
localApiClient = apiClient;
|
||||
|
||||
console.debug('loaded ApiClient singleton');
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
.then(([globalize, browser]) => {
|
||||
window.Globalize = globalize;
|
||||
loadCoreDictionary(globalize).then(function () {
|
||||
onGlobalizeInit(browser, globalize);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
import('./clientUtils')
|
||||
.then(function () {
|
||||
createConnectionManager().then(function () {
|
||||
console.debug('initAfterDependencies promises resolved');
|
||||
|
||||
Promise.all([
|
||||
import('./globalize'),
|
||||
import('./browser')
|
||||
])
|
||||
.then(([globalize, {default: browser}]) => {
|
||||
window.Globalize = globalize;
|
||||
loadCoreDictionary(globalize).then(function () {
|
||||
onGlobalizeInit(browser, globalize);
|
||||
});
|
||||
});
|
||||
import('./keyboardNavigation')
|
||||
.then((keyboardnavigation) => {
|
||||
keyboardnavigation.enable();
|
||||
});
|
||||
import('./mouseManager');
|
||||
import('../components/autoFocuser').then((autoFocuser) => {
|
||||
autoFocuser.enable();
|
||||
});
|
||||
Promise.all([
|
||||
import('./globalize'),
|
||||
import('jellyfin-apiclient')
|
||||
])
|
||||
.then(([ globalize, { ConnectionManager, events } ]) => {
|
||||
Events.on(ConnectionManager, 'localusersignedin', globalize.updateCurrentCulture);
|
||||
});
|
||||
});
|
||||
import('./keyboardNavigation')
|
||||
.then((keyboardnavigation) => {
|
||||
keyboardnavigation.enable();
|
||||
});
|
||||
import('./mouseManager');
|
||||
import('../components/autoFocuser').then((autoFocuser) => {
|
||||
autoFocuser.enable();
|
||||
});
|
||||
Promise.all([
|
||||
import('./globalize'),
|
||||
import('jellyfin-apiclient')
|
||||
])
|
||||
.then(([ globalize, { ConnectionManager } ]) => {
|
||||
Events.on(ConnectionManager, 'localusersignedin', globalize.updateCurrentCulture);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -326,7 +253,7 @@ function initClient() {
|
|||
|
||||
import('../components/playback/playerSelectionMenu');
|
||||
|
||||
const apiClient = window.ConnectionManager && window.ConnectionManager.currentApiClient();
|
||||
const apiClient = ServerConnections.currentApiClient();
|
||||
if (apiClient) {
|
||||
fetch(apiClient.getUrl('Branding/Css'))
|
||||
.then(function(response) {
|
||||
|
@ -368,7 +295,7 @@ function initClient() {
|
|||
/* eslint-enable compat/compat */
|
||||
}
|
||||
|
||||
let localApiClient;
|
||||
//var localApiClient;
|
||||
|
||||
init();
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
|
||||
import { ConnectionManager, Events } from 'jellyfin-apiclient';
|
||||
import { Events } from 'jellyfin-apiclient';
|
||||
import serverNotifications from '../scripts/serverNotifications';
|
||||
import globalize from '../scripts/globalize';
|
||||
import '../elements/emby-button/emby-button';
|
||||
import ServerConnections from '../components/ServerConnections';
|
||||
|
||||
export default function (options) {
|
||||
function pollTasks() {
|
||||
ConnectionManager.getApiClient(serverId).getScheduledTasks({
|
||||
ServerConnections.getApiClient(serverId).getScheduledTasks({
|
||||
IsEnabled: true
|
||||
}).then(updateTasks);
|
||||
}
|
||||
|
@ -63,7 +64,7 @@ export default function (options) {
|
|||
}
|
||||
|
||||
function onScheduledTaskMessageConfirmed(id) {
|
||||
ConnectionManager.getApiClient(serverId).startScheduledTask(id).then(pollTasks);
|
||||
ServerConnections.getApiClient(serverId).startScheduledTask(id).then(pollTasks);
|
||||
}
|
||||
|
||||
function onButtonClick() {
|
||||
|
@ -81,13 +82,13 @@ export default function (options) {
|
|||
const serverId = ApiClient.serverId();
|
||||
|
||||
function onPollIntervalFired() {
|
||||
if (!ConnectionManager.getApiClient(serverId).isMessageChannelOpen()) {
|
||||
if (!ServerConnections.getApiClient(serverId).isMessageChannelOpen()) {
|
||||
pollTasks();
|
||||
}
|
||||
}
|
||||
|
||||
function startInterval() {
|
||||
const apiClient = ConnectionManager.getApiClient(serverId);
|
||||
const apiClient = ServerConnections.getApiClient(serverId);
|
||||
|
||||
if (pollInterval) {
|
||||
clearInterval(pollInterval);
|
||||
|
@ -97,7 +98,7 @@ export default function (options) {
|
|||
}
|
||||
|
||||
function stopInterval() {
|
||||
ConnectionManager.getApiClient(serverId).sendMessage('ScheduledTasksInfoStop');
|
||||
ServerConnections.getApiClient(serverId).sendMessage('ScheduledTasksInfoStop');
|
||||
|
||||
if (pollInterval) {
|
||||
clearInterval(pollInterval);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue