Revert "Fix context menu when watching a playlist"

This reverts commit e8bb5b6b3a.

We'll refactor this error handler in hls.js v1 upgrade
This commit is contained in:
Chocobozzz 2021-04-21 15:28:12 +02:00
parent 48d7e4ad13
commit 3e0e8d4afd
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 40 additions and 117 deletions

View File

@ -795,19 +795,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
src: environment.apiUrl + c.captionPath src: environment.apiUrl + c.captionPath
})) }))
const playlistOptions = this.playlist
? {
createComponent: false,
playlist: this.playlist,
getCurrentPosition: () => this.playlistPosition,
embedUrl: this.playlist.embedUrl,
embedTitle: this.playlist.displayName
}
: undefined
const options: PeertubePlayerManagerOptions = { const options: PeertubePlayerManagerOptions = {
common: { common: {
autoplay: this.isAutoplay(), autoplay: this.isAutoplay(),
@ -852,9 +839,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
videoCaptions: playerCaptions, videoCaptions: playerCaptions,
videoUUID: video.uuid, videoUUID: video.uuid
playlist: playlistOptions
}, },
webtorrent: { webtorrent: {

View File

@ -35,7 +35,7 @@ import {
VideoJSPluginOptions VideoJSPluginOptions
} from './peertube-videojs-typings' } from './peertube-videojs-typings'
import { TranslationsManager } from './translations-manager' 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' import { copyToClipboard } from '../../root-helpers/utils'
// Change 'Playback Rate' to 'Speed' (smaller for our settings menu) // Change 'Playback Rate' to 'Speed' (smaller for our settings menu)
@ -87,8 +87,6 @@ export interface CommonOptions extends CustomizationOptions {
hasPreviousVideo?: () => boolean hasPreviousVideo?: () => boolean
playlist?: PlaylistPluginOptions playlist?: PlaylistPluginOptions
playlistEmbedUrl?: string
playlistEmbedTitle?: string
videoDuration: number videoDuration: number
enableHotkeys: boolean enableHotkeys: boolean
@ -169,13 +167,7 @@ export class PeertubePlayerManager {
PeertubePlayerManager.alreadyPlayed = true PeertubePlayerManager.alreadyPlayed = true
}) })
self.addContextMenu({ self.addContextMenu(mode, player, options.common.embedUrl, options.common.embedTitle)
mode,
player,
videoEmbedUrl: options.common.embedUrl,
videoEmbedTitle: options.common.embedTitle,
playlist: options.common.playlist
})
player.bezels() player.bezels()
@ -213,13 +205,7 @@ export class PeertubePlayerManager {
videojs(newVideoElement, videojsOptions, function (this: videojs.Player) { videojs(newVideoElement, videojsOptions, function (this: videojs.Player) {
const player = this const player = this
self.addContextMenu({ self.addContextMenu(mode, player, options.common.embedUrl, options.common.embedTitle)
mode,
player,
videoEmbedUrl: options.common.embedUrl,
videoEmbedTitle: options.common.embedTitle,
playlist: options.common.playlist
})
PeertubePlayerManager.onPlayerChange(player) PeertubePlayerManager.onPlayerChange(player)
}) })
@ -253,7 +239,7 @@ export class PeertubePlayerManager {
} }
} }
if (commonOptions.playlist?.createComponent === true) { if (commonOptions.playlist) {
plugins.playlist = commonOptions.playlist plugins.playlist = commonOptions.playlist
} }
@ -511,71 +497,37 @@ export class PeertubePlayerManager {
return children return children
} }
private static addContextMenu (options: { private static addContextMenu (mode: PlayerMode, player: videojs.Player, videoEmbedUrl: string, videoEmbedTitle: string) {
mode: PlayerMode
player: videojs.Player
videoEmbedUrl: string
videoEmbedTitle: string
playlist?: PlaylistPluginOptions
}) {
const { mode, player, videoEmbedUrl, videoEmbedTitle, playlist } = options
const content = () => { const content = () => {
let items: { icon?: string, label: string, listener: Function }[] = [] const isLoopEnabled = player.options_['loop']
const items = [
if (!playlist) { {
const isLoopEnabled = player.options_['loop'] icon: 'repeat',
items = items.concat([ label: player.localize('Play in loop') + (isLoopEnabled ? '<span class="vjs-icon-tick-white"></span>' : ''),
{ listener: function () {
icon: 'repeat', player.options_['loop'] = !isLoopEnabled
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() }))
}
} }
]) },
} else { {
items = items.concat([ label: player.localize('Copy the video URL'),
{ listener: function () {
label: player.localize('Copy the playlist URL'), copyToClipboard(buildVideoLink())
listener: function () { }
copyToClipboard(buildPlaylistLink()) },
} {
}, label: player.localize('Copy the video URL at the current time'),
{ listener: function (this: videojs.Player) {
label: player.localize('Copy the playlist URL at current video position'), copyToClipboard(buildVideoLink({ startTime: this.currentTime() }))
listener: function (this: videojs.Player) { }
copyToClipboard(buildPlaylistLink({ playlistPosition: playlist.getCurrentPosition() })) },
} {
}, icon: 'code',
{ label: player.localize('Copy embed code'),
label: player.localize('Copy the playlist embed code'), listener: () => {
listener: function (this: videojs.Player) { copyToClipboard(buildVideoOrPlaylistEmbed(videoEmbedUrl, videoEmbedTitle))
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') { if (mode === 'webtorrent') {
items.push({ items.push({

View File

@ -113,18 +113,13 @@ type PeerTubePluginOptions = {
} }
type PlaylistPluginOptions = { type PlaylistPluginOptions = {
createComponent: boolean elements: VideoPlaylistElement[]
elements?: VideoPlaylistElement[]
playlist: VideoPlaylist playlist: VideoPlaylist
getCurrentPosition: () => number getCurrentPosition: () => number
embedUrl: string onItemClicked: (element: VideoPlaylistElement) => void
embedTitle: string
onItemClicked?: (element: VideoPlaylistElement) => void
} }
type NextPreviousVideoButtonOptions = { type NextPreviousVideoButtonOptions = {

View File

@ -94,8 +94,9 @@ function buildVideoLink (options: {
function buildPlaylistLink (options: { function buildPlaylistLink (options: {
baseUrl?: string baseUrl?: string
playlistPosition?: number
} = {}) { playlistPosition: number
}) {
const { baseUrl } = options const { baseUrl } = options
const url = baseUrl const url = baseUrl
@ -105,7 +106,6 @@ function buildPlaylistLink (options: {
const params = generateParams(window.location.search) const params = generateParams(window.location.search)
if (options.playlistPosition) params.set('playlistPosition', '' + options.playlistPosition) if (options.playlistPosition) params.set('playlistPosition', '' + options.playlistPosition)
else params.delete('playlistPosition')
return buildUrl(url, params) return buildUrl(url, params)
} }

View File

@ -492,8 +492,6 @@ export class PeerTubeEmbed {
const playlistPlugin = this.currentPlaylistElement const playlistPlugin = this.currentPlaylistElement
? { ? {
createComponent: true,
elements: this.playlistElements, elements: this.playlistElements,
playlist: this.playlist, playlist: this.playlist,
@ -504,10 +502,7 @@ export class PeerTubeEmbed {
this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid) this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid)
.catch(err => console.error(err)) .catch(err => console.error(err))
}, }
embedTitle: this.playlist.displayName,
embedUrl: window.location.origin + this.playlist.embedPath
} }
: undefined : undefined

View File

@ -29,18 +29,14 @@ const playerKeys = {
'Watching this video may reveal your IP address to others.': 'Watching this video may reveal your IP address to others.', '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': 'Copy the video URL',
'Copy the video URL at the current time': 'Copy the video URL at the current time', 'Copy the video URL at the current time': 'Copy the video URL at the current time',
'Copy video embed code': 'Copy video embed code', 'Copy embed code': 'Copy embed code',
'Copy magnet URI': 'Copy magnet URI', 'Copy magnet URI': 'Copy magnet URI',
'Total downloaded: ': 'Total downloaded: ', 'Total downloaded: ': 'Total downloaded: ',
'Total uploaded: ': 'Total uploaded: ', 'Total uploaded: ': 'Total uploaded: ',
'From servers: ': 'From servers: ', 'From servers: ': 'From servers: ',
'From peers: ': 'From peers: ', 'From peers: ': 'From peers: ',
'Normal mode': 'Normal mode', 'Normal mode': 'Normal mode',
'Play in loop': 'Play in loop', 'Theater mode': 'Theater mode'
'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) Object.assign(playerKeys, videojs)