aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/standalone')
-rw-r--r--client/src/standalone/videos/embed.ts81
1 files changed, 78 insertions, 3 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index adba32a31..fe65794f7 100644
--- a/client/src/standalone/videos/embed.ts
+++ b/client/src/standalone/videos/embed.ts
@@ -1,7 +1,5 @@
1import './embed.scss' 1import './embed.scss'
2import videojs from 'video.js' 2import videojs from 'video.js'
3import { objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index'
4import { Tokens } from '@root-helpers/users'
5import { peertubeTranslate } from '../../../../shared/core-utils/i18n' 3import { peertubeTranslate } from '../../../../shared/core-utils/i18n'
6import { 4import {
7 ResultList, 5 ResultList,
@@ -11,12 +9,19 @@ import {
11 VideoDetails, 9 VideoDetails,
12 VideoPlaylist, 10 VideoPlaylist,
13 VideoPlaylistElement, 11 VideoPlaylistElement,
14 VideoStreamingPlaylistType 12 VideoStreamingPlaylistType,
13 PluginType,
14 ClientHookName
15} from '../../../../shared/models' 15} from '../../../../shared/models'
16import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../assets/player/peertube-player-manager' 16import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../assets/player/peertube-player-manager'
17import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings' 17import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings'
18import { TranslationsManager } from '../../assets/player/translations-manager' 18import { TranslationsManager } from '../../assets/player/translations-manager'
19import { Hooks, loadPlugin, runHook } from '../../root-helpers/plugins'
20import { Tokens } from '../../root-helpers/users'
21import { peertubeLocalStorage } from '../../root-helpers/peertube-web-storage'
22import { objectToUrlEncoded } from '../../root-helpers/utils'
19import { PeerTubeEmbedApi } from './embed-api' 23import { PeerTubeEmbedApi } from './embed-api'
24import { RegisterClientHelpers } from '../../types/register-client-option.model'
20 25
21type Translations = { [ id: string ]: string } 26type Translations = { [ id: string ]: string }
22 27
@@ -60,6 +65,9 @@ export class PeerTubeEmbed {
60 65
61 private wrapperElement: HTMLElement 66 private wrapperElement: HTMLElement
62 67
68 private peertubeHooks: Hooks = {}
69 private loadedScripts = new Set<string>()
70
63 static async main () { 71 static async main () {
64 const videoContainerId = 'video-wrapper' 72 const videoContainerId = 'video-wrapper'
65 const embed = new PeerTubeEmbed(videoContainerId) 73 const embed = new PeerTubeEmbed(videoContainerId)
@@ -473,6 +481,8 @@ export class PeerTubeEmbed {
473 this.PeertubePlayerManagerModulePromise 481 this.PeertubePlayerManagerModulePromise
474 ]) 482 ])
475 483
484 await this.ensurePluginsAreLoaded(config, serverTranslations)
485
476 const videoInfo: VideoDetails = videoInfoTmp 486 const videoInfo: VideoDetails = videoInfoTmp
477 487
478 const PeertubePlayerManager = PeertubePlayerManagerModule.PeertubePlayerManager 488 const PeertubePlayerManager = PeertubePlayerManagerModule.PeertubePlayerManager
@@ -577,6 +587,8 @@ export class PeerTubeEmbed {
577 this.playNextVideo() 587 this.playNextVideo()
578 }) 588 })
579 } 589 }
590
591 this.runHook('action:embed.player.loaded', undefined, { player: this.player })
580 } 592 }
581 593
582 private async initCore () { 594 private async initCore () {
@@ -714,6 +726,69 @@ export class PeerTubeEmbed {
714 private isPlaylistEmbed () { 726 private isPlaylistEmbed () {
715 return window.location.pathname.split('/')[1] === 'video-playlists' 727 return window.location.pathname.split('/')[1] === 'video-playlists'
716 } 728 }
729
730 private async ensurePluginsAreLoaded (config: ServerConfig, translations?: { [ id: string ]: string }) {
731 if (config.plugin.registered.length === 0) return
732
733 for (const plugin of config.plugin.registered) {
734 for (const key of Object.keys(plugin.clientScripts)) {
735 const clientScript = plugin.clientScripts[key]
736
737 if (clientScript.scopes.includes('embed') === false) continue
738
739 const script = `/plugins/${plugin.name}/${plugin.version}/client-scripts/${clientScript.script}`
740
741 if (this.loadedScripts.has(script)) continue
742
743 const pluginInfo = {
744 plugin,
745 clientScript: {
746 script,
747 scopes: clientScript.scopes
748 },
749 pluginType: PluginType.PLUGIN,
750 isTheme: false
751 }
752
753 await loadPlugin(this.peertubeHooks, pluginInfo, _ => this.buildPeerTubeHelpers(translations))
754 }
755 }
756 }
757
758 private buildPeerTubeHelpers (translations?: { [ id: string ]: string }): RegisterClientHelpers {
759 function unimplemented (): any {
760 throw new Error('This helper is not implemented in embed.')
761 }
762
763 return {
764 getBaseStaticRoute: unimplemented,
765
766 getSettings: unimplemented,
767
768 isLoggedIn: unimplemented,
769
770 notifier: {
771 info: unimplemented,
772 error: unimplemented,
773 success: unimplemented
774 },
775
776 showModal: unimplemented,
777
778 markdownRenderer: {
779 textMarkdownToHTML: unimplemented,
780 enhancedMarkdownToHTML: unimplemented
781 },
782
783 translate: (value: string) => {
784 return Promise.resolve(peertubeTranslate(value, translations))
785 }
786 }
787 }
788
789 private runHook <T> (hookName: ClientHookName, result?: T, params?: any): Promise<T> {
790 return runHook(this.peertubeHooks, hookName, result, params)
791 }
717} 792}
718 793
719PeerTubeEmbed.main() 794PeerTubeEmbed.main()