From 951b582f52d0694865f020f0e53ccfad2d2d6033 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 7 Aug 2020 13:43:48 +0200 Subject: Add ability to share playlists in modal --- .../src/assets/player/peertube-player-manager.ts | 4 +- client/src/assets/player/utils.ts | 59 ++++++++++++++++------ 2 files changed, 46 insertions(+), 17 deletions(-) (limited to 'client/src/assets/player') diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index c71b43415..15b2f420b 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts @@ -35,7 +35,7 @@ import { VideoJSPluginOptions } from './peertube-videojs-typings' import { TranslationsManager } from './translations-manager' -import { buildVideoEmbed, buildVideoLink, copyToClipboard, getRtcConfig, isIOS, isSafari } from './utils' +import { buildVideoOrPlaylistEmbed, buildVideoLink, copyToClipboard, getRtcConfig, isIOS, isSafari } from './utils' // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) (videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed' @@ -492,7 +492,7 @@ export class PeertubePlayerManager { { label: player.localize('Copy embed code'), listener: () => { - copyToClipboard(buildVideoEmbed(videoEmbedUrl)) + copyToClipboard(buildVideoOrPlaylistEmbed(videoEmbedUrl)) } } ] diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index 115fdfa49..ce7a7fe6c 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts @@ -43,20 +43,20 @@ function isMobile () { } function buildVideoLink (options: { - baseUrl?: string, + baseUrl?: string - startTime?: number, - stopTime?: number, + startTime?: number + stopTime?: number - subtitle?: string, + subtitle?: string - loop?: boolean, - autoplay?: boolean, - muted?: boolean, + loop?: boolean + autoplay?: boolean + muted?: boolean // Embed options - title?: boolean, - warningTitle?: boolean, + title?: boolean + warningTitle?: boolean controls?: boolean peertubeLink?: boolean } = {}) { @@ -66,10 +66,7 @@ function buildVideoLink (options: { ? baseUrl : window.location.origin + window.location.pathname.replace('/embed/', '/watch/') - const params = new URLSearchParams(window.location.search) - // Remove these unused parameters when we are on a playlist page - params.delete('videoId') - params.delete('resume') + const params = generateParams(window.location.search) if (options.startTime) { const startTimeInt = Math.floor(options.startTime) @@ -91,6 +88,28 @@ function buildVideoLink (options: { if (options.controls === false) params.set('controls', '0') if (options.peertubeLink === false) params.set('peertubeLink', '0') + return buildUrl(url, params) +} + +function buildPlaylistLink (options: { + baseUrl?: string + + playlistPosition: number +}) { + const { baseUrl } = options + + const url = baseUrl + ? baseUrl + : window.location.origin + window.location.pathname.replace('/video-playlists/embed/', '/videos/watch/playlist/') + + const params = generateParams(window.location.search) + + if (options.playlistPosition) params.set('playlistPosition', '' + options.playlistPosition) + + return buildUrl(url, params) +} + +function buildUrl (url: string, params: URLSearchParams) { let hasParams = false params.forEach(() => hasParams = true) @@ -99,6 +118,15 @@ function buildVideoLink (options: { return url } +function generateParams (url: string) { + const params = new URLSearchParams(window.location.search) + // Unused parameters in embed + params.delete('videoId') + params.delete('resume') + + return params +} + function timeToInt (time: number | string) { if (!time) return 0 if (typeof time === 'number') return time @@ -140,7 +168,7 @@ function secondsToTime (seconds: number, full = false, symbol?: string) { return time } -function buildVideoEmbed (embedUrl: string) { +function buildVideoOrPlaylistEmbed (embedUrl: string) { return '