mirror of https://github.com/Chocobozzz/PeerTube
Improve control bar inactivity handling
Keep opened when user is in control bar settings Faster hidding transition for control barpull/4624/head
parent
07d6044e21
commit
dc9ff3128f
|
@ -11,6 +11,7 @@ import {
|
||||||
} from './peertube-player-local-storage'
|
} from './peertube-player-local-storage'
|
||||||
import { PeerTubePluginOptions, UserWatching, VideoJSCaption } from './peertube-videojs-typings'
|
import { PeerTubePluginOptions, UserWatching, VideoJSCaption } from './peertube-videojs-typings'
|
||||||
import { isMobile } from './utils'
|
import { isMobile } from './utils'
|
||||||
|
import { SettingsButton } from './videojs-components/settings-menu-button'
|
||||||
|
|
||||||
const Plugin = videojs.getPlugin('plugin')
|
const Plugin = videojs.getPlugin('plugin')
|
||||||
|
|
||||||
|
@ -31,7 +32,8 @@ class PeerTubePlugin extends Plugin {
|
||||||
|
|
||||||
private menuOpened = false
|
private menuOpened = false
|
||||||
private mouseInControlBar = false
|
private mouseInControlBar = false
|
||||||
private readonly savedInactivityTimeout: number
|
private mouseInSettings = false
|
||||||
|
private readonly initialInactivityTimeout: number
|
||||||
|
|
||||||
constructor (player: videojs.Player, options?: PeerTubePluginOptions) {
|
constructor (player: videojs.Player, options?: PeerTubePluginOptions) {
|
||||||
super(player)
|
super(player)
|
||||||
|
@ -40,8 +42,7 @@ class PeerTubePlugin extends Plugin {
|
||||||
this.videoDuration = options.videoDuration
|
this.videoDuration = options.videoDuration
|
||||||
this.videoCaptions = options.videoCaptions
|
this.videoCaptions = options.videoCaptions
|
||||||
this.isLive = options.isLive
|
this.isLive = options.isLive
|
||||||
|
this.initialInactivityTimeout = this.player.options_.inactivityTimeout
|
||||||
this.savedInactivityTimeout = player.options_.inactivityTimeout
|
|
||||||
|
|
||||||
if (options.autoplay) this.player.addClass('vjs-has-autoplay')
|
if (options.autoplay) this.player.addClass('vjs-has-autoplay')
|
||||||
|
|
||||||
|
@ -108,13 +109,13 @@ class PeerTubePlugin extends Plugin {
|
||||||
if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval)
|
if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
onMenuOpen () {
|
onMenuOpened () {
|
||||||
this.menuOpened = false
|
this.menuOpened = true
|
||||||
this.alterInactivity()
|
this.alterInactivity()
|
||||||
}
|
}
|
||||||
|
|
||||||
onMenuClosed () {
|
onMenuClosed () {
|
||||||
this.menuOpened = true
|
this.menuOpened = false
|
||||||
this.alterInactivity()
|
this.alterInactivity()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,26 +208,43 @@ class PeerTubePlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private listenControlBarMouse () {
|
private listenControlBarMouse () {
|
||||||
this.player.controlBar.on('mouseenter', () => {
|
const controlBar = this.player.controlBar
|
||||||
|
const settingsButton: SettingsButton = (controlBar as any).settingsButton
|
||||||
|
|
||||||
|
controlBar.on('mouseenter', () => {
|
||||||
this.mouseInControlBar = true
|
this.mouseInControlBar = true
|
||||||
this.alterInactivity()
|
this.alterInactivity()
|
||||||
})
|
})
|
||||||
|
|
||||||
this.player.controlBar.on('mouseleave', () => {
|
controlBar.on('mouseleave', () => {
|
||||||
this.mouseInControlBar = false
|
this.mouseInControlBar = false
|
||||||
this.alterInactivity()
|
this.alterInactivity()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
settingsButton.dialog.on('mouseenter', () => {
|
||||||
|
this.mouseInSettings = true
|
||||||
|
this.alterInactivity()
|
||||||
|
})
|
||||||
|
|
||||||
|
settingsButton.dialog.on('mouseleave', () => {
|
||||||
|
this.mouseInSettings = false
|
||||||
|
this.alterInactivity()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private alterInactivity () {
|
private alterInactivity () {
|
||||||
if (this.menuOpened) {
|
if (this.menuOpened || this.mouseInSettings || this.mouseInControlBar || this.isTouchEnabled()) {
|
||||||
this.player.options_.inactivityTimeout = this.savedInactivityTimeout
|
this.setInactivityTimeout(0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.mouseInControlBar && !this.isTouchEnabled()) {
|
this.setInactivityTimeout(this.initialInactivityTimeout)
|
||||||
this.player.options_.inactivityTimeout = 1
|
this.player.reportUserActivity(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setInactivityTimeout (timeout: number) {
|
||||||
|
(this.player as any).cache_.inactivityTimeout = timeout
|
||||||
|
this.player.options_.inactivityTimeout = timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
private isTouchEnabled () {
|
private isTouchEnabled () {
|
||||||
|
|
|
@ -144,7 +144,7 @@ class SettingsButton extends Button {
|
||||||
}
|
}
|
||||||
|
|
||||||
showDialog () {
|
showDialog () {
|
||||||
this.player().peertube().onMenuOpen();
|
this.player().peertube().onMenuOpened();
|
||||||
|
|
||||||
(this.menu.el() as HTMLElement).style.opacity = '1'
|
(this.menu.el() as HTMLElement).style.opacity = '1'
|
||||||
|
|
||||||
|
|
|
@ -158,6 +158,7 @@ body {
|
||||||
background: linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.6));
|
background: linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.6));
|
||||||
box-shadow: 0 -15px 40px 10px rgba(0, 0, 0, 0.2);
|
box-shadow: 0 -15px 40px 10px rgba(0, 0, 0, 0.2);
|
||||||
text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
|
text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
|
||||||
|
transition: visibility 0.3s, opacity 0.3s !important;
|
||||||
|
|
||||||
> button:first-child {
|
> button:first-child {
|
||||||
@include margin-left($first-control-bar-element-margin-left);
|
@include margin-left($first-control-bar-element-margin-left);
|
||||||
|
|
Loading…
Reference in New Issue