]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/resolution-menu-item.ts
Fix transcoding
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / resolution-menu-item.ts
index 95e0ed1f844bc74bd16312d8885ba6c77940e9a3..afe490abbfe6ede93fedc33843229d219ed5c8a1 100644 (file)
@@ -3,7 +3,7 @@ import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-ty
 const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem')
 class ResolutionMenuItem extends MenuItem {
 
-  constructor (player: videojs.Player, options) {
+  constructor (player: any, options: any) {
     const currentResolutionId = player.peertube().getCurrentResolutionId()
     options.selectable = true
     options.selected = options.id === currentResolutionId
@@ -13,18 +13,50 @@ class ResolutionMenuItem extends MenuItem {
     this.label = options.label
     this.id = options.id
 
-    player.peertube().on('videoFileUpdate', () => this.update())
+    player.peertube().on('videoFileUpdate', () => this.updateSelection())
+    player.peertube().on('autoResolutionUpdate', () => this.updateSelection())
   }
 
-  handleClick (event) {
+  handleClick (event: any) {
+    if (this.id === -1 && this.player_.peertube().isAutoResolutionForbidden()) return
+
     super.handleClick(event)
 
+    // Auto resolution
+    if (this.id === -1) {
+      this.player_.peertube().enableAutoResolution()
+      return
+    }
+
+    this.player_.peertube().disableAutoResolution()
     this.player_.peertube().updateResolution(this.id)
   }
 
-  update () {
+  updateSelection () {
+    // Check if auto resolution is forbidden or not
+    if (this.id === -1) {
+      if (this.player_.peertube().isAutoResolutionForbidden()) {
+        this.addClass('disabled')
+      } else {
+        this.removeClass('disabled')
+      }
+    }
+
+    if (this.player_.peertube().isAutoResolutionOn()) {
+      this.selected(this.id === -1)
+      return
+    }
+
     this.selected(this.player_.peertube().getCurrentResolutionId() === this.id)
   }
+
+  getLabel () {
+    if (this.id === -1) {
+      return this.label + ' <small>' + this.player_.peertube().getCurrentResolutionLabel() + '</small>'
+    }
+
+    return this.label
+  }
 }
 MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem)