]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/assets/player/mobile/peertube-mobile-plugin.ts
Move to landscape on mobile fullscreen
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / mobile / peertube-mobile-plugin.ts
CommitLineData
f1a0555a 1import './peertube-mobile-buttons'
e98ef69d 2import videojs from 'video.js'
f1a0555a
C
3
4const Plugin = videojs.getPlugin('plugin')
5
6class PeerTubeMobilePlugin extends Plugin {
7
8 constructor (player: videojs.Player, options: videojs.PlayerOptions) {
9 super(player, options)
10
11 player.addChild('PeerTubeMobileButtons')
e98ef69d
C
12
13 if (videojs.browser.IS_ANDROID && screen.orientation) {
14 this.handleFullscreenRotation()
15 }
16 }
17
18 private handleFullscreenRotation () {
19 this.player.on('fullscreenchange', () => {
20 if (!this.player.isFullscreen() || this.isPortraitVideo()) return
21
22 screen.orientation.lock('landscape')
23 .catch(err => console.error('Cannot lock screen to landscape.', err))
24 })
25 }
26
27 private isPortraitVideo () {
28 return this.player.videoWidth() < this.player.videoHeight()
f1a0555a
C
29 }
30}
31
32videojs.registerPlugin('peertubeMobile', PeerTubeMobilePlugin)
33export { PeerTubeMobilePlugin }