aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/peertube-plugin.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player/peertube-plugin.ts')
-rw-r--r--client/src/assets/player/peertube-plugin.ts44
1 files changed, 31 insertions, 13 deletions
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 {
11} from './peertube-player-local-storage' 11} from './peertube-player-local-storage'
12import { PeerTubePluginOptions, UserWatching, VideoJSCaption } from './peertube-videojs-typings' 12import { PeerTubePluginOptions, UserWatching, VideoJSCaption } from './peertube-videojs-typings'
13import { isMobile } from './utils' 13import { isMobile } from './utils'
14import { SettingsButton } from './videojs-components/settings-menu-button'
14 15
15const Plugin = videojs.getPlugin('plugin') 16const Plugin = videojs.getPlugin('plugin')
16 17
@@ -31,7 +32,8 @@ class PeerTubePlugin extends Plugin {
31 32
32 private menuOpened = false 33 private menuOpened = false
33 private mouseInControlBar = false 34 private mouseInControlBar = false
34 private readonly savedInactivityTimeout: number 35 private mouseInSettings = false
36 private readonly initialInactivityTimeout: number
35 37
36 constructor (player: videojs.Player, options?: PeerTubePluginOptions) { 38 constructor (player: videojs.Player, options?: PeerTubePluginOptions) {
37 super(player) 39 super(player)
@@ -40,8 +42,7 @@ class PeerTubePlugin extends Plugin {
40 this.videoDuration = options.videoDuration 42 this.videoDuration = options.videoDuration
41 this.videoCaptions = options.videoCaptions 43 this.videoCaptions = options.videoCaptions
42 this.isLive = options.isLive 44 this.isLive = options.isLive
43 45 this.initialInactivityTimeout = this.player.options_.inactivityTimeout
44 this.savedInactivityTimeout = player.options_.inactivityTimeout
45 46
46 if (options.autoplay) this.player.addClass('vjs-has-autoplay') 47 if (options.autoplay) this.player.addClass('vjs-has-autoplay')
47 48
@@ -108,13 +109,13 @@ class PeerTubePlugin extends Plugin {
108 if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval) 109 if (this.userWatchingVideoInterval) clearInterval(this.userWatchingVideoInterval)
109 } 110 }
110 111
111 onMenuOpen () { 112 onMenuOpened () {
112 this.menuOpened = false 113 this.menuOpened = true
113 this.alterInactivity() 114 this.alterInactivity()
114 } 115 }
115 116
116 onMenuClosed () { 117 onMenuClosed () {
117 this.menuOpened = true 118 this.menuOpened = false
118 this.alterInactivity() 119 this.alterInactivity()
119 } 120 }
120 121
@@ -207,26 +208,43 @@ class PeerTubePlugin extends Plugin {
207 } 208 }
208 209
209 private listenControlBarMouse () { 210 private listenControlBarMouse () {
210 this.player.controlBar.on('mouseenter', () => { 211 const controlBar = this.player.controlBar
212 const settingsButton: SettingsButton = (controlBar as any).settingsButton
213
214 controlBar.on('mouseenter', () => {
211 this.mouseInControlBar = true 215 this.mouseInControlBar = true
212 this.alterInactivity() 216 this.alterInactivity()
213 }) 217 })
214 218
215 this.player.controlBar.on('mouseleave', () => { 219 controlBar.on('mouseleave', () => {
216 this.mouseInControlBar = false 220 this.mouseInControlBar = false
217 this.alterInactivity() 221 this.alterInactivity()
218 }) 222 })
223
224 settingsButton.dialog.on('mouseenter', () => {
225 this.mouseInSettings = true
226 this.alterInactivity()
227 })
228
229 settingsButton.dialog.on('mouseleave', () => {
230 this.mouseInSettings = false
231 this.alterInactivity()
232 })
219 } 233 }
220 234
221 private alterInactivity () { 235 private alterInactivity () {
222 if (this.menuOpened) { 236 if (this.menuOpened || this.mouseInSettings || this.mouseInControlBar || this.isTouchEnabled()) {
223 this.player.options_.inactivityTimeout = this.savedInactivityTimeout 237 this.setInactivityTimeout(0)
224 return 238 return
225 } 239 }
226 240
227 if (!this.mouseInControlBar && !this.isTouchEnabled()) { 241 this.setInactivityTimeout(this.initialInactivityTimeout)
228 this.player.options_.inactivityTimeout = 1 242 this.player.reportUserActivity(true)
229 } 243 }
244
245 private setInactivityTimeout (timeout: number) {
246 (this.player as any).cache_.inactivityTimeout = timeout
247 this.player.options_.inactivityTimeout = timeout
230 } 248 }
231 249
232 private isTouchEnabled () { 250 private isTouchEnabled () {