aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/peertube-load-progress-bar.ts
blob: ee8a6cd81c8697ca626ff73ae3aa7d2d6ec09db9 (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
32
33
34
35
import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings'

const Component: VideoJSComponentInterface = videojsUntyped.getComponent('Component')

class PeerTubeLoadProgressBar extends Component {

  constructor (player: any, options: any) {
    super(player, options)
    this.partEls_ = []
    this.on(player, 'progress', this.update)
  }

  createEl () {
    return super.createEl('div', {
      className: 'vjs-load-progress',
      innerHTML: `<span class="vjs-control-text"><span>${this.localize('Loaded')}</span>: 0%</span>`
    })
  }

  dispose () {
    this.partEls_ = null

    super.dispose()
  }

  update () {
    const torrent = this.player().peertube().getTorrent()
    if (!torrent) return

    this.el_.style.width = (torrent.progress * 100) + '%'
  }

}

Component.registerComponent('PeerTubeLoadProgressBar', PeerTubeLoadProgressBar)