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