aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone
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/standalone
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/standalone')
-rw-r--r--client/src/standalone/videos/embed.ts53
1 files changed, 13 insertions, 40 deletions
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'
3import { peertubeTranslate } from '../../../../shared/core-utils/i18n' 3import { peertubeTranslate } from '../../../../shared/core-utils/i18n'
4import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 4import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5import { 5import {
6 ClientHookName,
7 HTMLServerConfig, 6 HTMLServerConfig,
8 OAuth2ErrorCode, 7 OAuth2ErrorCode,
9 PluginType, 8 PluginType,
@@ -19,7 +18,7 @@ import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from
19import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings' 18import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings'
20import { TranslationsManager } from '../../assets/player/translations-manager' 19import { TranslationsManager } from '../../assets/player/translations-manager'
21import { peertubeLocalStorage } from '../../root-helpers/peertube-web-storage' 20import { peertubeLocalStorage } from '../../root-helpers/peertube-web-storage'
22import { Hooks, loadPlugin, runHook } from '../../root-helpers/plugins' 21import { PluginsManager } from '../../root-helpers/plugins-manager'
23import { Tokens } from '../../root-helpers/users' 22import { Tokens } from '../../root-helpers/users'
24import { objectToUrlEncoded } from '../../root-helpers/utils' 23import { objectToUrlEncoded } from '../../root-helpers/utils'
25import { RegisterClientHelpers } from '../../types/register-client-option.model' 24import { RegisterClientHelpers } from '../../types/register-client-option.model'
@@ -68,8 +67,7 @@ export class PeerTubeEmbed {
68 67
69 private wrapperElement: HTMLElement 68 private wrapperElement: HTMLElement
70 69
71 private peertubeHooks: Hooks = {} 70 private pluginsManager: PluginsManager
72 private loadedScripts = new Set<string>()
73 71
74 static async main () { 72 static async main () {
75 const videoContainerId = 'video-wrapper' 73 const videoContainerId = 'video-wrapper'
@@ -489,7 +487,7 @@ export class PeerTubeEmbed {
489 this.PeertubePlayerManagerModulePromise 487 this.PeertubePlayerManagerModulePromise
490 ]) 488 ])
491 489
492 await this.ensurePluginsAreLoaded(serverTranslations) 490 await this.loadPlugins(serverTranslations)
493 491
494 const videoInfo: VideoDetails = videoInfoTmp 492 const videoInfo: VideoDetails = videoInfoTmp
495 493
@@ -560,7 +558,9 @@ export class PeerTubeEmbed {
560 558
561 webtorrent: { 559 webtorrent: {
562 videoFiles: videoInfo.files 560 videoFiles: videoInfo.files
563 } 561 },
562
563 pluginsManager: this.pluginsManager
564 } 564 }
565 565
566 if (this.mode === 'p2p-media-loader') { 566 if (this.mode === 'p2p-media-loader') {
@@ -600,7 +600,7 @@ export class PeerTubeEmbed {
600 }) 600 })
601 } 601 }
602 602
603 this.runHook('action:embed.player.loaded', undefined, { player: this.player, videojs, video: videoInfo }) 603 this.pluginsManager.runHook('action:embed.player.loaded', undefined, { player: this.player, videojs, video: videoInfo })
604 } 604 }
605 605
606 private async initCore () { 606 private async initCore () {
@@ -740,37 +740,14 @@ export class PeerTubeEmbed {
740 return window.location.pathname.split('/')[1] === 'video-playlists' 740 return window.location.pathname.split('/')[1] === 'video-playlists'
741 } 741 }
742 742
743 private async ensurePluginsAreLoaded (translations?: { [ id: string ]: string }) { 743 private loadPlugins (translations?: { [ id: string ]: string }) {
744 if (this.config.plugin.registered.length === 0) return 744 this.pluginsManager = new PluginsManager({
745 745 peertubeHelpersFactory: _ => this.buildPeerTubeHelpers(translations)
746 for (const plugin of this.config.plugin.registered) { 746 })
747 for (const key of Object.keys(plugin.clientScripts)) {
748 const clientScript = plugin.clientScripts[key]
749
750 if (clientScript.scopes.includes('embed') === false) continue
751
752 const script = `/plugins/${plugin.name}/${plugin.version}/client-scripts/${clientScript.script}`
753
754 if (this.loadedScripts.has(script)) continue
755 747
756 const pluginInfo = { 748 this.pluginsManager.loadPluginsList(this.config)
757 plugin,
758 clientScript: {
759 script,
760 scopes: clientScript.scopes
761 },
762 pluginType: PluginType.PLUGIN,
763 isTheme: false
764 }
765 749
766 await loadPlugin({ 750 return this.pluginsManager.ensurePluginsAreLoaded('embed')
767 hooks: this.peertubeHooks,
768 pluginInfo,
769 onSettingsScripts: () => undefined,
770 peertubeHelpersFactory: _ => this.buildPeerTubeHelpers(translations)
771 })
772 }
773 }
774 } 751 }
775 752
776 private buildPeerTubeHelpers (translations?: { [ id: string ]: string }): RegisterClientHelpers { 753 private buildPeerTubeHelpers (translations?: { [ id: string ]: string }): RegisterClientHelpers {
@@ -808,10 +785,6 @@ export class PeerTubeEmbed {
808 } 785 }
809 } 786 }
810 } 787 }
811
812 private runHook <T> (hookName: ClientHookName, result?: T, params?: any): Promise<T> {
813 return runHook(this.peertubeHooks, hookName, result, params)
814 }
815} 788}
816 789
817PeerTubeEmbed.main() 790PeerTubeEmbed.main()