]>
Commit | Line | Data |
---|---|---|
c6352f2c C |
1 | import { VideoFile } from '../../../../shared/models/videos' |
2 | ||
3 | import 'videojs-hotkeys' | |
c7b0dacb | 4 | import 'videojs-dock' |
960a11e8 C |
5 | import 'videojs-contextmenu' |
6 | import 'videojs-contextmenu-ui' | |
c6352f2c C |
7 | import './peertube-link-button' |
8 | import './resolution-menu-button' | |
9 | import './settings-menu-button' | |
10 | import './webtorrent-info-button' | |
11 | import './peertube-videojs-plugin' | |
77728efa | 12 | import './peertube-load-progress-bar' |
c6352f2c | 13 | import { videojsUntyped } from './peertube-videojs-typings' |
960a11e8 | 14 | import { buildVideoEmbed, buildVideoLink, copyToClipboard } from './utils' |
74b7c6d4 | 15 | import { getCompleteLocale, is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n' |
c6352f2c C |
16 | |
17 | // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) | |
18 | videojsUntyped.getComponent('PlaybackRateMenuButton').prototype.controlText_ = 'Speed' | |
19 | ||
20 | function getVideojsOptions (options: { | |
21 | autoplay: boolean, | |
22 | playerElement: HTMLVideoElement, | |
23 | videoViewUrl: string, | |
24 | videoDuration: number, | |
25 | videoFiles: VideoFile[], | |
26 | enableHotkeys: boolean, | |
27 | inactivityTimeout: number, | |
33d78552 | 28 | peertubeLink: boolean, |
f37bad63 C |
29 | poster: string, |
30 | startTime: number | |
c6352f2c C |
31 | }) { |
32 | const videojsOptions = { | |
33 | controls: true, | |
33d78552 | 34 | poster: options.poster, |
80109b2d | 35 | autoplay: false, |
c6352f2c C |
36 | inactivityTimeout: options.inactivityTimeout, |
37 | playbackRates: [ 0.5, 1, 1.5, 2 ], | |
38 | plugins: { | |
39 | peertube: { | |
80109b2d | 40 | autoplay: options.autoplay, // Use peertube plugin autoplay because we get the file by webtorrent |
c6352f2c C |
41 | videoFiles: options.videoFiles, |
42 | playerElement: options.playerElement, | |
43 | videoViewUrl: options.videoViewUrl, | |
f37bad63 C |
44 | videoDuration: options.videoDuration, |
45 | startTime: options.startTime | |
c6352f2c C |
46 | } |
47 | }, | |
48 | controlBar: { | |
49 | children: getControlBarChildren(options) | |
50 | } | |
51 | } | |
52 | ||
53 | if (options.enableHotkeys === true) { | |
54 | Object.assign(videojsOptions.plugins, { | |
55 | hotkeys: { | |
56 | enableVolumeScroll: false | |
57 | } | |
58 | }) | |
59 | } | |
60 | ||
61 | return videojsOptions | |
62 | } | |
63 | ||
64 | function getControlBarChildren (options: { | |
65 | peertubeLink: boolean | |
66 | }) { | |
67 | const children = { | |
68 | 'playToggle': {}, | |
69 | 'currentTimeDisplay': {}, | |
70 | 'timeDivider': {}, | |
71 | 'durationDisplay': {}, | |
72 | 'liveDisplay': {}, | |
73 | ||
74 | 'flexibleWidthSpacer': {}, | |
77728efa C |
75 | 'progressControl': { |
76 | children: { | |
77 | 'seekBar': { | |
78 | children: { | |
79 | 'peerTubeLoadProgressBar': {}, | |
80 | 'playProgressBar': {} | |
81 | } | |
82 | } | |
83 | } | |
84 | }, | |
c6352f2c C |
85 | |
86 | 'webTorrentButton': {}, | |
87 | ||
88 | 'muteToggle': {}, | |
89 | 'volumeControl': {}, | |
90 | ||
91 | 'settingsButton': { | |
92 | setup: { | |
93 | maxHeightOffset: 40 | |
94 | }, | |
95 | entries: [ | |
96 | 'resolutionMenuButton', | |
97 | 'playbackRateMenuButton' | |
98 | ] | |
99 | } | |
100 | } | |
101 | ||
102 | if (options.peertubeLink === true) { | |
103 | Object.assign(children, { | |
104 | 'peerTubeLinkButton': {} | |
105 | }) | |
106 | } | |
107 | ||
108 | Object.assign(children, { | |
109 | 'fullscreenToggle': {} | |
110 | }) | |
111 | ||
112 | return children | |
113 | } | |
114 | ||
e945b184 C |
115 | function addContextMenu (player: any, videoEmbedUrl: string) { |
116 | console.log(videoEmbedUrl) | |
117 | ||
118 | player.contextmenuUI({ | |
119 | content: [ | |
120 | { | |
121 | label: player.localize('Copy the video URL'), | |
122 | listener: function () { | |
123 | copyToClipboard(buildVideoLink()) | |
124 | } | |
125 | }, | |
126 | { | |
127 | label: player.localize('Copy the video URL at the current time'), | |
128 | listener: function () { | |
129 | const player = this | |
130 | copyToClipboard(buildVideoLink(player.currentTime())) | |
131 | } | |
132 | }, | |
133 | { | |
134 | label: player.localize('Copy embed code'), | |
135 | listener: () => { | |
136 | copyToClipboard(buildVideoEmbed(videoEmbedUrl)) | |
137 | } | |
138 | } | |
139 | ] | |
140 | }) | |
141 | } | |
142 | ||
143 | function loadLocale (serverUrl: string, videojs: any, locale: string) { | |
74b7c6d4 | 144 | const completeLocale = getCompleteLocale(locale) |
e945b184 | 145 | |
74b7c6d4 C |
146 | if (!is18nLocale(completeLocale) || isDefaultLocale(completeLocale)) return Promise.resolve(undefined) |
147 | ||
148 | return fetch(serverUrl + '/client/locales/' + completeLocale + '/player.json') | |
e945b184 | 149 | .then(res => res.json()) |
74b7c6d4 | 150 | .then(json => videojs.addLanguage(completeLocale, json)) |
e945b184 C |
151 | } |
152 | ||
153 | export { | |
154 | loadLocale, | |
155 | getVideojsOptions, | |
156 | addContextMenu | |
157 | } |