X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fassets%2Fplayer%2Fpeertube-videojs-plugin.ts;h=c99363fb52e65a90b6dfb99f9f0804cf6b76f335;hb=09700934b90e2ac7b1b9ed1694d9d4d52735e2e1;hp=618d77cbed6c373a8e0b1ae61c04fb053c456f8a;hpb=bf5685f0b7b1f23a1a3a972fc4d66061f31f9510;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts index 618d77cbe..c99363fb5 100644 --- a/client/src/assets/player/peertube-videojs-plugin.ts +++ b/client/src/assets/player/peertube-videojs-plugin.ts @@ -2,6 +2,7 @@ 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' @@ -22,7 +23,6 @@ interface VideoJSComponentInterface { type PeertubePluginOptions = { videoFiles: VideoFile[] playerElement: HTMLVideoElement - peerTubeLink: boolean videoViewUrl: string videoDuration: number } @@ -53,8 +53,8 @@ class ResolutionMenuItem extends MenuItem { 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) { @@ -90,10 +90,10 @@ class ResolutionMenuButton extends MenuButton { 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 }) ) } @@ -112,15 +112,11 @@ class ResolutionMenuButton extends MenuButton { 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') @@ -136,12 +132,8 @@ class PeertubeLinkButton extends Button { handleClick () { this.player_.pause() } - - dispose () { - this.parentNode.removeChild(this) - } } -Button.registerComponent('PeerTubeLinkButton', PeertubeLinkButton) +Button.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton) class WebTorrentButton extends Button { createEl () { @@ -227,10 +219,6 @@ class WebTorrentButton extends Button { return div } - - dispose () { - this.parentNode.removeChild(this) - } } Button.registerComponent('WebTorrentButton', WebTorrentButton) @@ -282,12 +270,12 @@ class PeerTubePlugin extends Plugin { 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) { @@ -307,7 +295,9 @@ class PeerTubePlugin extends Plugin { // 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 @@ -350,7 +340,7 @@ class PeerTubePlugin extends Plugin { this.trigger('videoFileUpdate') } - updateResolution (resolution) { + updateResolution (resolutionId: number) { // Remember player state const currentTime = this.player.currentTime() const isPaused = this.player.paused() @@ -363,7 +353,7 @@ class PeerTubePlugin extends Plugin { 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_() @@ -390,20 +380,6 @@ class PeerTubePlugin extends Plugin { } 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 {