From d1f21ebba640ccec21ca96496d0319f7511ac0b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Aug 2019 10:17:19 +0200 Subject: Fix control bar inactive timeout --- client/src/assets/player/peertube-plugin.ts | 48 ++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'client/src/assets/player/peertube-plugin.ts') diff --git a/client/src/assets/player/peertube-plugin.ts b/client/src/assets/player/peertube-plugin.ts index dd9408c8e..9824c43b5 100644 --- a/client/src/assets/player/peertube-plugin.ts +++ b/client/src/assets/player/peertube-plugin.ts @@ -36,6 +36,10 @@ class PeerTubePlugin extends Plugin { private userWatchingVideoInterval: any private lastResolutionChange: ResolutionUpdateData + private menuOpened = false + private mouseInControlBar = false + private readonly savedInactivityTimeout: number + constructor (player: videojs.Player, options: PeerTubePluginOptions) { super(player, options) @@ -43,6 +47,8 @@ class PeerTubePlugin extends Plugin { this.videoDuration = options.videoDuration this.videoCaptions = options.videoCaptions + this.savedInactivityTimeout = player.options_.inactivityTimeout + if (options.autoplay === true) this.player.addClass('vjs-has-autoplay') this.player.on('autoplay-failure', () => { @@ -124,6 +130,16 @@ class PeerTubePlugin extends Plugin { if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval) } + onMenuOpen () { + this.menuOpened = false + this.alterInactivity() + } + + onMenuClosed () { + this.menuOpened = true + this.alterInactivity() + } + private initializePlayer () { if (isMobile()) this.player.addClass('vjs-is-mobile') @@ -131,7 +147,7 @@ class PeerTubePlugin extends Plugin { this.initCaptions() - this.alterInactivity() + this.listenControlBarMouse() } private runViewAdd () { @@ -208,23 +224,25 @@ class PeerTubePlugin extends Plugin { this.trigger('resolutionChange', data) } - private alterInactivity () { - let saveInactivityTimeout: number + private listenControlBarMouse () { + this.player.controlBar.on('mouseenter', () => { + this.mouseInControlBar = true + this.alterInactivity() + }) - const disableInactivity = () => { - saveInactivityTimeout = this.player.options_.inactivityTimeout - this.player.options_.inactivityTimeout = 0 - } - const enableInactivity = () => { - this.player.options_.inactivityTimeout = saveInactivityTimeout - } + this.player.controlBar.on('mouseleave', () => { + this.mouseInControlBar = false + this.alterInactivity() + }) + } - const settingsDialog = this.player.children_.find((c: any) => c.name_ === 'SettingsDialog') + private alterInactivity () { + if (this.menuOpened || this.mouseInControlBar) { + this.player.options_.inactivityTimeout = this.savedInactivityTimeout + return + } - this.player.controlBar.on('mouseenter', () => disableInactivity()) - settingsDialog.on('mouseenter', () => disableInactivity()) - this.player.controlBar.on('mouseleave', () => enableInactivity()) - settingsDialog.on('mouseleave', () => enableInactivity()) + this.player.options_.inactivityTimeout = 1 } private initCaptions () { -- cgit v1.2.3