diff options
Diffstat (limited to 'client/src/assets')
-rw-r--r-- | client/src/assets/player/peertube-player-manager.ts | 4 | ||||
-rw-r--r-- | client/src/assets/player/utils.ts | 61 |
2 files changed, 48 insertions, 17 deletions
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 { | |||
35 | VideoJSPluginOptions | 35 | VideoJSPluginOptions |
36 | } from './peertube-videojs-typings' | 36 | } from './peertube-videojs-typings' |
37 | import { TranslationsManager } from './translations-manager' | 37 | import { TranslationsManager } from './translations-manager' |
38 | import { buildVideoEmbed, buildVideoLink, copyToClipboard, getRtcConfig, isIOS, isSafari } from './utils' | 38 | import { buildVideoOrPlaylistEmbed, buildVideoLink, copyToClipboard, getRtcConfig, isIOS, isSafari } from './utils' |
39 | 39 | ||
40 | // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) | 40 | // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) |
41 | (videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed' | 41 | (videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed' |
@@ -492,7 +492,7 @@ export class PeertubePlayerManager { | |||
492 | { | 492 | { |
493 | label: player.localize('Copy embed code'), | 493 | label: player.localize('Copy embed code'), |
494 | listener: () => { | 494 | listener: () => { |
495 | copyToClipboard(buildVideoEmbed(videoEmbedUrl)) | 495 | copyToClipboard(buildVideoOrPlaylistEmbed(videoEmbedUrl)) |
496 | } | 496 | } |
497 | } | 497 | } |
498 | ] | 498 | ] |
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index 20d97c7e2..ce7a7fe6c 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts | |||
@@ -43,21 +43,22 @@ function isMobile () { | |||
43 | } | 43 | } |
44 | 44 | ||
45 | function buildVideoLink (options: { | 45 | function buildVideoLink (options: { |
46 | baseUrl?: string, | 46 | baseUrl?: string |
47 | 47 | ||
48 | startTime?: number, | 48 | startTime?: number |
49 | stopTime?: number, | 49 | stopTime?: number |
50 | 50 | ||
51 | subtitle?: string, | 51 | subtitle?: string |
52 | 52 | ||
53 | loop?: boolean, | 53 | loop?: boolean |
54 | autoplay?: boolean, | 54 | autoplay?: boolean |
55 | muted?: boolean, | 55 | muted?: boolean |
56 | 56 | ||
57 | // Embed options | 57 | // Embed options |
58 | title?: boolean, | 58 | title?: boolean |
59 | warningTitle?: boolean, | 59 | warningTitle?: boolean |
60 | controls?: boolean | 60 | controls?: boolean |
61 | peertubeLink?: boolean | ||
61 | } = {}) { | 62 | } = {}) { |
62 | const { baseUrl } = options | 63 | const { baseUrl } = options |
63 | 64 | ||
@@ -65,10 +66,7 @@ function buildVideoLink (options: { | |||
65 | ? baseUrl | 66 | ? baseUrl |
66 | : window.location.origin + window.location.pathname.replace('/embed/', '/watch/') | 67 | : window.location.origin + window.location.pathname.replace('/embed/', '/watch/') |
67 | 68 | ||
68 | const params = new URLSearchParams(window.location.search) | 69 | const params = generateParams(window.location.search) |
69 | // Remove these unused parameters when we are on a playlist page | ||
70 | params.delete('videoId') | ||
71 | params.delete('resume') | ||
72 | 70 | ||
73 | if (options.startTime) { | 71 | if (options.startTime) { |
74 | const startTimeInt = Math.floor(options.startTime) | 72 | const startTimeInt = Math.floor(options.startTime) |
@@ -88,7 +86,30 @@ function buildVideoLink (options: { | |||
88 | if (options.title === false) params.set('title', '0') | 86 | if (options.title === false) params.set('title', '0') |
89 | if (options.warningTitle === false) params.set('warningTitle', '0') | 87 | if (options.warningTitle === false) params.set('warningTitle', '0') |
90 | if (options.controls === false) params.set('controls', '0') | 88 | if (options.controls === false) params.set('controls', '0') |
89 | if (options.peertubeLink === false) params.set('peertubeLink', '0') | ||
90 | |||
91 | return buildUrl(url, params) | ||
92 | } | ||
93 | |||
94 | function buildPlaylistLink (options: { | ||
95 | baseUrl?: string | ||
96 | |||
97 | playlistPosition: number | ||
98 | }) { | ||
99 | const { baseUrl } = options | ||
100 | |||
101 | const url = baseUrl | ||
102 | ? baseUrl | ||
103 | : window.location.origin + window.location.pathname.replace('/video-playlists/embed/', '/videos/watch/playlist/') | ||
91 | 104 | ||
105 | const params = generateParams(window.location.search) | ||
106 | |||
107 | if (options.playlistPosition) params.set('playlistPosition', '' + options.playlistPosition) | ||
108 | |||
109 | return buildUrl(url, params) | ||
110 | } | ||
111 | |||
112 | function buildUrl (url: string, params: URLSearchParams) { | ||
92 | let hasParams = false | 113 | let hasParams = false |
93 | params.forEach(() => hasParams = true) | 114 | params.forEach(() => hasParams = true) |
94 | 115 | ||
@@ -97,6 +118,15 @@ function buildVideoLink (options: { | |||
97 | return url | 118 | return url |
98 | } | 119 | } |
99 | 120 | ||
121 | function generateParams (url: string) { | ||
122 | const params = new URLSearchParams(window.location.search) | ||
123 | // Unused parameters in embed | ||
124 | params.delete('videoId') | ||
125 | params.delete('resume') | ||
126 | |||
127 | return params | ||
128 | } | ||
129 | |||
100 | function timeToInt (time: number | string) { | 130 | function timeToInt (time: number | string) { |
101 | if (!time) return 0 | 131 | if (!time) return 0 |
102 | if (typeof time === 'number') return time | 132 | if (typeof time === 'number') return time |
@@ -138,7 +168,7 @@ function secondsToTime (seconds: number, full = false, symbol?: string) { | |||
138 | return time | 168 | return time |
139 | } | 169 | } |
140 | 170 | ||
141 | function buildVideoEmbed (embedUrl: string) { | 171 | function buildVideoOrPlaylistEmbed (embedUrl: string) { |
142 | return '<iframe width="560" height="315" ' + | 172 | return '<iframe width="560" height="315" ' + |
143 | 'sandbox="allow-same-origin allow-scripts allow-popups" ' + | 173 | 'sandbox="allow-same-origin allow-scripts allow-popups" ' + |
144 | 'src="' + embedUrl + '" ' + | 174 | 'src="' + embedUrl + '" ' + |
@@ -201,8 +231,9 @@ export { | |||
201 | timeToInt, | 231 | timeToInt, |
202 | secondsToTime, | 232 | secondsToTime, |
203 | isWebRTCDisabled, | 233 | isWebRTCDisabled, |
234 | buildPlaylistLink, | ||
204 | buildVideoLink, | 235 | buildVideoLink, |
205 | buildVideoEmbed, | 236 | buildVideoOrPlaylistEmbed, |
206 | videoFileMaxByResolution, | 237 | videoFileMaxByResolution, |
207 | videoFileMinByResolution, | 238 | videoFileMinByResolution, |
208 | copyToClipboard, | 239 | copyToClipboard, |