aboutsummaryrefslogblamecommitdiffhomepage
path: root/client/src/assets/player/videojs-components/peertube-load-progress-bar.ts
blob: 7869b56ce989473ee95da348f01cb7385366902f (plain) (tree)
1
2
3
4
5
6
7
8
9
                              
 
                                                   


                                                 
                                                                            
                          
 










                                                                                                    



                   
                                                           

                        

                                                                           




                                                                               
import videojs from 'video.js'

const Component = videojs.getComponent('Component')

class PeerTubeLoadProgressBar extends Component {

  constructor (player: videojs.Player, options?: videojs.ComponentOptions) {
    super(player, options)

    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 () {
    super.dispose()
  }

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

    // FIXME: typings
    (this.el() as HTMLElement).style.width = (torrent.progress * 100) + '%'
  }

}

Component.registerComponent('PeerTubeLoadProgressBar', PeerTubeLoadProgressBar)