- return menuItems
- },
-
- update: function () {
- this.label.innerHTML = this.player_.getCurrentResolutionLabel()
- this.hide()
- return MenuButton.prototype.update.call(this)
- },
-
- buildCSSClass: function () {
- return MenuButton.prototype.buildCSSClass.call(this) + ' vjs-resolution-button'
- }
-})
-MenuButton.registerComponent('ResolutionMenuButton', ResolutionMenuButton)
-
-const Button = videojsUntyped.getComponent('Button')
-const PeertubeLinkButton = videojsUntyped.extend(Button, {
- constructor: function (player) {
- Button.call(this, player)
- },
-
- createEl: function () {
- const link = document.createElement('a')
- link.href = window.location.href.replace('embed', 'watch')
- link.innerHTML = 'PeerTube'
- link.title = 'Go to the video page'
- link.className = 'vjs-peertube-link'
- link.target = '_blank'
-
- return link
- },
-
- handleClick: function () {
- this.player_.pause()
- }
-})
-Button.registerComponent('PeerTubeLinkButton', PeertubeLinkButton)
-
-const WebTorrentButton = videojsUntyped.extend(Button, {
- constructor: function (player) {
- Button.call(this, player)
- },
-
- createEl: function () {
- const div = document.createElement('div')
- const subDiv = document.createElement('div')
- div.appendChild(subDiv)
-
- const downloadIcon = document.createElement('span')
- downloadIcon.classList.add('icon', 'icon-download')
- subDiv.appendChild(downloadIcon)
-
- const downloadSpeedText = document.createElement('span')
- downloadSpeedText.classList.add('download-speed-text')
- const downloadSpeedNumber = document.createElement('span')
- downloadSpeedNumber.classList.add('download-speed-number')
- const downloadSpeedUnit = document.createElement('span')
- downloadSpeedText.appendChild(downloadSpeedNumber)
- downloadSpeedText.appendChild(downloadSpeedUnit)
- subDiv.appendChild(downloadSpeedText)
-
- const uploadIcon = document.createElement('span')
- uploadIcon.classList.add('icon', 'icon-upload')
- subDiv.appendChild(uploadIcon)
-
- const uploadSpeedText = document.createElement('span')
- uploadSpeedText.classList.add('upload-speed-text')
- const uploadSpeedNumber = document.createElement('span')
- uploadSpeedNumber.classList.add('upload-speed-number')
- const uploadSpeedUnit = document.createElement('span')
- uploadSpeedText.appendChild(uploadSpeedNumber)
- uploadSpeedText.appendChild(uploadSpeedUnit)
- subDiv.appendChild(uploadSpeedText)
-
- const peersText = document.createElement('span')
- peersText.textContent = ' peers'
- peersText.classList.add('peers-text')
- const peersNumber = document.createElement('span')
- peersNumber.classList.add('peers-number')
- subDiv.appendChild(peersNumber)
- subDiv.appendChild(peersText)
-
- div.className = 'vjs-webtorrent'
- // Hide the stats before we get the info
- subDiv.style.display = 'none'
-
- this.player_.on('torrentInfo', (event, data) => {
- const downloadSpeed = bytes(data.downloadSpeed)
- const uploadSpeed = bytes(data.uploadSpeed)
- const numPeers = data.numPeers
-
- downloadSpeedNumber.textContent = downloadSpeed[0]
- downloadSpeedUnit.textContent = ' ' + downloadSpeed[1]
-
- uploadSpeedNumber.textContent = uploadSpeed[0]
- uploadSpeedUnit.textContent = ' ' + uploadSpeed[1]
-
- peersNumber.textContent = numPeers
-
- subDiv.style.display = 'block'
+ private player: any
+ private currentVideoFile: VideoFile
+ private torrent: WebTorrent.Torrent
+ private videoCaptions: VideoJSCaption[]
+ private renderer
+ private fakeRenderer
+ private autoResolution = true
+ private forbidAutoResolution = false
+ private isAutoResolutionObservation = false
+
+ private videoViewInterval
+ private torrentInfoInterval
+ private autoQualityInterval
+ private addTorrentDelay
+ private qualityObservationTimer
+ private runAutoQualitySchedulerTimer
+
+ private downloadSpeeds: number[] = []
+
+ constructor (player: videojs.Player, options: PeertubePluginOptions) {
+ super(player, options)
+
+ // Disable auto play on iOS
+ this.autoplay = options.autoplay && this.isIOS() === false
+
+ this.startTime = timeToInt(options.startTime)
+ this.videoFiles = options.videoFiles
+ this.videoViewUrl = options.videoViewUrl
+ this.videoDuration = options.videoDuration
+ this.videoCaptions = options.videoCaptions
+
+ this.savePlayerSrcFunction = this.player.src
+ // Hack to "simulate" src link in video.js >= 6
+ // Without this, we can't play the video after pausing it
+ // https://github.com/videojs/video.js/blob/master/src/js/player.js#L1633
+ this.player.src = () => true
+
+ this.playerElement = options.playerElement
+
+ if (this.autoplay === true) this.player.addClass('vjs-has-autoplay')
+
+ this.player.ready(() => {
+ const volume = getStoredVolume()
+ if (volume !== undefined) this.player.volume(volume)
+ const muted = getStoredMute()
+ if (muted !== undefined) this.player.muted(muted)
+
+ this.initializePlayer()
+ this.runTorrentInfoScheduler()
+ this.runViewAdd()
+
+ this.player.one('play', () => {
+ // Don't run immediately scheduler, wait some seconds the TCP connections are made
+ this.runAutoQualitySchedulerTimer = setTimeout(() => {
+ this.runAutoQualityScheduler()
+ }, this.CONSTANTS.AUTO_QUALITY_SCHEDULER)
+ })