From 72f611ca1549d711f8cbf5dd08a3f1562a32fabb Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Sat, 15 May 2021 06:30:24 +0200 Subject: add client hook filter:videojs.options closes #4086 --- client/src/standalone/videos/embed.ts | 53 +++++++++-------------------------- 1 file changed, 13 insertions(+), 40 deletions(-) (limited to 'client/src/standalone/videos/embed.ts') diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index a367feb8e..dc9727049 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -3,7 +3,6 @@ import videojs from 'video.js' import { peertubeTranslate } from '../../../../shared/core-utils/i18n' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { - ClientHookName, HTMLServerConfig, OAuth2ErrorCode, PluginType, @@ -19,7 +18,7 @@ import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings' import { TranslationsManager } from '../../assets/player/translations-manager' import { peertubeLocalStorage } from '../../root-helpers/peertube-web-storage' -import { Hooks, loadPlugin, runHook } from '../../root-helpers/plugins' +import { PluginsManager } from '../../root-helpers/plugins-manager' import { Tokens } from '../../root-helpers/users' import { objectToUrlEncoded } from '../../root-helpers/utils' import { RegisterClientHelpers } from '../../types/register-client-option.model' @@ -68,8 +67,7 @@ export class PeerTubeEmbed { private wrapperElement: HTMLElement - private peertubeHooks: Hooks = {} - private loadedScripts = new Set() + private pluginsManager: PluginsManager static async main () { const videoContainerId = 'video-wrapper' @@ -489,7 +487,7 @@ export class PeerTubeEmbed { this.PeertubePlayerManagerModulePromise ]) - await this.ensurePluginsAreLoaded(serverTranslations) + await this.loadPlugins(serverTranslations) const videoInfo: VideoDetails = videoInfoTmp @@ -560,7 +558,9 @@ export class PeerTubeEmbed { webtorrent: { videoFiles: videoInfo.files - } + }, + + pluginsManager: this.pluginsManager } if (this.mode === 'p2p-media-loader') { @@ -600,7 +600,7 @@ export class PeerTubeEmbed { }) } - this.runHook('action:embed.player.loaded', undefined, { player: this.player, videojs, video: videoInfo }) + this.pluginsManager.runHook('action:embed.player.loaded', undefined, { player: this.player, videojs, video: videoInfo }) } private async initCore () { @@ -740,37 +740,14 @@ export class PeerTubeEmbed { return window.location.pathname.split('/')[1] === 'video-playlists' } - private async ensurePluginsAreLoaded (translations?: { [ id: string ]: string }) { - if (this.config.plugin.registered.length === 0) return - - for (const plugin of this.config.plugin.registered) { - for (const key of Object.keys(plugin.clientScripts)) { - const clientScript = plugin.clientScripts[key] - - if (clientScript.scopes.includes('embed') === false) continue - - const script = `/plugins/${plugin.name}/${plugin.version}/client-scripts/${clientScript.script}` - - if (this.loadedScripts.has(script)) continue + private loadPlugins (translations?: { [ id: string ]: string }) { + this.pluginsManager = new PluginsManager({ + peertubeHelpersFactory: _ => this.buildPeerTubeHelpers(translations) + }) - const pluginInfo = { - plugin, - clientScript: { - script, - scopes: clientScript.scopes - }, - pluginType: PluginType.PLUGIN, - isTheme: false - } + this.pluginsManager.loadPluginsList(this.config) - await loadPlugin({ - hooks: this.peertubeHooks, - pluginInfo, - onSettingsScripts: () => undefined, - peertubeHelpersFactory: _ => this.buildPeerTubeHelpers(translations) - }) - } - } + return this.pluginsManager.ensurePluginsAreLoaded('embed') } private buildPeerTubeHelpers (translations?: { [ id: string ]: string }): RegisterClientHelpers { @@ -808,10 +785,6 @@ export class PeerTubeEmbed { } } } - - private runHook (hookName: ClientHookName, result?: T, params?: any): Promise { - return runHook(this.peertubeHooks, hookName, result, params) - } } PeerTubeEmbed.main() -- cgit v1.2.3