From 6cca7360eb9027e1544f7513df7da4684061ef7e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Jun 2018 16:50:33 +0200 Subject: Reduce bundle sizes --- client/src/assets/player/peertube-link-button.ts | 1 + .../src/assets/player/peertube-videojs-plugin.ts | 17 ++++++++++----- .../src/assets/player/peertube-videojs-typings.ts | 2 +- client/src/assets/player/resolution-menu-item.ts | 1 + client/src/assets/player/settings-menu-item.ts | 1 + client/src/assets/player/utils.ts | 25 ++++++++++++++++++++++ 6 files changed, 41 insertions(+), 6 deletions(-) (limited to 'client/src/assets') diff --git a/client/src/assets/player/peertube-link-button.ts b/client/src/assets/player/peertube-link-button.ts index 26f8b9d73..715207bc0 100644 --- a/client/src/assets/player/peertube-link-button.ts +++ b/client/src/assets/player/peertube-link-button.ts @@ -1,3 +1,4 @@ +import * as videojs from 'video.js' import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' import { buildVideoLink } from './utils' diff --git a/client/src/assets/player/peertube-videojs-plugin.ts b/client/src/assets/player/peertube-videojs-plugin.ts index 9babe556a..b54f096b2 100644 --- a/client/src/assets/player/peertube-videojs-plugin.ts +++ b/client/src/assets/player/peertube-videojs-plugin.ts @@ -4,9 +4,16 @@ import { VideoFile } from '../../../../shared/models/videos/video.model' import { renderVideo } from './video-renderer' import './settings-menu-button' import { PeertubePluginOptions, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' -import { getAverageBandwidth, getStoredMute, getStoredVolume, saveAverageBandwidth, saveMuteInStore, saveVolumeInStore } from './utils' -import minBy from 'lodash-es/minBy' -import maxBy from 'lodash-es/maxBy' +import { + getAverageBandwidth, + getStoredMute, + getStoredVolume, + saveAverageBandwidth, + saveMuteInStore, + saveVolumeInStore, + videoFileMaxByResolution, + videoFileMinByResolution +} from './utils' import * as CacheChunkStore from 'cache-chunk-store' import { PeertubeChunkStore } from './peertube-chunk-store' @@ -339,9 +346,9 @@ class PeerTubePlugin extends Plugin { }) // If the download speed is too bad, return the lowest resolution we have - if (filteredFiles.length === 0) return minBy(this.videoFiles, 'resolution.id') + if (filteredFiles.length === 0) return videoFileMinByResolution(this.videoFiles) - return maxBy(filteredFiles, 'resolution.id') + return videoFileMaxByResolution(filteredFiles) } private getAndSaveActualDownloadSpeed () { diff --git a/client/src/assets/player/peertube-videojs-typings.ts b/client/src/assets/player/peertube-videojs-typings.ts index abdf333e1..50d6039ea 100644 --- a/client/src/assets/player/peertube-videojs-typings.ts +++ b/client/src/assets/player/peertube-videojs-typings.ts @@ -2,7 +2,7 @@ import * as videojs from 'video.js' import { VideoFile } from '../../../../shared/models/videos/video.model' import { PeerTubePlugin } from './peertube-videojs-plugin' -declare module 'video.js' { +declare namespace videojs { interface Player { peertube (): PeerTubePlugin } diff --git a/client/src/assets/player/resolution-menu-item.ts b/client/src/assets/player/resolution-menu-item.ts index 4b1ed0642..3fe1d8f0f 100644 --- a/client/src/assets/player/resolution-menu-item.ts +++ b/client/src/assets/player/resolution-menu-item.ts @@ -1,3 +1,4 @@ +import * as videojs from 'video.js' import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem') diff --git a/client/src/assets/player/settings-menu-item.ts b/client/src/assets/player/settings-menu-item.ts index f595fd459..88985e1ae 100644 --- a/client/src/assets/player/settings-menu-item.ts +++ b/client/src/assets/player/settings-menu-item.ts @@ -1,6 +1,7 @@ // Author: Yanko Shterev // Thanks https://github.com/yshterev/videojs-settings-menu +import * as videojs from 'video.js' import { toTitleCase } from './utils' import { VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' diff --git a/client/src/assets/player/utils.ts b/client/src/assets/player/utils.ts index ce7aaea2a..4eaf53720 100644 --- a/client/src/assets/player/utils.ts +++ b/client/src/assets/player/utils.ts @@ -1,4 +1,5 @@ import { is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n' +import { VideoFile } from '../../../../shared/models/videos' function toTitleCase (str: string) { return str.charAt(0).toUpperCase() + str.slice(1) @@ -97,6 +98,28 @@ function copyToClipboard (text: string) { document.body.removeChild(el) } +function videoFileMaxByResolution (files: VideoFile[]) { + let max = files[0] + + for (let i = 1; i < files.length; i++) { + const file = files[i] + if (max.resolution.id < file.resolution.id) max = file + } + + return max +} + +function videoFileMinByResolution (files: VideoFile[]) { + let min = files[0] + + for (let i = 1; i < files.length; i++) { + const file = files[i] + if (min.resolution.id > file.resolution.id) min = file + } + + return min +} + export { toTitleCase, buildVideoLink, @@ -107,6 +130,8 @@ export { saveMuteInStore, buildVideoEmbed, getStoredMute, + videoFileMaxByResolution, + videoFileMinByResolution, copyToClipboard, isMobile, bytes -- cgit v1.2.3