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

Merge pull request #4401 from thornbill/add-plugin-types

Add plugin types
This commit is contained in:
Bill Thornton 2023-03-10 15:23:06 -05:00 committed by GitHub
commit 0cec50c6aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 53 additions and 21 deletions

View file

@ -8,6 +8,7 @@ import datetime from '../../scripts/datetime';
import globalize from '../../scripts/globalize';
import loading from '../loading/loading';
import skinManager from '../../scripts/themeManager';
import { PluginType } from '../../types/plugin.ts';
import Events from '../../utils/events.ts';
import '../../elements/emby-select/emby-select';
import '../../elements/emby-checkbox/emby-checkbox';
@ -35,7 +36,7 @@ import template from './displaySettings.template.html';
function loadScreensavers(context, userSettings) {
const selectScreensaver = context.querySelector('.selectScreensaver');
const options = pluginManager.ofType('screensaver').map(plugin => {
const options = pluginManager.ofType(PluginType.Screensaver).map(plugin => {
return {
name: plugin.name,
value: plugin.id

View file

@ -11,6 +11,7 @@ import { appHost } from '../apphost';
import Screenfull from 'screenfull';
import ServerConnections from '../ServerConnections';
import alert from '../alert';
import { PluginType } from '../../types/plugin.ts';
import { includesAny } from '../../utils/container.ts';
const UNLIMITED_ITEMS = -1;
@ -2265,7 +2266,7 @@ class PlaybackManager {
function runInterceptors(item, playOptions) {
return new Promise(function (resolve, reject) {
const interceptors = pluginManager.ofType('preplayintercept');
const interceptors = pluginManager.ofType(PluginType.PreplayIntercept);
interceptors.sort(function (a, b) {
return (a.order || 0) - (b.order || 0);
@ -3426,12 +3427,12 @@ class PlaybackManager {
}
Events.on(pluginManager, 'registered', function (e, plugin) {
if (plugin.type === 'mediaplayer') {
if (plugin.type === PluginType.MediaPlayer) {
initMediaPlayer(plugin);
}
});
pluginManager.ofType('mediaplayer').forEach(initMediaPlayer);
pluginManager.ofType(PluginType.MediaPlayer).forEach(initMediaPlayer);
function sendProgressUpdate(player, progressEventName, reportPlaylist) {
if (!player) {

View file

@ -1,10 +1,11 @@
/* eslint-disable indent */
import ServerConnections from '../../components/ServerConnections';
import { PluginType } from '../../types/plugin.ts';
class BackdropScreensaver {
constructor() {
this.name = 'Backdrop ScreenSaver';
this.type = 'screensaver';
this.type = PluginType.Screensaver;
this.id = 'backdropscreensaver';
this.supportsAnonymous = false;
}

View file

@ -9,6 +9,7 @@ import TableOfContents from './tableOfContents';
import dom from '../../scripts/dom';
import { translateHtml } from '../../scripts/globalize';
import * as userSettings from '../../scripts/settings/userSettings';
import { PluginType } from '../../types/plugin.ts';
import Events from '../../utils/events.ts';
import '../../elements/emby-button/paper-icon-button-light';
@ -19,7 +20,7 @@ import './style.scss';
export class BookPlayer {
constructor() {
this.name = 'Book Player';
this.type = 'mediaplayer';
this.type = PluginType.MediaPlayer;
this.id = 'bookplayer';
this.priority = 1;

View file

@ -5,6 +5,7 @@ import globalize from '../../scripts/globalize';
import castSenderApiLoader from './castSenderApi';
import ServerConnections from '../../components/ServerConnections';
import alert from '../../components/alert';
import { PluginType } from '../../types/plugin.ts';
import Events from '../../utils/events.ts';
// Based on https://github.com/googlecast/CastVideos-chrome/blob/master/CastVideos.js
@ -569,7 +570,7 @@ class ChromecastPlayer {
constructor() {
// playbackManager needs this
this.name = PlayerName;
this.type = 'mediaplayer';
this.type = PluginType.MediaPlayer;
this.id = 'chromecast';
this.isLocalPlayer = false;
this.lastPlayerData = {};

View file

@ -6,13 +6,14 @@ import keyboardnavigation from '../../scripts/keyboardNavigation';
import { appRouter } from '../../components/appRouter';
import ServerConnections from '../../components/ServerConnections';
import * as userSettings from '../../scripts/settings/userSettings';
import { PluginType } from '../../types/plugin.ts';
import './style.scss';
export class ComicsPlayer {
constructor() {
this.name = 'Comics Player';
this.type = 'mediaplayer';
this.type = PluginType.MediaPlayer;
this.id = 'comicsplayer';
this.priority = 1;
this.imageMap = new Map();

View file

@ -2,6 +2,7 @@ import globalize from '../../scripts/globalize';
import * as userSettings from '../../scripts/settings/userSettings';
import { appHost } from '../../components/apphost';
import alert from '../../components/alert';
import { PluginType } from '../../types/plugin.ts';
// TODO: Replace with date-fns
// https://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php
@ -46,7 +47,7 @@ function showIsoMessage() {
class ExpirementalPlaybackWarnings {
constructor() {
this.name = 'Experimental playback warnings';
this.type = 'preplayintercept';
this.type = PluginType.PreplayIntercept;
this.id = 'expirementalplaybackwarnings';
}

View file

@ -3,6 +3,7 @@ import { appHost } from '../../components/apphost';
import * as htmlMediaHelper from '../../components/htmlMediaHelper';
import profileBuilder from '../../scripts/browserDeviceProfile';
import { getIncludeCorsCredentials } from '../../scripts/settings/webSettings';
import { PluginType } from '../../types/plugin.ts';
import Events from '../../utils/events.ts';
function getDefaultProfile() {
@ -88,7 +89,7 @@ class HtmlAudioPlayer {
const self = this;
self.name = 'Html Audio Player';
self.type = 'mediaplayer';
self.type = PluginType.MediaPlayer;
self.id = 'htmlaudioplayer';
// Let any players created by plugins take priority

View file

@ -30,6 +30,7 @@ import ServerConnections from '../../components/ServerConnections';
import profileBuilder, { canPlaySecondaryAudio } from '../../scripts/browserDeviceProfile';
import { getIncludeCorsCredentials } from '../../scripts/settings/webSettings';
import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../components/backdrop/backdrop';
import { PluginType } from '../../types/plugin.ts';
import Events from '../../utils/events.ts';
import { includesAny } from '../../utils/container.ts';
import debounce from 'lodash-es/debounce';
@ -170,7 +171,7 @@ function tryRemoveElement(elem) {
/**
* @type {string}
*/
type = 'mediaplayer';
type = PluginType.MediaPlayer;
/**
* @type {string}
*/

View file

@ -1,8 +1,10 @@
import { PluginType } from '../../types/plugin.ts';
export default function () {
const self = this;
self.name = 'Logo ScreenSaver';
self.type = 'screensaver';
self.type = PluginType.Screensaver;
self.id = 'logoscreensaver';
self.supportsAnonymous = true;

View file

@ -4,6 +4,7 @@ import keyboardnavigation from '../../scripts/keyboardNavigation';
import dialogHelper from '../../components/dialogHelper/dialogHelper';
import dom from '../../scripts/dom';
import { appRouter } from '../../components/appRouter';
import { PluginType } from '../../types/plugin.ts';
import Events from '../../utils/events.ts';
import './style.scss';
@ -12,7 +13,7 @@ import '../../elements/emby-button/paper-icon-button-light';
export class PdfPlayer {
constructor() {
this.name = 'PDF Player';
this.type = 'mediaplayer';
this.type = PluginType.MediaPlayer;
this.id = 'pdfplayer';
this.priority = 1;

View file

@ -1,9 +1,10 @@
import ServerConnections from '../../components/ServerConnections';
import { PluginType } from '../../types/plugin.ts';
export default class PhotoPlayer {
constructor() {
this.name = 'Photo Player';
this.type = 'mediaplayer';
this.type = PluginType.MediaPlayer;
this.id = 'photoplayer';
this.priority = 1;
}

View file

@ -1,6 +1,7 @@
import globalize from '../../scripts/globalize';
import ServerConnections from '../../components/ServerConnections';
import alert from '../../components/alert';
import { PluginType } from '../../types/plugin.ts';
function showErrorMessage() {
return alert(globalize.translate('MessagePlayAccessRestricted'));
@ -9,7 +10,7 @@ function showErrorMessage() {
class PlayAccessValidation {
constructor() {
this.name = 'Playback validation';
this.type = 'preplayintercept';
this.type = PluginType.PreplayIntercept;
this.id = 'playaccessvalidation';
this.order = -2;
}

View file

@ -1,6 +1,7 @@
import { playbackManager } from '../../components/playback/playbackmanager';
import serverNotifications from '../../scripts/serverNotifications';
import ServerConnections from '../../components/ServerConnections';
import { PluginType } from '../../types/plugin.ts';
import Events from '../../utils/events.ts';
function getActivePlayerId() {
@ -181,7 +182,7 @@ class SessionPlayer {
const self = this;
this.name = 'Remote Control';
this.type = 'mediaplayer';
this.type = PluginType.MediaPlayer;
this.isLocalPlayer = false;
this.id = 'remoteplayer';

View file

@ -5,8 +5,9 @@ import SyncPlay from './core';
import SyncPlayNoActivePlayer from './ui/players/NoActivePlayer';
import SyncPlayHtmlVideoPlayer from './ui/players/HtmlVideoPlayer';
import SyncPlayHtmlAudioPlayer from './ui/players/HtmlAudioPlayer';
import { Plugin, PluginType } from '../../types/plugin';
class SyncPlayPlugin {
class SyncPlayPlugin implements Plugin {
name: string;
id: string;
type: string;
@ -17,7 +18,7 @@ class SyncPlayPlugin {
this.id = 'syncplay';
// NOTE: This should probably be a "mediaplayer" so the playback manager can handle playback logic, but
// SyncPlay needs refactored so it does not have an independent playback manager.
this.type = 'syncplay';
this.type = PluginType.SyncPlay;
this.priority = 1;
this.init();

View file

@ -2,6 +2,7 @@ import browser from '../../scripts/browser';
import { appRouter } from '../../components/appRouter';
import loading from '../../components/loading/loading';
import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../components/backdrop/backdrop';
import { PluginType } from '../../types/plugin.ts';
import Events from '../../utils/events.ts';
/* globals YT */
@ -197,7 +198,7 @@ function setCurrentSrc(instance, elem, options) {
class YoutubePlayer {
constructor() {
this.name = 'Youtube Player';
this.type = 'mediaplayer';
this.type = PluginType.MediaPlayer;
this.id = 'youtubeplayer';
// Let any players created by plugins take priority

View file

@ -16,6 +16,7 @@ import imageHelper from './imagehelper';
import { getMenuLinks } from '../scripts/settings/webSettings';
import Dashboard, { pageClassOn } from '../utils/dashboard';
import ServerConnections from '../components/ServerConnections';
import { PluginType } from '../types/plugin.ts';
import Events from '../utils/events.ts';
import { getParameterByName } from '../utils/url.ts';
@ -159,7 +160,7 @@ import '../styles/flexstyles.scss';
// Button is present
headerSyncButton
// SyncPlay plugin is loaded
&& pluginManager.plugins.filter(plugin => plugin.id === 'syncplay').length > 0
&& pluginManager.ofType(PluginType.SyncPlay).length > 0
// SyncPlay enabled for user
&& policy?.SyncPlayAccess !== 'None'
) {

View file

@ -3,6 +3,7 @@ import { pluginManager } from '../components/pluginManager';
import inputManager from './inputManager';
import * as userSettings from './settings/userSettings';
import ServerConnections from '../components/ServerConnections';
import { PluginType } from '../types/plugin.ts';
import Events from '../utils/events.ts';
import './screensavermanager.scss';
@ -34,7 +35,7 @@ function getScreensaverPlugin(isLoggedIn) {
option = isLoggedIn ? 'backdropscreensaver' : 'logoscreensaver';
}
const plugins = pluginManager.ofType('screensaver');
const plugins = pluginManager.ofType(PluginType.Screensaver);
for (const plugin of plugins) {
if (plugin.id === option) {

13
src/types/plugin.ts Normal file
View file

@ -0,0 +1,13 @@
export enum PluginType {
MediaPlayer = 'mediaplayer',
PreplayIntercept = 'preplayintercept',
Screensaver = 'screensaver',
SyncPlay = 'syncplay'
}
export interface Plugin {
name: string
id: string
type: PluginType | string
priority: number
}