]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/standalone/videos/embed.ts
Add control bar option for peertube player
[github/Chocobozzz/PeerTube.git] / client / src / standalone / videos / embed.ts
index 9e4d879112fbfcf4d40c7a8ea0b6ed23d5a491b9..1fc8e229b2f79eaa9cc50236e30f66b925abdca5 100644 (file)
@@ -1,6 +1,6 @@
 import './embed.scss'
-import '../../assets/player/dock/peertube-dock-component'
-import '../../assets/player/dock/peertube-dock-plugin'
+import '../../assets/player/shared/dock/peertube-dock-component'
+import '../../assets/player/shared/dock/peertube-dock-plugin'
 import videojs from 'video.js'
 import { peertubeTranslate } from '../../../../shared/core-utils/i18n'
 import {
@@ -8,6 +8,7 @@ import {
   HttpStatusCode,
   LiveVideo,
   OAuth2ErrorCode,
+  PublicServerSetting,
   ResultList,
   UserRefreshToken,
   Video,
@@ -17,15 +18,14 @@ import {
   VideoPlaylistElement,
   VideoStreamingPlaylistType
 } from '../../../../shared/models'
-import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../assets/player'
-import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings'
+import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode, VideoJSCaption } from '../../assets/player'
 import { TranslationsManager } from '../../assets/player/translations-manager'
-import { isP2PEnabled } from '../../assets/player/utils'
 import { getBoolOrDefault } from '../../root-helpers/local-storage-utils'
 import { peertubeLocalStorage } from '../../root-helpers/peertube-web-storage'
-import { PluginsManager } from '../../root-helpers/plugins-manager'
+import { PluginInfo, PluginsManager } from '../../root-helpers/plugins-manager'
 import { UserLocalStorageKeys, UserTokens } from '../../root-helpers/users'
 import { objectToUrlEncoded } from '../../root-helpers/utils'
+import { isP2PEnabled } from '../../root-helpers/video'
 import { RegisterClientHelpers } from '../../types/register-client-option.model'
 import { PeerTubeEmbedApi } from './embed-api'
 
@@ -37,7 +37,10 @@ export class PeerTubeEmbed {
   api: PeerTubeEmbedApi = null
 
   autoplay: boolean
+
   controls: boolean
+  controlBar: boolean
+
   muted: boolean
   loop: boolean
   subtitle: string
@@ -99,6 +102,10 @@ export class PeerTubeEmbed {
     return window.location.origin + '/api/v1/videos/live/' + videoId
   }
 
+  getPluginUrl () {
+    return window.location.origin + '/api/v1/plugins'
+  }
+
   refreshFetch (url: string, options?: RequestInit) {
     return fetch(url, options)
       .then((res: Response) => {
@@ -291,7 +298,10 @@ export class PeerTubeEmbed {
       const params = new URL(window.location.toString()).searchParams
 
       this.autoplay = this.getParamToggle(params, 'autoplay', false)
+
       this.controls = this.getParamToggle(params, 'controls', true)
+      this.controlBar = this.getParamToggle(params, 'controlBar', true)
+
       this.muted = this.getParamToggle(params, 'muted', undefined)
       this.loop = this.getParamToggle(params, 'loop', false)
       this.title = this.getParamToggle(params, 'title', true)
@@ -535,7 +545,10 @@ export class PeerTubeEmbed {
       common: {
         // Autoplay in playlist mode
         autoplay: alreadyHadPlayer ? true : this.autoplay,
+
         controls: this.controls,
+        controlBar: this.controlBar,
+
         muted: this.muted,
         loop: this.loop,
 
@@ -761,8 +774,12 @@ export class PeerTubeEmbed {
     return document.getElementById('placeholder-preview')
   }
 
+  private getHeaderTokenValue () {
+    return `${this.userTokens.tokenType} ${this.userTokens.accessToken}`
+  }
+
   private setHeadersFromTokens () {
-    this.headers.set('Authorization', `${this.userTokens.tokenType} ${this.userTokens.accessToken}`)
+    this.headers.set('Authorization', this.getHeaderTokenValue())
   }
 
   private removeTokensFromHeaders () {
@@ -780,7 +797,7 @@ export class PeerTubeEmbed {
 
   private loadPlugins (translations?: { [ id: string ]: string }) {
     this.pluginsManager = new PluginsManager({
-      peertubeHelpersFactory: _ => this.buildPeerTubeHelpers(translations)
+      peertubeHelpersFactory: pluginInfo => this.buildPeerTubeHelpers(pluginInfo, translations)
     })
 
     this.pluginsManager.loadPluginsList(this.config)
@@ -788,7 +805,7 @@ export class PeerTubeEmbed {
     return this.pluginsManager.ensurePluginsAreLoaded('embed')
   }
 
-  private buildPeerTubeHelpers (translations?: { [ id: string ]: string }): RegisterClientHelpers {
+  private buildPeerTubeHelpers (pluginInfo: PluginInfo, translations?: { [ id: string ]: string }): RegisterClientHelpers {
     const unimplemented = () => {
       throw new Error('This helper is not implemented in embed.')
     }
@@ -798,10 +815,20 @@ export class PeerTubeEmbed {
       getBaseRouterRoute: unimplemented,
       getBasePluginClientPath: unimplemented,
 
-      getSettings: unimplemented,
+      getSettings: () => {
+        const url = this.getPluginUrl() + '/' + pluginInfo.plugin.npmName + '/public-settings'
 
-      isLoggedIn: unimplemented,
-      getAuthHeader: unimplemented,
+        return this.refreshFetch(url, { headers: this.headers })
+          .then(res => res.json())
+          .then((obj: PublicServerSetting) => obj.publicSettings)
+      },
+
+      isLoggedIn: () => !!this.userTokens,
+      getAuthHeader: () => {
+        if (!this.userTokens) return undefined
+
+        return { Authorization: this.getHeaderTokenValue() }
+      },
 
       notifier: {
         info: unimplemented,