From dc9ff3128f2fa9cd64ab628699608b3794c78d43 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 9 Dec 2021 10:33:32 +0100 Subject: Improve control bar inactivity handling Keep opened when user is in control bar settings Faster hidding transition for control bar --- client/src/assets/player/peertube-plugin.ts | 44 +++++++++++++++------- .../videojs-components/settings-menu-button.ts | 2 +- 2 files changed, 32 insertions(+), 14 deletions(-) (limited to 'client/src/assets/player') diff --git a/client/src/assets/player/peertube-plugin.ts b/client/src/assets/player/peertube-plugin.ts index f03553184..451b4a161 100644 --- a/client/src/assets/player/peertube-plugin.ts +++ b/client/src/assets/player/peertube-plugin.ts @@ -11,6 +11,7 @@ import { } from './peertube-player-local-storage' import { PeerTubePluginOptions, UserWatching, VideoJSCaption } from './peertube-videojs-typings' import { isMobile } from './utils' +import { SettingsButton } from './videojs-components/settings-menu-button' const Plugin = videojs.getPlugin('plugin') @@ -31,7 +32,8 @@ class PeerTubePlugin extends Plugin { private menuOpened = false private mouseInControlBar = false - private readonly savedInactivityTimeout: number + private mouseInSettings = false + private readonly initialInactivityTimeout: number constructor (player: videojs.Player, options?: PeerTubePluginOptions) { super(player) @@ -40,8 +42,7 @@ class PeerTubePlugin extends Plugin { this.videoDuration = options.videoDuration this.videoCaptions = options.videoCaptions this.isLive = options.isLive - - this.savedInactivityTimeout = player.options_.inactivityTimeout + this.initialInactivityTimeout = this.player.options_.inactivityTimeout if (options.autoplay) this.player.addClass('vjs-has-autoplay') @@ -108,13 +109,13 @@ class PeerTubePlugin extends Plugin { if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval) } - onMenuOpen () { - this.menuOpened = false + onMenuOpened () { + this.menuOpened = true this.alterInactivity() } onMenuClosed () { - this.menuOpened = true + this.menuOpened = false this.alterInactivity() } @@ -207,26 +208,43 @@ class PeerTubePlugin extends Plugin { } 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.alterInactivity() }) - this.player.controlBar.on('mouseleave', () => { + controlBar.on('mouseleave', () => { this.mouseInControlBar = false this.alterInactivity() }) + + settingsButton.dialog.on('mouseenter', () => { + this.mouseInSettings = true + this.alterInactivity() + }) + + settingsButton.dialog.on('mouseleave', () => { + this.mouseInSettings = false + this.alterInactivity() + }) } private alterInactivity () { - if (this.menuOpened) { - this.player.options_.inactivityTimeout = this.savedInactivityTimeout + if (this.menuOpened || this.mouseInSettings || this.mouseInControlBar || this.isTouchEnabled()) { + this.setInactivityTimeout(0) return } - if (!this.mouseInControlBar && !this.isTouchEnabled()) { - this.player.options_.inactivityTimeout = 1 - } + this.setInactivityTimeout(this.initialInactivityTimeout) + this.player.reportUserActivity(true) + } + + private setInactivityTimeout (timeout: number) { + (this.player as any).cache_.inactivityTimeout = timeout + this.player.options_.inactivityTimeout = timeout } private isTouchEnabled () { diff --git a/client/src/assets/player/videojs-components/settings-menu-button.ts b/client/src/assets/player/videojs-components/settings-menu-button.ts index 75a5c6904..6de390f4d 100644 --- a/client/src/assets/player/videojs-components/settings-menu-button.ts +++ b/client/src/assets/player/videojs-components/settings-menu-button.ts @@ -144,7 +144,7 @@ class SettingsButton extends Button { } showDialog () { - this.player().peertube().onMenuOpen(); + this.player().peertube().onMenuOpened(); (this.menu.el() as HTMLElement).style.opacity = '1' -- cgit v1.2.3