]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/peertube-player-manager.ts
Load embed api resolutions on init
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / peertube-player-manager.ts
index 689e70fb5751d8ac638cb90dc3f4888474c9054d..62dff82859320aa1dc8b6e041a850ee022d9922b 100644 (file)
@@ -4,6 +4,8 @@ import 'videojs-contextmenu-pt'
 import 'videojs-contrib-quality-levels'
 import './upnext/end-card'
 import './upnext/upnext-plugin'
+import './stats/stats-card'
+import './stats/stats-plugin'
 import './bezels/bezels-plugin'
 import './peertube-plugin'
 import './videojs-components/next-previous-video-button'
@@ -35,7 +37,7 @@ import {
   VideoJSPluginOptions
 } from './peertube-videojs-typings'
 import { TranslationsManager } from './translations-manager'
-import { buildVideoOrPlaylistEmbed, buildVideoLink, getRtcConfig, isSafari, isIOS, buildPlaylistLink } from './utils'
+import { buildVideoOrPlaylistEmbed, buildVideoLink, getRtcConfig, isSafari, isIOS } from './utils'
 import { copyToClipboard } from '../../root-helpers/utils'
 
 // Change 'Playback Rate' to 'Speed' (smaller for our settings menu)
@@ -87,8 +89,6 @@ export interface CommonOptions extends CustomizationOptions {
   hasPreviousVideo?: () => boolean
 
   playlist?: PlaylistPluginOptions
-  playlistEmbedUrl?: string
-  playlistEmbedTitle?: string
 
   videoDuration: number
   enableHotkeys: boolean
@@ -169,15 +169,14 @@ export class PeertubePlayerManager {
           PeertubePlayerManager.alreadyPlayed = true
         })
 
-        self.addContextMenu({
-          mode,
-          player,
-          videoEmbedUrl: options.common.embedUrl,
-          videoEmbedTitle: options.common.embedTitle,
-          playlist: options.common.playlist
-        })
+        self.addContextMenu(mode, player, options.common.embedUrl, options.common.embedTitle)
 
         player.bezels()
+        player.stats({
+          videoUUID: options.common.videoUUID,
+          videoIsLive: options.common.isLive,
+          mode
+        })
 
         return res(player)
       })
@@ -213,13 +212,7 @@ export class PeertubePlayerManager {
     videojs(newVideoElement, videojsOptions, function (this: videojs.Player) {
       const player = this
 
-      self.addContextMenu({
-        mode,
-        player,
-        videoEmbedUrl: options.common.embedUrl,
-        videoEmbedTitle: options.common.embedTitle,
-        playlist: options.common.playlist
-      })
+      self.addContextMenu(mode, player, options.common.embedUrl, options.common.embedTitle)
 
       PeertubePlayerManager.onPlayerChange(player)
     })
@@ -253,7 +246,7 @@ export class PeertubePlayerManager {
       }
     }
 
-    if (commonOptions.playlist?.createComponent === true) {
+    if (commonOptions.playlist) {
       plugins.playlist = commonOptions.playlist
     }
 
@@ -511,71 +504,37 @@ export class PeertubePlayerManager {
     return children
   }
 
-  private static addContextMenu (options: {
-    mode: PlayerMode
-    player: videojs.Player
-    videoEmbedUrl: string
-    videoEmbedTitle: string
-    playlist?: PlaylistPluginOptions
-  }) {
-    const { mode, player, videoEmbedUrl, videoEmbedTitle, playlist } = options
-
+  private static addContextMenu (mode: PlayerMode, player: videojs.Player, videoEmbedUrl: string, videoEmbedTitle: string) {
     const content = () => {
-      let items: { icon?: string, label: string, listener: Function }[] = []
-
-      if (!playlist) {
-        const isLoopEnabled = player.options_['loop']
-        items = items.concat([
-          {
-            icon: 'repeat',
-            label: player.localize('Play in loop') + (isLoopEnabled ? '<span class="vjs-icon-tick-white"></span>' : ''),
-            listener: function () {
-              player.options_['loop'] = !isLoopEnabled
-            }
-          },
-          {
-            label: player.localize('Copy the video URL'),
-            listener: function () {
-              copyToClipboard(buildVideoLink())
-            }
-          },
-          {
-            label: player.localize('Copy the video URL at the current time'),
-            listener: function (this: videojs.Player) {
-              copyToClipboard(buildVideoLink({ startTime: this.currentTime() }))
-            }
+      const isLoopEnabled = player.options_['loop']
+      const items = [
+        {
+          icon: 'repeat',
+          label: player.localize('Play in loop') + (isLoopEnabled ? '<span class="vjs-icon-tick-white"></span>' : ''),
+          listener: function () {
+            player.options_['loop'] = !isLoopEnabled
           }
-        ])
-      } else {
-        items = items.concat([
-          {
-            label: player.localize('Copy the playlist URL'),
-            listener: function () {
-              copyToClipboard(buildPlaylistLink())
-            }
-          },
-          {
-            label: player.localize('Copy the playlist URL at current video position'),
-            listener: function (this: videojs.Player) {
-              copyToClipboard(buildPlaylistLink({ playlistPosition: playlist.getCurrentPosition() }))
-            }
-          },
-          {
-            label: player.localize('Copy the playlist embed code'),
-            listener: function (this: videojs.Player) {
-              copyToClipboard(buildVideoOrPlaylistEmbed(playlist.embedUrl, playlist.embedTitle))
-            }
+        },
+        {
+          label: player.localize('Copy the video URL'),
+          listener: function () {
+            copyToClipboard(buildVideoLink())
+          }
+        },
+        {
+          label: player.localize('Copy the video URL at the current time'),
+          listener: function (this: videojs.Player) {
+            copyToClipboard(buildVideoLink({ startTime: this.currentTime() }))
+          }
+        },
+        {
+          icon: 'code',
+          label: player.localize('Copy embed code'),
+          listener: () => {
+            copyToClipboard(buildVideoOrPlaylistEmbed(videoEmbedUrl, videoEmbedTitle))
           }
-        ])
-      }
-
-      items = items.concat({
-        icon: 'code',
-        label: player.localize('Copy video embed code'),
-        listener: () => {
-          copyToClipboard(buildVideoOrPlaylistEmbed(videoEmbedUrl, videoEmbedTitle))
         }
-      })
+      ]
 
       if (mode === 'webtorrent') {
         items.push({
@@ -586,6 +545,14 @@ export class PeertubePlayerManager {
         })
       }
 
+      items.push({
+        icon: 'info',
+        label: player.localize('Stats for nerds'),
+        listener: () => {
+          player.stats().show()
+        }
+      })
+
       return items.map(i => ({
         ...i,
         label: `<span class="vjs-icon-${i.icon || 'link-2'}"></span>` + i.label