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 --- .../src/assets/player/peertube-player-manager.ts | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'client/src/assets/player/peertube-player-manager.ts') diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index 62dff8285..814253188 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts @@ -22,8 +22,10 @@ import './videojs-components/settings-panel-child' import './videojs-components/theater-button' import './playlist/playlist-plugin' import videojs from 'video.js' +import { PluginsManager } from '@root-helpers/plugins-manager' import { isDefaultLocale } from '@shared/core-utils/i18n' import { VideoFile } from '@shared/models' +import { copyToClipboard } from '../../root-helpers/utils' import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager' import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder' import { segmentValidatorFactory } from './p2p-media-loader/segment-validator' @@ -37,8 +39,7 @@ import { VideoJSPluginOptions } from './peertube-videojs-typings' import { TranslationsManager } from './translations-manager' -import { buildVideoOrPlaylistEmbed, buildVideoLink, getRtcConfig, isSafari, isIOS } from './utils' -import { copyToClipboard } from '../../root-helpers/utils' +import { buildVideoLink, buildVideoOrPlaylistEmbed, getRtcConfig, isIOS, isSafari } from './utils' // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) (videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed' @@ -116,21 +117,26 @@ export interface CommonOptions extends CustomizationOptions { } export type PeertubePlayerManagerOptions = { - common: CommonOptions, - webtorrent: WebtorrentOptions, + common: CommonOptions + webtorrent: WebtorrentOptions p2pMediaLoader?: P2PMediaLoaderOptions + + pluginsManager: PluginsManager } export class PeertubePlayerManager { private static playerElementClassName: string private static onPlayerChange: (player: videojs.Player) => void private static alreadyPlayed = false + private static pluginsManager: PluginsManager static initState () { PeertubePlayerManager.alreadyPlayed = false } static async initialize (mode: PlayerMode, options: PeertubePlayerManagerOptions, onPlayerChange: (player: videojs.Player) => void) { + this.pluginsManager = options.pluginsManager + let p2pMediaLoader: any this.onPlayerChange = onPlayerChange @@ -144,7 +150,7 @@ export class PeertubePlayerManager { ]) } - const videojsOptions = this.getVideojsOptions(mode, options, p2pMediaLoader) + const videojsOptions = await this.getVideojsOptions(mode, options, p2pMediaLoader) await TranslationsManager.loadLocaleInVideoJS(options.common.serverUrl, options.common.language, videojs) @@ -206,7 +212,7 @@ export class PeertubePlayerManager { await import('./webtorrent/webtorrent-plugin') const mode = 'webtorrent' - const videojsOptions = this.getVideojsOptions(mode, options) + const videojsOptions = await this.getVideojsOptions(mode, options) const self = this videojs(newVideoElement, videojsOptions, function (this: videojs.Player) { @@ -218,16 +224,16 @@ export class PeertubePlayerManager { }) } - private static getVideojsOptions ( + private static async getVideojsOptions ( mode: PlayerMode, options: PeertubePlayerManagerOptions, p2pMediaLoaderModule?: any - ): videojs.PlayerOptions { + ): Promise { const commonOptions = options.common const isHLS = mode === 'p2p-media-loader' let autoplay = this.getAutoPlayValue(commonOptions.autoplay) - let html5 = { + const html5 = { preloadTextTracks: false } @@ -306,7 +312,7 @@ export class PeertubePlayerManager { Object.assign(videojsOptions, { language: commonOptions.language }) } - return videojsOptions + return this.pluginsManager.runHook('filter:internal.player.videojs.options.result', videojsOptions) } private static addP2PMediaLoaderOptions ( -- cgit v1.2.3