-
-// https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts
-// Don't import all Angular stuff, just copy the code with shame
-const dictionaryBytes: Array<{max: number, type: string}> = [
- { max: 1024, type: 'B' },
- { max: 1048576, type: 'KB' },
- { max: 1073741824, type: 'MB' },
- { max: 1.0995116e12, type: 'GB' }
-]
-function bytes (value) {
- const format = dictionaryBytes.find(d => value < d.max) || dictionaryBytes[dictionaryBytes.length - 1]
- const calc = Math.floor(value / (format.max / 1024)).toString()
-
- return [ calc, format.type ]
-}
-
-// videojs typings don't have some method we need
-const videojsUntyped = videojs as any
-const webtorrent = new WebTorrent({ dht: false })
-
-const MenuItem = videojsUntyped.getComponent('MenuItem')
-const ResolutionMenuItem = videojsUntyped.extend(MenuItem, {
- constructor: function (player: videojs.Player, options) {
- options.selectable = true
- MenuItem.call(this, player, options)
-
- const currentResolution = this.player_.getCurrentResolution()
- this.selected(this.options_.id === currentResolution)
- },
-
- handleClick: function (event) {
- MenuItem.prototype.handleClick.call(this, event)
- this.player_.updateResolution(this.options_.id)
- }
-})
-MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem)
-
-const MenuButton = videojsUntyped.getComponent('MenuButton')
-const ResolutionMenuButton = videojsUntyped.extend(MenuButton, {
- constructor: function (player, options) {
- this.label = document.createElement('span')
- options.label = 'Quality'
-
- MenuButton.call(this, player, options)
- this.el().setAttribute('aria-label', 'Quality')
- this.controlText('Quality')
-
- videojsUntyped.dom.addClass(this.label, 'vjs-resolution-button-label')
- this.el().appendChild(this.label)
-
- player.on('videoFileUpdate', videojs.bind(this, this.update))
- },
-
- createItems: function () {
- const menuItems = []
- for (const videoFile of this.player_.videoFiles) {
- menuItems.push(new ResolutionMenuItem(
- this.player_,