aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/peertube-player-manager.ts
diff options
context:
space:
mode:
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>2021-05-15 06:30:24 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-06-14 13:35:48 +0200
commit72f611ca1549d711f8cbf5dd08a3f1562a32fabb (patch)
tree5c3bcbc52d1544c94a229842df7ae0cdf58c79b0 /client/src/assets/player/peertube-player-manager.ts
parent520bf885c5e75914f85196b8350970f51c3e1976 (diff)
downloadPeerTube-72f611ca1549d711f8cbf5dd08a3f1562a32fabb.tar.gz
PeerTube-72f611ca1549d711f8cbf5dd08a3f1562a32fabb.tar.zst
PeerTube-72f611ca1549d711f8cbf5dd08a3f1562a32fabb.zip
add client hook filter:videojs.options
closes #4086
Diffstat (limited to 'client/src/assets/player/peertube-player-manager.ts')
-rw-r--r--client/src/assets/player/peertube-player-manager.ts26
1 files changed, 16 insertions, 10 deletions
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'
22import './videojs-components/theater-button' 22import './videojs-components/theater-button'
23import './playlist/playlist-plugin' 23import './playlist/playlist-plugin'
24import videojs from 'video.js' 24import videojs from 'video.js'
25import { PluginsManager } from '@root-helpers/plugins-manager'
25import { isDefaultLocale } from '@shared/core-utils/i18n' 26import { isDefaultLocale } from '@shared/core-utils/i18n'
26import { VideoFile } from '@shared/models' 27import { VideoFile } from '@shared/models'
28import { copyToClipboard } from '../../root-helpers/utils'
27import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager' 29import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager'
28import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder' 30import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder'
29import { segmentValidatorFactory } from './p2p-media-loader/segment-validator' 31import { segmentValidatorFactory } from './p2p-media-loader/segment-validator'
@@ -37,8 +39,7 @@ import {
37 VideoJSPluginOptions 39 VideoJSPluginOptions
38} from './peertube-videojs-typings' 40} from './peertube-videojs-typings'
39import { TranslationsManager } from './translations-manager' 41import { TranslationsManager } from './translations-manager'
40import { buildVideoOrPlaylistEmbed, buildVideoLink, getRtcConfig, isSafari, isIOS } from './utils' 42import { buildVideoLink, buildVideoOrPlaylistEmbed, getRtcConfig, isIOS, isSafari } from './utils'
41import { copyToClipboard } from '../../root-helpers/utils'
42 43
43// Change 'Playback Rate' to 'Speed' (smaller for our settings menu) 44// Change 'Playback Rate' to 'Speed' (smaller for our settings menu)
44(videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed' 45(videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed'
@@ -116,21 +117,26 @@ export interface CommonOptions extends CustomizationOptions {
116} 117}
117 118
118export type PeertubePlayerManagerOptions = { 119export type PeertubePlayerManagerOptions = {
119 common: CommonOptions, 120 common: CommonOptions
120 webtorrent: WebtorrentOptions, 121 webtorrent: WebtorrentOptions
121 p2pMediaLoader?: P2PMediaLoaderOptions 122 p2pMediaLoader?: P2PMediaLoaderOptions
123
124 pluginsManager: PluginsManager
122} 125}
123 126
124export class PeertubePlayerManager { 127export class PeertubePlayerManager {
125 private static playerElementClassName: string 128 private static playerElementClassName: string
126 private static onPlayerChange: (player: videojs.Player) => void 129 private static onPlayerChange: (player: videojs.Player) => void
127 private static alreadyPlayed = false 130 private static alreadyPlayed = false
131 private static pluginsManager: PluginsManager
128 132
129 static initState () { 133 static initState () {
130 PeertubePlayerManager.alreadyPlayed = false 134 PeertubePlayerManager.alreadyPlayed = false
131 } 135 }
132 136
133 static async initialize (mode: PlayerMode, options: PeertubePlayerManagerOptions, onPlayerChange: (player: videojs.Player) => void) { 137 static async initialize (mode: PlayerMode, options: PeertubePlayerManagerOptions, onPlayerChange: (player: videojs.Player) => void) {
138 this.pluginsManager = options.pluginsManager
139
134 let p2pMediaLoader: any 140 let p2pMediaLoader: any
135 141
136 this.onPlayerChange = onPlayerChange 142 this.onPlayerChange = onPlayerChange
@@ -144,7 +150,7 @@ export class PeertubePlayerManager {
144 ]) 150 ])
145 } 151 }
146 152
147 const videojsOptions = this.getVideojsOptions(mode, options, p2pMediaLoader) 153 const videojsOptions = await this.getVideojsOptions(mode, options, p2pMediaLoader)
148 154
149 await TranslationsManager.loadLocaleInVideoJS(options.common.serverUrl, options.common.language, videojs) 155 await TranslationsManager.loadLocaleInVideoJS(options.common.serverUrl, options.common.language, videojs)
150 156
@@ -206,7 +212,7 @@ export class PeertubePlayerManager {
206 await import('./webtorrent/webtorrent-plugin') 212 await import('./webtorrent/webtorrent-plugin')
207 213
208 const mode = 'webtorrent' 214 const mode = 'webtorrent'
209 const videojsOptions = this.getVideojsOptions(mode, options) 215 const videojsOptions = await this.getVideojsOptions(mode, options)
210 216
211 const self = this 217 const self = this
212 videojs(newVideoElement, videojsOptions, function (this: videojs.Player) { 218 videojs(newVideoElement, videojsOptions, function (this: videojs.Player) {
@@ -218,16 +224,16 @@ export class PeertubePlayerManager {
218 }) 224 })
219 } 225 }
220 226
221 private static getVideojsOptions ( 227 private static async getVideojsOptions (
222 mode: PlayerMode, 228 mode: PlayerMode,
223 options: PeertubePlayerManagerOptions, 229 options: PeertubePlayerManagerOptions,
224 p2pMediaLoaderModule?: any 230 p2pMediaLoaderModule?: any
225 ): videojs.PlayerOptions { 231 ): Promise<videojs.PlayerOptions> {
226 const commonOptions = options.common 232 const commonOptions = options.common
227 const isHLS = mode === 'p2p-media-loader' 233 const isHLS = mode === 'p2p-media-loader'
228 234
229 let autoplay = this.getAutoPlayValue(commonOptions.autoplay) 235 let autoplay = this.getAutoPlayValue(commonOptions.autoplay)
230 let html5 = { 236 const html5 = {
231 preloadTextTracks: false 237 preloadTextTracks: false
232 } 238 }
233 239
@@ -306,7 +312,7 @@ export class PeertubePlayerManager {
306 Object.assign(videojsOptions, { language: commonOptions.language }) 312 Object.assign(videojsOptions, { language: commonOptions.language })
307 } 313 }
308 314
309 return videojsOptions 315 return this.pluginsManager.runHook('filter:internal.player.videojs.options.result', videojsOptions)
310 } 316 }
311 317
312 private static addP2PMediaLoaderOptions ( 318 private static addP2PMediaLoaderOptions (