diff options
Diffstat (limited to 'client/src/assets')
4 files changed, 71 insertions, 20 deletions
diff --git a/client/src/assets/player/peertube-player-local-storage.ts b/client/src/assets/player/peertube-player-local-storage.ts index 059fca308..f6c5c5419 100644 --- a/client/src/assets/player/peertube-player-local-storage.ts +++ b/client/src/assets/player/peertube-player-local-storage.ts | |||
@@ -29,7 +29,7 @@ function getStoredTheater () { | |||
29 | const value = getLocalStorage('theater-enabled') | 29 | const value = getLocalStorage('theater-enabled') |
30 | if (value !== null && value !== undefined) return value === 'true' | 30 | if (value !== null && value !== undefined) return value === 'true' |
31 | 31 | ||
32 | return undefined | 32 | return false |
33 | } | 33 | } |
34 | 34 | ||
35 | function saveVolumeInStore (value: number) { | 35 | function saveVolumeInStore (value: number) { |
diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index 6cdd54372..083c621d2 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts | |||
@@ -39,7 +39,19 @@ export type P2PMediaLoaderOptions = { | |||
39 | videoFiles: VideoFile[] | 39 | videoFiles: VideoFile[] |
40 | } | 40 | } |
41 | 41 | ||
42 | export type CommonOptions = { | 42 | export interface CustomizationOptions { |
43 | startTime: number | string | ||
44 | stopTime: number | string | ||
45 | |||
46 | controls?: boolean | ||
47 | muted?: boolean | ||
48 | loop?: boolean | ||
49 | subtitle?: string | ||
50 | |||
51 | peertubeLink: boolean | ||
52 | } | ||
53 | |||
54 | export interface CommonOptions extends CustomizationOptions { | ||
43 | playerElement: HTMLVideoElement | 55 | playerElement: HTMLVideoElement |
44 | onPlayerElementChange: (element: HTMLVideoElement) => void | 56 | onPlayerElementChange: (element: HTMLVideoElement) => void |
45 | 57 | ||
@@ -48,21 +60,14 @@ export type CommonOptions = { | |||
48 | enableHotkeys: boolean | 60 | enableHotkeys: boolean |
49 | inactivityTimeout: number | 61 | inactivityTimeout: number |
50 | poster: string | 62 | poster: string |
51 | startTime: number | string | ||
52 | stopTime: number | string | ||
53 | 63 | ||
54 | theaterMode: boolean | 64 | theaterMode: boolean |
55 | captions: boolean | 65 | captions: boolean |
56 | peertubeLink: boolean | ||
57 | 66 | ||
58 | videoViewUrl: string | 67 | videoViewUrl: string |
59 | embedUrl: string | 68 | embedUrl: string |
60 | 69 | ||
61 | language?: string | 70 | language?: string |
62 | controls?: boolean | ||
63 | muted?: boolean | ||
64 | loop?: boolean | ||
65 | subtitle?: string | ||
66 | 71 | ||
67 | videoCaptions: VideoJSCaption[] | 72 | videoCaptions: VideoJSCaption[] |
68 | 73 | ||
@@ -117,8 +122,17 @@ export class PeertubePlayerManager { | |||
117 | videojs(options.common.playerElement, videojsOptions, function (this: any) { | 122 | videojs(options.common.playerElement, videojsOptions, function (this: any) { |
118 | const player = this | 123 | const player = this |
119 | 124 | ||
120 | player.tech_.one('error', () => self.maybeFallbackToWebTorrent(mode, player, options)) | 125 | let alreadyFallback = false |
121 | player.one('error', () => self.maybeFallbackToWebTorrent(mode, player, options)) | 126 | |
127 | player.tech_.one('error', () => { | ||
128 | if (!alreadyFallback) self.maybeFallbackToWebTorrent(mode, player, options) | ||
129 | alreadyFallback = true | ||
130 | }) | ||
131 | |||
132 | player.one('error', () => { | ||
133 | if (!alreadyFallback) self.maybeFallbackToWebTorrent(mode, player, options) | ||
134 | alreadyFallback = true | ||
135 | }) | ||
122 | 136 | ||
123 | self.addContextMenu(mode, player, options.common.embedUrl) | 137 | self.addContextMenu(mode, player, options.common.embedUrl) |
124 | 138 | ||
@@ -432,7 +446,7 @@ export class PeertubePlayerManager { | |||
432 | label: player.localize('Copy the video URL at the current time'), | 446 | label: player.localize('Copy the video URL at the current time'), |
433 | listener: function () { | 447 | listener: function () { |
434 | const player = this as videojs.Player | 448 | const player = this as videojs.Player |
435 | copyToClipboard(buildVideoLink(player.currentTime())) | 449 | copyToClipboard(buildVideoLink({ startTime: player.currentTime() })) |
436 | } | 450 | } |
437 | }, | 451 | }, |
438 | { | 452 | { |
diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index 366689962..777abb568 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts | |||
@@ -27,18 +27,55 @@ function isMobile () { | |||
27 | return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) | 27 | return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) |
28 | } | 28 | } |
29 | 29 | ||
30 | function buildVideoLink (time?: number, url?: string) { | 30 | function buildVideoLink (options: { |
31 | if (!url) url = window.location.origin + window.location.pathname.replace('/embed/', '/watch/') | 31 | baseUrl?: string, |
32 | 32 | ||
33 | if (time) { | 33 | startTime?: number, |
34 | const timeInt = Math.floor(time) | 34 | stopTime?: number, |
35 | 35 | ||
36 | const params = new URLSearchParams(window.location.search) | 36 | subtitle?: string, |
37 | params.set('start', secondsToTime(timeInt)) | ||
38 | 37 | ||
39 | return url + '?' + params.toString() | 38 | loop?: boolean, |
39 | autoplay?: boolean, | ||
40 | muted?: boolean, | ||
41 | |||
42 | // Embed options | ||
43 | title?: boolean, | ||
44 | warningTitle?: boolean, | ||
45 | controls?: boolean | ||
46 | } = {}) { | ||
47 | const { baseUrl } = options | ||
48 | |||
49 | const url = baseUrl | ||
50 | ? baseUrl | ||
51 | : window.location.origin + window.location.pathname.replace('/embed/', '/watch/') | ||
52 | |||
53 | const params = new URLSearchParams(window.location.search) | ||
54 | |||
55 | if (options.startTime) { | ||
56 | const startTimeInt = Math.floor(options.startTime) | ||
57 | params.set('start', secondsToTime(startTimeInt)) | ||
58 | } | ||
59 | |||
60 | if (options.stopTime) { | ||
61 | const stopTimeInt = Math.floor(options.stopTime) | ||
62 | params.set('stop', secondsToTime(stopTimeInt)) | ||
40 | } | 63 | } |
41 | 64 | ||
65 | if (options.subtitle) params.set('subtitle', options.subtitle) | ||
66 | |||
67 | if (options.loop === true) params.set('loop', '1') | ||
68 | if (options.autoplay === true) params.set('autoplay', '1') | ||
69 | if (options.muted === true) params.set('muted', '1') | ||
70 | if (options.title === false) params.set('title', '0') | ||
71 | if (options.warningTitle === false) params.set('warningTitle', '0') | ||
72 | if (options.controls === false) params.set('controls', '0') | ||
73 | |||
74 | let hasParams = false | ||
75 | params.forEach(() => hasParams = true) | ||
76 | |||
77 | if (hasParams) return url + '?' + params.toString() | ||
78 | |||
42 | return url | 79 | return url |
43 | } | 80 | } |
44 | 81 | ||
diff --git a/client/src/assets/player/videojs-components/peertube-link-button.ts b/client/src/assets/player/videojs-components/peertube-link-button.ts index fed8ea33e..4d0ea37f5 100644 --- a/client/src/assets/player/videojs-components/peertube-link-button.ts +++ b/client/src/assets/player/videojs-components/peertube-link-button.ts | |||
@@ -16,7 +16,7 @@ class PeerTubeLinkButton extends Button { | |||
16 | } | 16 | } |
17 | 17 | ||
18 | updateHref () { | 18 | updateHref () { |
19 | this.el().setAttribute('href', buildVideoLink(this.player().currentTime())) | 19 | this.el().setAttribute('href', buildVideoLink({ startTime: this.player().currentTime() })) |
20 | } | 20 | } |
21 | 21 | ||
22 | handleClick () { | 22 | handleClick () { |