VideoJSPluginOptions
} from './peertube-videojs-typings'
import { TranslationsManager } from './translations-manager'
-import { buildVideoOrPlaylistEmbed, buildVideoLink, getRtcConfig, isSafari, isIOS } from './utils'
+import { buildVideoOrPlaylistEmbed, buildVideoLink, getRtcConfig, isSafari, isIOS, buildPlaylistLink } from './utils'
import { copyToClipboard } from '../../root-helpers/utils'
// Change 'Playback Rate' to 'Speed' (smaller for our settings menu)
hasPreviousVideo?: () => boolean
playlist?: PlaylistPluginOptions
+ playlistEmbedUrl?: string
+ playlistEmbedTitle?: string
videoDuration: number
enableHotkeys: boolean
PeertubePlayerManager.alreadyPlayed = true
})
- self.addContextMenu(mode, player, options.common.embedUrl, options.common.embedTitle)
+ self.addContextMenu({
+ mode,
+ player,
+ videoEmbedUrl: options.common.embedUrl,
+ videoEmbedTitle: options.common.embedTitle,
+ playlist: options.common.playlist
+ })
player.bezels()
videojs(newVideoElement, videojsOptions, function (this: videojs.Player) {
const player = this
- self.addContextMenu(mode, player, options.common.embedUrl, options.common.embedTitle)
+ self.addContextMenu({
+ mode,
+ player,
+ videoEmbedUrl: options.common.embedUrl,
+ videoEmbedTitle: options.common.embedTitle,
+ playlist: options.common.playlist
+ })
PeertubePlayerManager.onPlayerChange(player)
})
}
}
- if (commonOptions.playlist) {
+ if (commonOptions.playlist?.createComponent === true) {
plugins.playlist = commonOptions.playlist
}
return children
}
- private static addContextMenu (mode: PlayerMode, player: videojs.Player, videoEmbedUrl: string, videoEmbedTitle: string) {
+ private static addContextMenu (options: {
+ mode: PlayerMode
+ player: videojs.Player
+ videoEmbedUrl: string
+ videoEmbedTitle: string
+ playlist?: PlaylistPluginOptions
+ }) {
+ const { mode, player, videoEmbedUrl, videoEmbedTitle, playlist } = options
+
const content = () => {
- 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
- }
- },
- {
- 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() }))
+ 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() }))
+ }
}
- },
- {
- icon: 'code',
- label: player.localize('Copy embed code'),
- listener: () => {
- copyToClipboard(buildVideoOrPlaylistEmbed(videoEmbedUrl, videoEmbedTitle))
+ ])
+ } 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))
+ }
}
+ ])
+ }
+
+ items = items.concat({
+ icon: 'code',
+ label: player.localize('Copy video embed code'),
+ listener: () => {
+ copyToClipboard(buildVideoOrPlaylistEmbed(videoEmbedUrl, videoEmbedTitle))
}
- ]
+ })
if (mode === 'webtorrent') {
items.push({
'Watching this video may reveal your IP address to others.': 'Watching this video may reveal your IP address to others.',
'Copy the video URL': 'Copy the video URL',
'Copy the video URL at the current time': 'Copy the video URL at the current time',
- 'Copy embed code': 'Copy embed code',
+ 'Copy video embed code': 'Copy video embed code',
'Copy magnet URI': 'Copy magnet URI',
'Total downloaded: ': 'Total downloaded: ',
'Total uploaded: ': 'Total uploaded: ',
'From servers: ': 'From servers: ',
'From peers: ': 'From peers: ',
'Normal mode': 'Normal mode',
- 'Theater mode': 'Theater mode'
+ 'Play in loop': 'Play in loop',
+ 'Theater mode': 'Theater mode',
+ 'Copy the playlist URL': 'Copy the playlist URL',
+ 'Copy the playlist URL at current video position': 'Copy the playlist URL at current video position',
+ 'Copy the playlist embed code': 'Copy the playlist embed code'
}
Object.assign(playerKeys, videojs)