import * as videojs from 'video.js'
import * as WebTorrent from 'webtorrent'
+import { VideoConstant, VideoResolution } from '../../../../shared/models/videos'
import { VideoFile } from '../../../../shared/models/videos/video.model'
import { renderVideo } from './video-renderer'
type PeertubePluginOptions = {
videoFiles: VideoFile[]
playerElement: HTMLVideoElement
- peerTubeLink: boolean
videoViewUrl: string
videoDuration: number
}
options.selectable = true
super(player, options)
- const currentResolution = this.player_.peertube().getCurrentResolution()
- this.selected(this.options_.id === currentResolution)
+ const currentResolutionId = this.player_.peertube().getCurrentResolutionId()
+ this.selected(this.options_.id === currentResolutionId)
}
handleClick (event) {
menuItems.push(new ResolutionMenuItem(
this.player_,
{
- id: videoFile.resolution,
- label: videoFile.resolutionLabel,
+ id: videoFile.resolution.id,
+ label: videoFile.resolution.label,
src: videoFile.magnetUri,
- selected: videoFile.resolution === this.currentSelection
+ selected: videoFile.resolution.id === this.currentSelectionId
})
)
}
buildCSSClass () {
return super.buildCSSClass() + ' vjs-resolution-button'
}
-
- dispose () {
- this.parentNode.removeChild(this)
- }
}
MenuButton.registerComponent('ResolutionMenuButton', ResolutionMenuButton)
const Button: VideoJSComponentInterface = videojsUntyped.getComponent('Button')
-class PeertubeLinkButton extends Button {
+class PeerTubeLinkButton extends Button {
createEl () {
const link = document.createElement('a')
handleClick () {
this.player_.pause()
}
-
- dispose () {
- this.parentNode.removeChild(this)
- }
}
-Button.registerComponent('PeerTubeLinkButton', PeertubeLinkButton)
+Button.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton)
class WebTorrentButton extends Button {
createEl () {
return div
}
-
- dispose () {
- this.parentNode.removeChild(this)
- }
}
Button.registerComponent('WebTorrentButton', WebTorrentButton)
this.flushVideoFile(this.currentVideoFile, false)
}
- getCurrentResolution () {
- return this.currentVideoFile ? this.currentVideoFile.resolution : -1
+ getCurrentResolutionId () {
+ return this.currentVideoFile ? this.currentVideoFile.resolution.id : -1
}
getCurrentResolutionLabel () {
- return this.currentVideoFile ? this.currentVideoFile.resolutionLabel : ''
+ return this.currentVideoFile ? this.currentVideoFile.resolution.label : ''
}
updateVideoFile (videoFile?: VideoFile, done?: () => void) {
// Do not display error to user because we will have multiple fallbacks
this.disableErrorDisplay()
+
this.player.src = () => true
+ this.player.playbackRate(1)
const previousVideoFile = this.currentVideoFile
this.currentVideoFile = videoFile
this.trigger('videoFileUpdate')
}
- updateResolution (resolution) {
+ updateResolution (resolutionId: number) {
// Remember player state
const currentTime = this.player.currentTime()
const isPaused = this.player.paused()
this.player.bigPlayButton.hide()
}
- const newVideoFile = this.videoFiles.find(f => f.resolution === resolution)
+ const newVideoFile = this.videoFiles.find(f => f.resolution.id === resolutionId)
this.updateVideoFile(newVideoFile, () => {
this.player.currentTime(currentTime)
this.player.handleTechSeeked_()
}
private initializePlayer (options: PeertubePluginOptions) {
- const controlBar = this.player.controlBar
-
- const menuButton = new ResolutionMenuButton(this.player, options)
- const fullscreenElement = controlBar.fullscreenToggle.el()
- controlBar.resolutionSwitcher = controlBar.el().insertBefore(menuButton.el(), fullscreenElement)
-
- if (options.peerTubeLink === true) {
- const peerTubeLinkButton = new PeertubeLinkButton(this.player)
- controlBar.peerTubeLink = controlBar.el().insertBefore(peerTubeLinkButton.el(), fullscreenElement)
- }
-
- const webTorrentButton = new WebTorrentButton(this.player)
- controlBar.webTorrent = controlBar.el().insertBefore(webTorrentButton.el(), controlBar.progressControl.el())
-
if (this.autoplay === true) {
this.updateVideoFile(undefined, () => this.player.play())
} else {