Fix control bar inactive timeout

pull/2012/head
Chocobozzz 2019-08-07 10:17:19 +02:00
parent 327b331889
commit d1f21ebba6
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 37 additions and 15 deletions

View File

@ -36,6 +36,10 @@ class PeerTubePlugin extends Plugin {
private userWatchingVideoInterval: any private userWatchingVideoInterval: any
private lastResolutionChange: ResolutionUpdateData private lastResolutionChange: ResolutionUpdateData
private menuOpened = false
private mouseInControlBar = false
private readonly savedInactivityTimeout: number
constructor (player: videojs.Player, options: PeerTubePluginOptions) { constructor (player: videojs.Player, options: PeerTubePluginOptions) {
super(player, options) super(player, options)
@ -43,6 +47,8 @@ class PeerTubePlugin extends Plugin {
this.videoDuration = options.videoDuration this.videoDuration = options.videoDuration
this.videoCaptions = options.videoCaptions this.videoCaptions = options.videoCaptions
this.savedInactivityTimeout = player.options_.inactivityTimeout
if (options.autoplay === true) this.player.addClass('vjs-has-autoplay') if (options.autoplay === true) this.player.addClass('vjs-has-autoplay')
this.player.on('autoplay-failure', () => { this.player.on('autoplay-failure', () => {
@ -124,6 +130,16 @@ class PeerTubePlugin extends Plugin {
if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval) if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval)
} }
onMenuOpen () {
this.menuOpened = false
this.alterInactivity()
}
onMenuClosed () {
this.menuOpened = true
this.alterInactivity()
}
private initializePlayer () { private initializePlayer () {
if (isMobile()) this.player.addClass('vjs-is-mobile') if (isMobile()) this.player.addClass('vjs-is-mobile')
@ -131,7 +147,7 @@ class PeerTubePlugin extends Plugin {
this.initCaptions() this.initCaptions()
this.alterInactivity() this.listenControlBarMouse()
} }
private runViewAdd () { private runViewAdd () {
@ -208,23 +224,25 @@ class PeerTubePlugin extends Plugin {
this.trigger('resolutionChange', data) this.trigger('resolutionChange', data)
} }
private listenControlBarMouse () {
this.player.controlBar.on('mouseenter', () => {
this.mouseInControlBar = true
this.alterInactivity()
})
this.player.controlBar.on('mouseleave', () => {
this.mouseInControlBar = false
this.alterInactivity()
})
}
private alterInactivity () { private alterInactivity () {
let saveInactivityTimeout: number if (this.menuOpened || this.mouseInControlBar) {
this.player.options_.inactivityTimeout = this.savedInactivityTimeout
const disableInactivity = () => { return
saveInactivityTimeout = this.player.options_.inactivityTimeout
this.player.options_.inactivityTimeout = 0
}
const enableInactivity = () => {
this.player.options_.inactivityTimeout = saveInactivityTimeout
} }
const settingsDialog = this.player.children_.find((c: any) => c.name_ === 'SettingsDialog') this.player.options_.inactivityTimeout = 1
this.player.controlBar.on('mouseenter', () => disableInactivity())
settingsDialog.on('mouseenter', () => disableInactivity())
this.player.controlBar.on('mouseleave', () => enableInactivity())
settingsDialog.on('mouseleave', () => enableInactivity())
} }
private initCaptions () { private initCaptions () {

View File

@ -122,6 +122,8 @@ class SettingsButton extends Button {
} }
showDialog () { showDialog () {
this.player_.peertube().onMenuOpen()
this.menu.el_.style.opacity = '1' this.menu.el_.style.opacity = '1'
this.dialog.show() this.dialog.show()
@ -129,6 +131,8 @@ class SettingsButton extends Button {
} }
hideDialog () { hideDialog () {
this.player_.peertube().onMenuClosed()
this.dialog.hide() this.dialog.hide()
this.setDialogSize(this.getComponentSize(this.menu)) this.setDialogSize(this.getComponentSize(this.menu))
this.menu.el_.style.opacity = '1' this.menu.el_.style.opacity = '1'