X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fassets%2Fplayer%2Fpeertube-plugin.ts;h=5085f7f86b758832ea9b19e371cceb0ebf055b77;hb=610d0be13b3d01f653ef269271dd667a57c85ef2;hp=dd9408c8e280b37df8803cc3b9d96ddb36af24ef;hpb=e2f01c47e08d26a30ad47068d195b3d21d0df8a1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/assets/player/peertube-plugin.ts b/client/src/assets/player/peertube-plugin.ts index dd9408c8e..5085f7f86 100644 --- a/client/src/assets/player/peertube-plugin.ts +++ b/client/src/assets/player/peertube-plugin.ts @@ -1,14 +1,10 @@ -// FIXME: something weird with our path definition in tsconfig and typings -// @ts-ignore -import * as videojs from 'video.js' +import videojs from 'video.js' import './videojs-components/settings-menu-button' import { PeerTubePluginOptions, ResolutionUpdateData, UserWatching, - VideoJSCaption, - VideoJSComponentInterface, - videojsUntyped + VideoJSCaption } from './peertube-videojs-typings' import { isMobile, timeToInt } from './utils' import { @@ -20,7 +16,8 @@ import { saveVolumeInStore } from './peertube-player-local-storage' -const Plugin: VideoJSComponentInterface = videojs.getPlugin('plugin') +const Plugin = videojs.getPlugin('plugin') + class PeerTubePlugin extends Plugin { private readonly videoViewUrl: string private readonly videoDuration: number @@ -28,7 +25,6 @@ class PeerTubePlugin extends Plugin { USER_WATCHING_VIDEO_INTERVAL: 5000 // Every 5 seconds, notify the user is watching the video } - private player: any private videoCaptions: VideoJSCaption[] private defaultSubtitle: string @@ -36,13 +32,19 @@ class PeerTubePlugin extends Plugin { private userWatchingVideoInterval: any private lastResolutionChange: ResolutionUpdateData - constructor (player: videojs.Player, options: PeerTubePluginOptions) { - super(player, options) + private menuOpened = false + private mouseInControlBar = false + private readonly savedInactivityTimeout: number + + constructor (player: videojs.Player, options?: PeerTubePluginOptions) { + super(player) this.videoViewUrl = options.videoViewUrl 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', () => { @@ -61,7 +63,7 @@ class PeerTubePlugin extends Plugin { this.player.p2pMediaLoader().on('resolutionChange', (_: any, d: any) => this.handleResolutionChange(d)) } - this.player.tech_.on('loadedqualitydata', () => { + this.player.tech(true).on('loadedqualitydata', () => { setTimeout(() => { // Replay a resolution change, now we loaded all quality data if (this.lastResolutionChange) this.handleResolutionChange(this.lastResolutionChange) @@ -96,7 +98,7 @@ class PeerTubePlugin extends Plugin { } this.player.textTracks().on('change', () => { - const showing = this.player.textTracks().tracks_.find((t: { kind: string, mode: string }) => { + const showing = this.player.textTracks().tracks_.find(t => { return t.kind === 'captions' && t.mode === 'showing' }) @@ -124,6 +126,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 +143,7 @@ class PeerTubePlugin extends Plugin { this.initCaptions() - this.alterInactivity() + this.listenControlBarMouse() } private runViewAdd () { @@ -208,23 +220,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 () { @@ -244,7 +258,7 @@ class PeerTubePlugin extends Plugin { // Thanks: https://github.com/videojs/video.js/issues/4460#issuecomment-312861657 private initSmoothProgressBar () { - const SeekBar = videojsUntyped.getComponent('SeekBar') + const SeekBar = videojs.getComponent('SeekBar') as any SeekBar.prototype.getPercent = function getPercent () { // Allows for smooth scrubbing, when player can't keep up. // const time = (this.player_.scrubbing()) ?