]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/videojs-components/resolution-menu-button.ts
Fix live duration in player
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / videojs-components / resolution-menu-button.ts
index d49ca02300d8217a05fef67bf68ccbcfd7cbefe5..8bd5b4f03610220379bac16719e9f4e46410fff3 100644 (file)
@@ -1,6 +1,4 @@
-import videojs from 'video.js/dist/alt/video.core.js'
-
-import { LoadedQualityData } from '../peertube-videojs-typings'
+import videojs from 'video.js'
 import { ResolutionMenuItem } from './resolution-menu-item'
 
 const Menu = videojs.getComponent('Menu')
@@ -13,9 +11,12 @@ class ResolutionMenuButton extends MenuButton {
 
     this.controlText('Quality')
 
-    player.tech(true).on('loadedqualitydata', (e: any, data: any) => this.buildQualities(data))
+    player.peertubeResolutions().on('resolutionsAdded', () => this.buildQualities())
 
-    player.peertube().on('resolutionChange', () => setTimeout(() => this.trigger('updateLabel'), 0))
+    // For parent
+    player.peertubeResolutions().on('resolutionChanged', () => {
+      setTimeout(() => this.trigger('labelUpdated'))
+    })
   }
 
   createEl () {
@@ -58,20 +59,8 @@ class ResolutionMenuButton extends MenuButton {
     })
   }
 
-  private buildQualities (data: LoadedQualityData) {
-    // The automatic resolution item will need other labels
-    const labels: { [ id: number ]: string } = {}
-
-    data.qualityData.video.sort((a, b) => {
-      if (a.id > b.id) return -1
-      if (a.id === b.id) return 0
-      return 1
-    })
-
-    for (const d of data.qualityData.video) {
-      // Skip auto resolution, we'll add it ourselves
-      if (d.id === -1) continue
-
+  private buildQualities () {
+    for (const d of this.player().peertubeResolutions().getResolutions()) {
       const label = d.label === '0p'
         ? this.player().localize('Audio-only')
         : d.label
@@ -81,25 +70,11 @@ class ResolutionMenuButton extends MenuButton {
         {
           id: d.id,
           label,
-          selected: d.selected,
-          callback: data.qualitySwitchCallback
+          selected: d.selected
         })
       )
-
-      labels[d.id] = d.label
     }
 
-    this.menu.addChild(new ResolutionMenuItem(
-      this.player_,
-      {
-        id: -1,
-        label: this.player_.localize('Auto'),
-        labels,
-        callback: data.qualitySwitchCallback,
-        selected: true // By default, in auto mode
-      }
-    ))
-
     for (const m of this.menu.children()) {
       this.addClickListener(m)
     }