From c6352f2c64f3c1ad54f8500f493587cdce3d33c9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Mar 2018 17:40:00 +0200 Subject: Improve player Add a settings dialog based on the work of Yanko Shterev (@yshterev): https://github.com/yshterev/videojs-settings-menu. Thanks! --- client/src/assets/player/resolution-menu-button.ts | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 client/src/assets/player/resolution-menu-button.ts (limited to 'client/src/assets/player/resolution-menu-button.ts') diff --git a/client/src/assets/player/resolution-menu-button.ts b/client/src/assets/player/resolution-menu-button.ts new file mode 100644 index 000000000..c927b084d --- /dev/null +++ b/client/src/assets/player/resolution-menu-button.ts @@ -0,0 +1,68 @@ +import * as videojs from 'video.js' +import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' +import { ResolutionMenuItem } from './resolution-menu-item' + +const Menu: VideoJSComponentInterface = videojsUntyped.getComponent('Menu') +const MenuButton: VideoJSComponentInterface = videojsUntyped.getComponent('MenuButton') +class ResolutionMenuButton extends MenuButton { + label: HTMLElement + + constructor (player: videojs.Player, options) { + options.label = 'Quality' + super(player, options) + + this.controlText_ = 'Quality' + this.player = player + + player.peertube().on('videoFileUpdate', () => this.updateLabel()) + } + + createEl () { + const el = super.createEl() + + this.labelEl_ = videojsUntyped.dom.createEl('div', { + className: 'vjs-resolution-value', + innerHTML: this.player_.peertube().getCurrentResolutionLabel() + }) + + el.appendChild(this.labelEl_) + + return el + } + + updateARIAAttributes () { + this.el().setAttribute('aria-label', 'Quality') + } + + createMenu () { + const menu = new Menu(this.player()) + + for (const videoFile of this.player_.peertube().videoFiles) { + menu.addChild(new ResolutionMenuItem( + this.player_, + { + id: videoFile.resolution.id, + label: videoFile.resolution.label, + src: videoFile.magnetUri + }) + ) + } + + return menu + } + + updateLabel () { + if (!this.labelEl_) return + + this.labelEl_.innerHTML = this.player_.peertube().getCurrentResolutionLabel() + } + + buildCSSClass () { + return super.buildCSSClass() + ' vjs-resolution-button' + } + + buildWrapperCSSClass () { + return 'vjs-resolution-control ' + super.buildWrapperCSSClass() + } +} +MenuButton.registerComponent('ResolutionMenuButton', ResolutionMenuButton) -- cgit v1.2.3