aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/resolution-menu-item.ts
blob: 8ad834c59c6b6432474a769a018cb5649e79fada (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'

const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem')
class ResolutionMenuItem extends MenuItem {

  constructor (player: videojs.Player, options) {
    const currentResolutionId = player.peertube().getCurrentResolutionId()
    options.selectable = true
    options.selected = options.id === currentResolutionId

    super(player, options)

    this.label = options.label
    this.id = options.id

    player.peertube().on('videoFileUpdate', () => this.updateSelection())
  }

  handleClick (event) {
    super.handleClick(event)

    this.player_.peertube().updateResolution(this.id)
  }

  updateSelection () {
    this.selected(this.player_.peertube().getCurrentResolutionId() === this.id)
  }
}
MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem)

export { ResolutionMenuItem }