From 57d6503286b114fee61b5e4725825e2490dcac29 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 14 Mar 2022 14:28:20 +0100 Subject: [PATCH] Reorganize player files --- .../video-block-list.component.ts | 2 +- .../video-upload.component.ts | 2 +- .../information/privacy-concerns.component.ts | 2 +- .../+video-watch/video-watch.component.ts | 11 ++-- .../embed-markup.component.ts | 2 +- .../shared-main/video/embed.component.ts | 2 +- .../video-share.component.ts | 2 +- client/src/assets/player/index.ts | 2 +- .../assets/player/peertube-player-manager.ts | 59 ++++++++--------- .../{ => shared}/bezels/bezels-plugin.ts | 0 .../src/assets/player/shared/bezels/index.ts | 2 + .../player/{ => shared}/bezels/pause-bezel.ts | 2 +- .../src/assets/player/shared/common/index.ts | 1 + .../src/assets/player/shared/common/utils.ts | 66 +++++++++++++++++++ .../assets/player/shared/control-bar/index.ts | 5 ++ .../control-bar/next-previous-video-button.ts | 2 +- .../control-bar/p2p-info-button.ts | 4 +- .../control-bar/peertube-link-button.ts | 2 +- .../control-bar/peertube-load-progress-bar.ts | 0 .../control-bar/theater-button.ts | 2 +- client/src/assets/player/shared/dock/index.ts | 2 + .../dock/peertube-dock-component.ts | 0 .../{ => shared}/dock/peertube-dock-plugin.ts | 0 .../src/assets/player/shared/hotkeys/index.ts | 1 + .../hotkeys/peertube-hotkeys-plugin.ts | 0 .../control-bar-options-builder.ts | 11 +++- .../manager-options/hls-options-builder.ts | 8 +-- .../player/shared/manager-options/index.ts | 1 + .../manager-options-builder.ts | 9 +-- .../webtorrent-options-builder.ts | 2 +- .../src/assets/player/shared/mobile/index.ts | 2 + .../mobile/peertube-mobile-buttons.ts | 0 .../mobile/peertube-mobile-plugin.ts | 0 .../p2p-media-loader/hls-plugin.ts | 2 +- .../player/shared/p2p-media-loader/index.ts | 5 ++ .../p2p-media-loader-plugin.ts | 2 +- .../redundancy-url-manager.ts | 0 .../p2p-media-loader/segment-url-builder.ts | 0 .../p2p-media-loader/segment-validator.ts | 0 .../assets/player/shared/peertube/index.ts | 1 + .../{ => shared/peertube}/peertube-plugin.ts | 8 +-- .../assets/player/shared/playlist/index.ts | 4 ++ .../{ => shared}/playlist/playlist-button.ts | 2 +- .../playlist/playlist-menu-item.ts | 2 +- .../{ => shared}/playlist/playlist-menu.ts | 2 +- .../{ => shared}/playlist/playlist-plugin.ts | 4 +- .../assets/player/shared/resolutions/index.ts | 1 + .../peertube-resolutions-plugin.ts | 2 +- .../assets/player/shared/settings/index.ts | 7 ++ .../settings/resolution-menu-button.ts | 0 .../settings/resolution-menu-item.ts | 0 .../{ => shared}/settings/settings-dialog.ts | 0 .../settings/settings-menu-button.ts | 6 +- .../settings/settings-menu-item.ts | 3 +- .../settings/settings-panel-child.ts | 0 .../{ => shared}/settings/settings-panel.ts | 0 .../src/assets/player/shared/stats/index.ts | 2 + .../player/{ => shared}/stats/stats-card.ts | 4 +- .../player/{ => shared}/stats/stats-plugin.ts | 0 .../player/{ => shared}/upnext/end-card.ts | 0 .../src/assets/player/shared/upnext/index.ts | 2 + .../{ => shared}/upnext/upnext-plugin.ts | 0 .../webtorrent/peertube-chunk-store.ts | 0 .../{ => shared}/webtorrent/video-renderer.ts | 0 .../webtorrent/webtorrent-plugin.ts | 7 +- client/src/assets/player/types/index.ts | 2 + .../manager-options.ts} | 2 +- .../{ => types}/peertube-videojs-typings.ts | 24 +++---- client/src/root-helpers/index.ts | 3 +- client/src/root-helpers/video.ts | 33 ++++++++++ client/src/root-helpers/web-browser.ts | 24 +++++++ client/src/standalone/videos/embed.ts | 9 ++- 72 files changed, 267 insertions(+), 102 deletions(-) rename client/src/assets/player/{ => shared}/bezels/bezels-plugin.ts (100%) create mode 100644 client/src/assets/player/shared/bezels/index.ts rename client/src/assets/player/{ => shared}/bezels/pause-bezel.ts (97%) create mode 100644 client/src/assets/player/shared/common/index.ts create mode 100644 client/src/assets/player/shared/common/utils.ts create mode 100644 client/src/assets/player/shared/control-bar/index.ts rename client/src/assets/player/{ => shared}/control-bar/next-previous-video-button.ts (94%) rename client/src/assets/player/{ => shared}/control-bar/p2p-info-button.ts (98%) rename client/src/assets/player/{ => shared}/control-bar/peertube-link-button.ts (94%) rename client/src/assets/player/{ => shared}/control-bar/peertube-load-progress-bar.ts (100%) rename client/src/assets/player/{ => shared}/control-bar/theater-button.ts (93%) create mode 100644 client/src/assets/player/shared/dock/index.ts rename client/src/assets/player/{ => shared}/dock/peertube-dock-component.ts (100%) rename client/src/assets/player/{ => shared}/dock/peertube-dock-plugin.ts (100%) create mode 100644 client/src/assets/player/shared/hotkeys/index.ts rename client/src/assets/player/{ => shared}/hotkeys/peertube-hotkeys-plugin.ts (100%) rename client/src/assets/player/{ => shared}/manager-options/control-bar-options-builder.ts (91%) rename client/src/assets/player/{ => shared}/manager-options/hls-options-builder.ts (96%) create mode 100644 client/src/assets/player/shared/manager-options/index.ts rename client/src/assets/player/{ => shared}/manager-options/manager-options-builder.ts (95%) rename client/src/assets/player/{ => shared}/manager-options/webtorrent-options-builder.ts (92%) create mode 100644 client/src/assets/player/shared/mobile/index.ts rename client/src/assets/player/{ => shared}/mobile/peertube-mobile-buttons.ts (100%) rename client/src/assets/player/{ => shared}/mobile/peertube-mobile-plugin.ts (100%) rename client/src/assets/player/{ => shared}/p2p-media-loader/hls-plugin.ts (99%) create mode 100644 client/src/assets/player/shared/p2p-media-loader/index.ts rename client/src/assets/player/{ => shared}/p2p-media-loader/p2p-media-loader-plugin.ts (99%) rename client/src/assets/player/{ => shared}/p2p-media-loader/redundancy-url-manager.ts (100%) rename client/src/assets/player/{ => shared}/p2p-media-loader/segment-url-builder.ts (100%) rename client/src/assets/player/{ => shared}/p2p-media-loader/segment-validator.ts (100%) create mode 100644 client/src/assets/player/shared/peertube/index.ts rename client/src/assets/player/{ => shared/peertube}/peertube-plugin.ts (97%) create mode 100644 client/src/assets/player/shared/playlist/index.ts rename client/src/assets/player/{ => shared}/playlist/playlist-button.ts (95%) rename client/src/assets/player/{ => shared}/playlist/playlist-menu-item.ts (98%) rename client/src/assets/player/{ => shared}/playlist/playlist-menu.ts (97%) rename client/src/assets/player/{ => shared}/playlist/playlist-plugin.ts (82%) create mode 100644 client/src/assets/player/shared/resolutions/index.ts rename client/src/assets/player/{ => shared/resolutions}/peertube-resolutions-plugin.ts (96%) create mode 100644 client/src/assets/player/shared/settings/index.ts rename client/src/assets/player/{ => shared}/settings/resolution-menu-button.ts (100%) rename client/src/assets/player/{ => shared}/settings/resolution-menu-item.ts (100%) rename client/src/assets/player/{ => shared}/settings/settings-dialog.ts (100%) rename client/src/assets/player/{ => shared}/settings/settings-menu-button.ts (98%) rename client/src/assets/player/{ => shared}/settings/settings-menu-item.ts (98%) rename client/src/assets/player/{ => shared}/settings/settings-panel-child.ts (100%) rename client/src/assets/player/{ => shared}/settings/settings-panel.ts (100%) create mode 100644 client/src/assets/player/shared/stats/index.ts rename client/src/assets/player/{ => shared}/stats/stats-card.ts (99%) rename client/src/assets/player/{ => shared}/stats/stats-plugin.ts (100%) rename client/src/assets/player/{ => shared}/upnext/end-card.ts (100%) create mode 100644 client/src/assets/player/shared/upnext/index.ts rename client/src/assets/player/{ => shared}/upnext/upnext-plugin.ts (100%) rename client/src/assets/player/{ => shared}/webtorrent/peertube-chunk-store.ts (100%) rename client/src/assets/player/{ => shared}/webtorrent/video-renderer.ts (100%) rename client/src/assets/player/{ => shared}/webtorrent/webtorrent-plugin.ts (98%) create mode 100644 client/src/assets/player/types/index.ts rename client/src/assets/player/{manager-options/manager-options.model.ts => types/manager-options.ts} (98%) rename client/src/assets/player/{ => types}/peertube-videojs-typings.ts (82%) create mode 100644 client/src/root-helpers/video.ts create mode 100644 client/src/root-helpers/web-browser.ts diff --git a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts index 67752c15a..033305a2b 100644 --- a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts +++ b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts @@ -1,6 +1,5 @@ import { SortMeta } from 'primeng/api' import { switchMap } from 'rxjs/operators' -import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' import { environment } from 'src/environments/environment' import { Component, OnInit } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' @@ -8,6 +7,7 @@ import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, S import { AdvancedInputFilter } from '@app/shared/shared-forms' import { DropdownAction, VideoService } from '@app/shared/shared-main' import { VideoBlockService } from '@app/shared/shared-moderation' +import { buildVideoOrPlaylistEmbed } from '@root-helpers/video' import { buildVideoEmbedLink, decorateVideoLink } from '@shared/core-utils' import { VideoBlacklist, VideoBlacklistType } from '@shared/models' diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts index fb6f2601b..5655e48da 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts @@ -1,6 +1,6 @@ import { truncate } from 'lodash-es' import { UploadState, UploadxOptions, UploadxService } from 'ngx-uploadx' -import { isIOS } from 'src/assets/player/utils' +import { isIOS } from '@root-helpers/web-browser' import { HttpErrorResponse, HttpEventType, HttpHeaders } from '@angular/common/http' import { AfterViewInit, Component, ElementRef, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' import { Router } from '@angular/router' diff --git a/client/src/app/+videos/+video-watch/shared/information/privacy-concerns.component.ts b/client/src/app/+videos/+video-watch/shared/information/privacy-concerns.component.ts index 24030df3e..b51457e02 100644 --- a/client/src/app/+videos/+video-watch/shared/information/privacy-concerns.component.ts +++ b/client/src/app/+videos/+video-watch/shared/information/privacy-concerns.component.ts @@ -1,8 +1,8 @@ import { Component, Input, OnInit } from '@angular/core' import { ServerService, User, UserService } from '@app/core' import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' +import { isP2PEnabled } from '@root-helpers/video' import { HTMLServerConfig, Video } from '@shared/models' -import { isP2PEnabled } from '../../../../../assets/player/utils' @Component({ selector: 'my-privacy-concerns', diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts index 067d3bc84..f13c885f2 100644 --- a/client/src/app/+videos/+video-watch/video-watch.component.ts +++ b/client/src/app/+videos/+video-watch/video-watch.component.ts @@ -1,6 +1,6 @@ import { Hotkey, HotkeysService } from 'angular2-hotkeys' import { forkJoin, map, Observable, of, Subscription, switchMap } from 'rxjs' -import { isP2PEnabled } from 'src/assets/player/utils' +import { VideoJsPlayer } from 'video.js' import { PlatformLocation } from '@angular/common' import { Component, ElementRef, Inject, LOCALE_ID, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' @@ -24,6 +24,7 @@ import { Video, VideoCaptionService, VideoDetails, VideoService } from '@app/sha import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription' import { LiveVideoService } from '@app/shared/shared-video-live' import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' +import { isP2PEnabled } from '@root-helpers/video' import { timeToInt } from '@shared/core-utils' import { HTMLServerConfig, @@ -58,7 +59,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { @ViewChild('videoWatchPlaylist', { static: true }) videoWatchPlaylist: VideoWatchPlaylistComponent @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent - player: any + player: VideoJsPlayer playerElement: HTMLVideoElement playerPlaceholderImgSrc: string theaterEnabled = false @@ -418,8 +419,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.zone.runOutsideAngular(async () => { this.player = await PeertubePlayerManager.initialize(playerMode, playerOptions, player => this.player = player) - this.player.on('customError', ({ err }: { err: any }) => { - this.zone.run(() => this.handleGlobalError(err)) + this.player.on('customError', (_e, data: any) => { + this.zone.run(() => this.handleGlobalError(data.err)) }) this.player.on('timeupdate', () => { @@ -458,7 +459,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { suspended: () => { return ( - !isXPercentInViewport(this.player.el(), 80) || + !isXPercentInViewport(this.player.el() as HTMLElement, 80) || !document.getElementById('content').contains(document.activeElement) ) } diff --git a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/embed-markup.component.ts b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/embed-markup.component.ts index 53b70cc47..955b0af18 100644 --- a/client/src/app/shared/shared-custom-markup/peertube-custom-tags/embed-markup.component.ts +++ b/client/src/app/shared/shared-custom-markup/peertube-custom-tags/embed-markup.component.ts @@ -1,6 +1,6 @@ -import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' import { environment } from 'src/environments/environment' import { Component, ElementRef, Input, OnInit } from '@angular/core' +import { buildVideoOrPlaylistEmbed } from '@root-helpers/video' import { buildPlaylistEmbedLink, buildVideoEmbedLink } from '@shared/core-utils' import { CustomMarkupComponent } from './shared' diff --git a/client/src/app/shared/shared-main/video/embed.component.ts b/client/src/app/shared/shared-main/video/embed.component.ts index 4732efa44..123000834 100644 --- a/client/src/app/shared/shared-main/video/embed.component.ts +++ b/client/src/app/shared/shared-main/video/embed.component.ts @@ -1,7 +1,7 @@ -import { buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' import { environment } from 'src/environments/environment' import { Component, Input, OnInit } from '@angular/core' import { DomSanitizer, SafeHtml } from '@angular/platform-browser' +import { buildVideoOrPlaylistEmbed } from '@root-helpers/video' import { buildVideoEmbedLink, decorateVideoLink } from '@shared/core-utils' import { Video } from '@shared/models' diff --git a/client/src/app/shared/shared-share-modal/video-share.component.ts b/client/src/app/shared/shared-share-modal/video-share.component.ts index 36a4d7520..2346f03e4 100644 --- a/client/src/app/shared/shared-share-modal/video-share.component.ts +++ b/client/src/app/shared/shared-share-modal/video-share.component.ts @@ -4,9 +4,9 @@ import { ServerService } from '@app/core' import { VideoDetails } from '@app/shared/shared-main' import { VideoPlaylist } from '@app/shared/shared-video-playlist' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' +import { buildVideoOrPlaylistEmbed } from '@root-helpers/video' import { buildPlaylistLink, buildVideoLink, decoratePlaylistLink, decorateVideoLink } from '@shared/core-utils' import { VideoCaption, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' -import { buildVideoOrPlaylistEmbed } from '../../../assets/player/utils' type Customizations = { startAtCheckbox: boolean diff --git a/client/src/assets/player/index.ts b/client/src/assets/player/index.ts index 92270476d..9b87afc4a 100644 --- a/client/src/assets/player/index.ts +++ b/client/src/assets/player/index.ts @@ -1,2 +1,2 @@ export * from './peertube-player-manager' -export * from './manager-options/manager-options.model' +export * from './types' diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts index ddb521a52..1b2a67c77 100644 --- a/client/src/assets/player/peertube-player-manager.ts +++ b/client/src/assets/player/peertube-player-manager.ts @@ -1,35 +1,34 @@ import '@peertube/videojs-contextmenu' -import './upnext/end-card' -import './upnext/upnext-plugin' -import './stats/stats-card' -import './stats/stats-plugin' -import './bezels/bezels-plugin' -import './peertube-plugin' -import './peertube-resolutions-plugin' -import './control-bar/next-previous-video-button' -import './control-bar/p2p-info-button' -import './control-bar/peertube-link-button' -import './control-bar/peertube-load-progress-bar' -import './control-bar/theater-button' -import './settings/resolution-menu-button' -import './settings/resolution-menu-item' -import './settings/settings-dialog' -import './settings/settings-menu-button' -import './settings/settings-menu-item' -import './settings/settings-panel' -import './settings/settings-panel-child' -import './playlist/playlist-plugin' -import './mobile/peertube-mobile-plugin' -import './mobile/peertube-mobile-buttons' -import './hotkeys/peertube-hotkeys-plugin' +import './shared/upnext/end-card' +import './shared/upnext/upnext-plugin' +import './shared/stats/stats-card' +import './shared/stats/stats-plugin' +import './shared/bezels/bezels-plugin' +import './shared/peertube/peertube-plugin' +import './shared/resolutions/peertube-resolutions-plugin' +import './shared/control-bar/next-previous-video-button' +import './shared/control-bar/p2p-info-button' +import './shared/control-bar/peertube-link-button' +import './shared/control-bar/peertube-load-progress-bar' +import './shared/control-bar/theater-button' +import './shared/settings/resolution-menu-button' +import './shared/settings/resolution-menu-item' +import './shared/settings/settings-dialog' +import './shared/settings/settings-menu-button' +import './shared/settings/settings-menu-item' +import './shared/settings/settings-panel' +import './shared/settings/settings-panel-child' +import './shared/playlist/playlist-plugin' +import './shared/mobile/peertube-mobile-plugin' +import './shared/mobile/peertube-mobile-buttons' +import './shared/hotkeys/peertube-hotkeys-plugin' import videojs from 'video.js' import { PluginsManager } from '@root-helpers/plugins-manager' -import { ManagerOptionsBuilder } from './manager-options/manager-options-builder' -import { CommonOptions, PeertubePlayerManagerOptions, PlayerMode } from './manager-options/manager-options.model' +import { isMobile } from '@root-helpers/web-browser' import { saveAverageBandwidth } from './peertube-player-local-storage' -import { PlayerNetworkInfo } from './peertube-videojs-typings' +import { ManagerOptionsBuilder } from './shared/manager-options' import { TranslationsManager } from './translations-manager' -import { isMobile } from './utils' +import { CommonOptions, PeertubePlayerManagerOptions, PlayerMode, PlayerNetworkInfo } from './types' // Change 'Playback Rate' to 'Speed' (smaller for our settings menu) (videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed' @@ -60,11 +59,11 @@ export class PeertubePlayerManager { this.onPlayerChange = onPlayerChange this.playerElementClassName = options.common.playerElement.className - if (mode === 'webtorrent') await import('./webtorrent/webtorrent-plugin') + if (mode === 'webtorrent') await import('./shared/webtorrent/webtorrent-plugin') if (mode === 'p2p-media-loader') { const [ p2pMediaLoaderModule ] = await Promise.all([ import('@peertube/p2p-media-loader-hlsjs'), - import('./p2p-media-loader/p2p-media-loader-plugin') + import('./shared/p2p-media-loader/p2p-media-loader-plugin') ]) this.p2pMediaLoaderModule = p2pMediaLoaderModule @@ -174,7 +173,7 @@ export class PeertubePlayerManager { this.rebuildAndUpdateVideoElement(currentPlayer, options.common) - await import('./webtorrent/webtorrent-plugin') + await import('./shared/webtorrent/webtorrent-plugin') const newPlayer = await this.buildPlayer('webtorrent', options) this.onPlayerChange(newPlayer) diff --git a/client/src/assets/player/bezels/bezels-plugin.ts b/client/src/assets/player/shared/bezels/bezels-plugin.ts similarity index 100% rename from client/src/assets/player/bezels/bezels-plugin.ts rename to client/src/assets/player/shared/bezels/bezels-plugin.ts diff --git a/client/src/assets/player/shared/bezels/index.ts b/client/src/assets/player/shared/bezels/index.ts new file mode 100644 index 000000000..da861b07a --- /dev/null +++ b/client/src/assets/player/shared/bezels/index.ts @@ -0,0 +1,2 @@ +export * from './bezels-plugin' +export * from './pause-bezel' diff --git a/client/src/assets/player/bezels/pause-bezel.ts b/client/src/assets/player/shared/bezels/pause-bezel.ts similarity index 97% rename from client/src/assets/player/bezels/pause-bezel.ts rename to client/src/assets/player/shared/bezels/pause-bezel.ts index 315964311..e35c39a5f 100644 --- a/client/src/assets/player/bezels/pause-bezel.ts +++ b/client/src/assets/player/shared/bezels/pause-bezel.ts @@ -1,5 +1,5 @@ import videojs from 'video.js' -import { isMobile } from '../utils' +import { isMobile } from '@root-helpers/web-browser' function getPauseBezel () { return ` diff --git a/client/src/assets/player/shared/common/index.ts b/client/src/assets/player/shared/common/index.ts new file mode 100644 index 000000000..9c56149ef --- /dev/null +++ b/client/src/assets/player/shared/common/index.ts @@ -0,0 +1 @@ +export * from './utils' diff --git a/client/src/assets/player/shared/common/utils.ts b/client/src/assets/player/shared/common/utils.ts new file mode 100644 index 000000000..da7dda0c7 --- /dev/null +++ b/client/src/assets/player/shared/common/utils.ts @@ -0,0 +1,66 @@ +import { VideoFile } from '@shared/models' + +function toTitleCase (str: string) { + return str.charAt(0).toUpperCase() + str.slice(1) +} + +// 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: number) { + 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 ] +} + +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 +} + +function getRtcConfig () { + return { + iceServers: [ + { + urls: 'stun:stun.stunprotocol.org' + }, + { + urls: 'stun:stun.framasoft.org' + } + ] + } +} + +// --------------------------------------------------------------------------- + +export { + getRtcConfig, + toTitleCase, + + videoFileMaxByResolution, + videoFileMinByResolution, + bytes +} diff --git a/client/src/assets/player/shared/control-bar/index.ts b/client/src/assets/player/shared/control-bar/index.ts new file mode 100644 index 000000000..db5b8938d --- /dev/null +++ b/client/src/assets/player/shared/control-bar/index.ts @@ -0,0 +1,5 @@ +export * from './next-previous-video-button' +export * from './p2p-info-button' +export * from './peertube-link-button' +export * from './peertube-load-progress-bar' +export * from './theater-button' diff --git a/client/src/assets/player/control-bar/next-previous-video-button.ts b/client/src/assets/player/shared/control-bar/next-previous-video-button.ts similarity index 94% rename from client/src/assets/player/control-bar/next-previous-video-button.ts rename to client/src/assets/player/shared/control-bar/next-previous-video-button.ts index fe17ce2ce..b7b986806 100644 --- a/client/src/assets/player/control-bar/next-previous-video-button.ts +++ b/client/src/assets/player/shared/control-bar/next-previous-video-button.ts @@ -1,5 +1,5 @@ import videojs from 'video.js' -import { NextPreviousVideoButtonOptions } from '../peertube-videojs-typings' +import { NextPreviousVideoButtonOptions } from '../../types' const Button = videojs.getComponent('Button') diff --git a/client/src/assets/player/control-bar/p2p-info-button.ts b/client/src/assets/player/shared/control-bar/p2p-info-button.ts similarity index 98% rename from client/src/assets/player/control-bar/p2p-info-button.ts rename to client/src/assets/player/shared/control-bar/p2p-info-button.ts index 081dee1d3..36517e125 100644 --- a/client/src/assets/player/control-bar/p2p-info-button.ts +++ b/client/src/assets/player/shared/control-bar/p2p-info-button.ts @@ -1,6 +1,6 @@ import videojs from 'video.js' -import { PeerTubeP2PInfoButtonOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' -import { bytes } from '../utils' +import { PeerTubeP2PInfoButtonOptions, PlayerNetworkInfo } from '../../types' +import { bytes } from '../common' const Button = videojs.getComponent('Button') class P2pInfoButton extends Button { diff --git a/client/src/assets/player/control-bar/peertube-link-button.ts b/client/src/assets/player/shared/control-bar/peertube-link-button.ts similarity index 94% rename from client/src/assets/player/control-bar/peertube-link-button.ts rename to client/src/assets/player/shared/control-bar/peertube-link-button.ts index c49cee566..6d83263cc 100644 --- a/client/src/assets/player/control-bar/peertube-link-button.ts +++ b/client/src/assets/player/shared/control-bar/peertube-link-button.ts @@ -1,6 +1,6 @@ import videojs from 'video.js' import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' -import { PeerTubeLinkButtonOptions } from '../peertube-videojs-typings' +import { PeerTubeLinkButtonOptions } from '../../types' const Button = videojs.getComponent('Button') class PeerTubeLinkButton extends Button { diff --git a/client/src/assets/player/control-bar/peertube-load-progress-bar.ts b/client/src/assets/player/shared/control-bar/peertube-load-progress-bar.ts similarity index 100% rename from client/src/assets/player/control-bar/peertube-load-progress-bar.ts rename to client/src/assets/player/shared/control-bar/peertube-load-progress-bar.ts diff --git a/client/src/assets/player/control-bar/theater-button.ts b/client/src/assets/player/shared/control-bar/theater-button.ts similarity index 93% rename from client/src/assets/player/control-bar/theater-button.ts rename to client/src/assets/player/shared/control-bar/theater-button.ts index f862ee224..56c349d6b 100644 --- a/client/src/assets/player/control-bar/theater-button.ts +++ b/client/src/assets/player/shared/control-bar/theater-button.ts @@ -1,5 +1,5 @@ import videojs from 'video.js' -import { saveTheaterInStore, getStoredTheater } from '../peertube-player-local-storage' +import { getStoredTheater, saveTheaterInStore } from '../../peertube-player-local-storage' const Button = videojs.getComponent('Button') class TheaterButton extends Button { diff --git a/client/src/assets/player/shared/dock/index.ts b/client/src/assets/player/shared/dock/index.ts new file mode 100644 index 000000000..16e70a9c1 --- /dev/null +++ b/client/src/assets/player/shared/dock/index.ts @@ -0,0 +1,2 @@ +export * from './peertube-dock-component' +export * from './peertube-dock-plugin' diff --git a/client/src/assets/player/dock/peertube-dock-component.ts b/client/src/assets/player/shared/dock/peertube-dock-component.ts similarity index 100% rename from client/src/assets/player/dock/peertube-dock-component.ts rename to client/src/assets/player/shared/dock/peertube-dock-component.ts diff --git a/client/src/assets/player/dock/peertube-dock-plugin.ts b/client/src/assets/player/shared/dock/peertube-dock-plugin.ts similarity index 100% rename from client/src/assets/player/dock/peertube-dock-plugin.ts rename to client/src/assets/player/shared/dock/peertube-dock-plugin.ts diff --git a/client/src/assets/player/shared/hotkeys/index.ts b/client/src/assets/player/shared/hotkeys/index.ts new file mode 100644 index 000000000..cc99a1ea8 --- /dev/null +++ b/client/src/assets/player/shared/hotkeys/index.ts @@ -0,0 +1 @@ +export * from './peertube-hotkeys-plugin' diff --git a/client/src/assets/player/hotkeys/peertube-hotkeys-plugin.ts b/client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts similarity index 100% rename from client/src/assets/player/hotkeys/peertube-hotkeys-plugin.ts rename to client/src/assets/player/shared/hotkeys/peertube-hotkeys-plugin.ts diff --git a/client/src/assets/player/manager-options/control-bar-options-builder.ts b/client/src/assets/player/shared/manager-options/control-bar-options-builder.ts similarity index 91% rename from client/src/assets/player/manager-options/control-bar-options-builder.ts rename to client/src/assets/player/shared/manager-options/control-bar-options-builder.ts index 54e61c5d0..72a10eb26 100644 --- a/client/src/assets/player/manager-options/control-bar-options-builder.ts +++ b/client/src/assets/player/shared/manager-options/control-bar-options-builder.ts @@ -1,5 +1,10 @@ -import { NextPreviousVideoButtonOptions, PeerTubeLinkButtonOptions } from '../peertube-videojs-typings' -import { CommonOptions, PeertubePlayerManagerOptions, PlayerMode } from './manager-options.model' +import { + CommonOptions, + NextPreviousVideoButtonOptions, + PeerTubeLinkButtonOptions, + PeertubePlayerManagerOptions, + PlayerMode +} from '../../types' export class ControlBarOptionsBuilder { private options: CommonOptions @@ -41,7 +46,7 @@ export class ControlBarOptionsBuilder { muteToggle: {}, volumeControl: {}, - settingsButton: this.getSettingsButton() + ...this.getSettingsButton() }) if (this.options.peertubeLink === true) { diff --git a/client/src/assets/player/manager-options/hls-options-builder.ts b/client/src/assets/player/shared/manager-options/hls-options-builder.ts similarity index 96% rename from client/src/assets/player/manager-options/hls-options-builder.ts rename to client/src/assets/player/shared/manager-options/hls-options-builder.ts index 9de23561b..e7f664fd4 100644 --- a/client/src/assets/player/manager-options/hls-options-builder.ts +++ b/client/src/assets/player/shared/manager-options/hls-options-builder.ts @@ -1,13 +1,13 @@ import { HybridLoaderSettings } from '@peertube/p2p-media-loader-core' import { HlsJsEngineSettings } from '@peertube/p2p-media-loader-hlsjs' import { LiveVideoLatencyMode } from '@shared/models' +import { getAverageBandwidthInStore } from '../../peertube-player-local-storage' +import { P2PMediaLoader, P2PMediaLoaderPluginOptions } from '../../types' +import { PeertubePlayerManagerOptions } from '../../types/manager-options' +import { getRtcConfig } from '../common' import { RedundancyUrlManager } from '../p2p-media-loader/redundancy-url-manager' import { segmentUrlBuilderFactory } from '../p2p-media-loader/segment-url-builder' import { segmentValidatorFactory } from '../p2p-media-loader/segment-validator' -import { getAverageBandwidthInStore } from '../peertube-player-local-storage' -import { P2PMediaLoader, P2PMediaLoaderPluginOptions } from '../peertube-videojs-typings' -import { getRtcConfig } from '../utils' -import { PeertubePlayerManagerOptions } from './manager-options.model' export class HLSOptionsBuilder { diff --git a/client/src/assets/player/shared/manager-options/index.ts b/client/src/assets/player/shared/manager-options/index.ts new file mode 100644 index 000000000..4934d8302 --- /dev/null +++ b/client/src/assets/player/shared/manager-options/index.ts @@ -0,0 +1 @@ +export * from './manager-options-builder' diff --git a/client/src/assets/player/manager-options/manager-options-builder.ts b/client/src/assets/player/shared/manager-options/manager-options-builder.ts similarity index 95% rename from client/src/assets/player/manager-options/manager-options-builder.ts rename to client/src/assets/player/shared/manager-options/manager-options-builder.ts index 14bdb5d96..5dab1f7a9 100644 --- a/client/src/assets/player/manager-options/manager-options-builder.ts +++ b/client/src/assets/player/shared/manager-options/manager-options-builder.ts @@ -1,12 +1,13 @@ import videojs from 'video.js' +import { copyToClipboard } from '@root-helpers/utils' +import { buildVideoOrPlaylistEmbed } from '@root-helpers/video' +import { isIOS, isSafari } from '@root-helpers/web-browser' import { buildVideoLink, decorateVideoLink } from '@shared/core-utils' import { isDefaultLocale } from '@shared/core-utils/i18n' -import { copyToClipboard } from '../../../root-helpers/utils' -import { VideoJSPluginOptions } from '../peertube-videojs-typings' -import { buildVideoOrPlaylistEmbed, isIOS, isSafari } from '../utils' +import { VideoJSPluginOptions } from '../../types' +import { CommonOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../types/manager-options' import { ControlBarOptionsBuilder } from './control-bar-options-builder' import { HLSOptionsBuilder } from './hls-options-builder' -import { CommonOptions, PeertubePlayerManagerOptions, PlayerMode } from './manager-options.model' import { WebTorrentOptionsBuilder } from './webtorrent-options-builder' export class ManagerOptionsBuilder { diff --git a/client/src/assets/player/manager-options/webtorrent-options-builder.ts b/client/src/assets/player/shared/manager-options/webtorrent-options-builder.ts similarity index 92% rename from client/src/assets/player/manager-options/webtorrent-options-builder.ts rename to client/src/assets/player/shared/manager-options/webtorrent-options-builder.ts index 303940b29..257cf1e05 100644 --- a/client/src/assets/player/manager-options/webtorrent-options-builder.ts +++ b/client/src/assets/player/shared/manager-options/webtorrent-options-builder.ts @@ -1,4 +1,4 @@ -import { PeertubePlayerManagerOptions } from './manager-options.model' +import { PeertubePlayerManagerOptions } from '../../types' export class WebTorrentOptionsBuilder { diff --git a/client/src/assets/player/shared/mobile/index.ts b/client/src/assets/player/shared/mobile/index.ts new file mode 100644 index 000000000..6f42b8db7 --- /dev/null +++ b/client/src/assets/player/shared/mobile/index.ts @@ -0,0 +1,2 @@ +export * from './peertube-mobile-buttons' +export * from './peertube-mobile-plugin' diff --git a/client/src/assets/player/mobile/peertube-mobile-buttons.ts b/client/src/assets/player/shared/mobile/peertube-mobile-buttons.ts similarity index 100% rename from client/src/assets/player/mobile/peertube-mobile-buttons.ts rename to client/src/assets/player/shared/mobile/peertube-mobile-buttons.ts diff --git a/client/src/assets/player/mobile/peertube-mobile-plugin.ts b/client/src/assets/player/shared/mobile/peertube-mobile-plugin.ts similarity index 100% rename from client/src/assets/player/mobile/peertube-mobile-plugin.ts rename to client/src/assets/player/shared/mobile/peertube-mobile-plugin.ts diff --git a/client/src/assets/player/p2p-media-loader/hls-plugin.ts b/client/src/assets/player/shared/p2p-media-loader/hls-plugin.ts similarity index 99% rename from client/src/assets/player/p2p-media-loader/hls-plugin.ts rename to client/src/assets/player/shared/p2p-media-loader/hls-plugin.ts index ccee2d90f..d0105fa36 100644 --- a/client/src/assets/player/p2p-media-loader/hls-plugin.ts +++ b/client/src/assets/player/shared/p2p-media-loader/hls-plugin.ts @@ -3,7 +3,7 @@ import Hlsjs, { ErrorData, HlsConfig, Level, LevelSwitchingData, ManifestParsedData } from 'hls.js' import videojs from 'video.js' -import { HlsjsConfigHandlerOptions, PeerTubeResolution, VideoJSTechHLS } from '../peertube-videojs-typings' +import { HlsjsConfigHandlerOptions, PeerTubeResolution, VideoJSTechHLS } from '../../types' type ErrorCounts = { [ type: string ]: number diff --git a/client/src/assets/player/shared/p2p-media-loader/index.ts b/client/src/assets/player/shared/p2p-media-loader/index.ts new file mode 100644 index 000000000..02fe71e73 --- /dev/null +++ b/client/src/assets/player/shared/p2p-media-loader/index.ts @@ -0,0 +1,5 @@ +export * from './hls-plugin' +export * from './p2p-media-loader-plugin' +export * from './redundancy-url-manager' +export * from './segment-url-builder' +export * from './segment-validator' diff --git a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts b/client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts similarity index 99% rename from client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts rename to client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts index 1d7a39b4e..5c0f0021f 100644 --- a/client/src/assets/player/p2p-media-loader/p2p-media-loader-plugin.ts +++ b/client/src/assets/player/shared/p2p-media-loader/p2p-media-loader-plugin.ts @@ -3,7 +3,7 @@ import videojs from 'video.js' import { Events, Segment } from '@peertube/p2p-media-loader-core' import { Engine, initHlsJsPlayer, initVideoJsContribHlsJsPlayer } from '@peertube/p2p-media-loader-hlsjs' import { timeToInt } from '@shared/core-utils' -import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../peertube-videojs-typings' +import { P2PMediaLoaderPluginOptions, PlayerNetworkInfo } from '../../types' import { registerConfigPlugin, registerSourceHandler } from './hls-plugin' registerConfigPlugin(videojs) diff --git a/client/src/assets/player/p2p-media-loader/redundancy-url-manager.ts b/client/src/assets/player/shared/p2p-media-loader/redundancy-url-manager.ts similarity index 100% rename from client/src/assets/player/p2p-media-loader/redundancy-url-manager.ts rename to client/src/assets/player/shared/p2p-media-loader/redundancy-url-manager.ts diff --git a/client/src/assets/player/p2p-media-loader/segment-url-builder.ts b/client/src/assets/player/shared/p2p-media-loader/segment-url-builder.ts similarity index 100% rename from client/src/assets/player/p2p-media-loader/segment-url-builder.ts rename to client/src/assets/player/shared/p2p-media-loader/segment-url-builder.ts diff --git a/client/src/assets/player/p2p-media-loader/segment-validator.ts b/client/src/assets/player/shared/p2p-media-loader/segment-validator.ts similarity index 100% rename from client/src/assets/player/p2p-media-loader/segment-validator.ts rename to client/src/assets/player/shared/p2p-media-loader/segment-validator.ts diff --git a/client/src/assets/player/shared/peertube/index.ts b/client/src/assets/player/shared/peertube/index.ts new file mode 100644 index 000000000..ff4d5241b --- /dev/null +++ b/client/src/assets/player/shared/peertube/index.ts @@ -0,0 +1 @@ +export * from './peertube-plugin' diff --git a/client/src/assets/player/peertube-plugin.ts b/client/src/assets/player/shared/peertube/peertube-plugin.ts similarity index 97% rename from client/src/assets/player/peertube-plugin.ts rename to client/src/assets/player/shared/peertube/peertube-plugin.ts index 4ffc9ce3e..1dc3e3de0 100644 --- a/client/src/assets/player/peertube-plugin.ts +++ b/client/src/assets/player/shared/peertube/peertube-plugin.ts @@ -1,5 +1,6 @@ import debug from 'debug' import videojs from 'video.js' +import { isMobile } from '@root-helpers/web-browser' import { timeToInt } from '@shared/core-utils' import { getStoredLastSubtitle, @@ -9,10 +10,9 @@ import { saveMuteInStore, saveVideoWatchHistory, saveVolumeInStore -} from './peertube-player-local-storage' -import { PeerTubePluginOptions, UserWatching, VideoJSCaption } from './peertube-videojs-typings' -import { SettingsButton } from './settings/settings-menu-button' -import { isMobile } from './utils' +} from '../../peertube-player-local-storage' +import { PeerTubePluginOptions, UserWatching, VideoJSCaption } from '../../types' +import { SettingsButton } from '../settings/settings-menu-button' const logger = debug('peertube:player:peertube') diff --git a/client/src/assets/player/shared/playlist/index.ts b/client/src/assets/player/shared/playlist/index.ts new file mode 100644 index 000000000..0be6e4d3c --- /dev/null +++ b/client/src/assets/player/shared/playlist/index.ts @@ -0,0 +1,4 @@ +export * from './playlist-button' +export * from './playlist-menu-item' +export * from './playlist-menu' +export * from './playlist-plugin' diff --git a/client/src/assets/player/playlist/playlist-button.ts b/client/src/assets/player/shared/playlist/playlist-button.ts similarity index 95% rename from client/src/assets/player/playlist/playlist-button.ts rename to client/src/assets/player/shared/playlist/playlist-button.ts index a7996ec60..6cfaf4158 100644 --- a/client/src/assets/player/playlist/playlist-button.ts +++ b/client/src/assets/player/shared/playlist/playlist-button.ts @@ -1,5 +1,5 @@ import videojs from 'video.js' -import { PlaylistPluginOptions } from '../peertube-videojs-typings' +import { PlaylistPluginOptions } from '../../types' import { PlaylistMenu } from './playlist-menu' const ClickableComponent = videojs.getComponent('ClickableComponent') diff --git a/client/src/assets/player/playlist/playlist-menu-item.ts b/client/src/assets/player/shared/playlist/playlist-menu-item.ts similarity index 98% rename from client/src/assets/player/playlist/playlist-menu-item.ts rename to client/src/assets/player/shared/playlist/playlist-menu-item.ts index 2519a34c7..81b5acf30 100644 --- a/client/src/assets/player/playlist/playlist-menu-item.ts +++ b/client/src/assets/player/shared/playlist/playlist-menu-item.ts @@ -1,7 +1,7 @@ import videojs from 'video.js' import { secondsToTime } from '@shared/core-utils' import { VideoPlaylistElement } from '@shared/models' -import { PlaylistItemOptions } from '../peertube-videojs-typings' +import { PlaylistItemOptions } from '../../types' const Component = videojs.getComponent('Component') diff --git a/client/src/assets/player/playlist/playlist-menu.ts b/client/src/assets/player/shared/playlist/playlist-menu.ts similarity index 97% rename from client/src/assets/player/playlist/playlist-menu.ts rename to client/src/assets/player/shared/playlist/playlist-menu.ts index a2583047b..1ec9ac804 100644 --- a/client/src/assets/player/playlist/playlist-menu.ts +++ b/client/src/assets/player/shared/playlist/playlist-menu.ts @@ -1,6 +1,6 @@ import videojs from 'video.js' import { VideoPlaylistElement } from '@shared/models' -import { PlaylistPluginOptions } from '../peertube-videojs-typings' +import { PlaylistPluginOptions } from '../../types' import { PlaylistMenuItem } from './playlist-menu-item' const Component = videojs.getComponent('Component') diff --git a/client/src/assets/player/playlist/playlist-plugin.ts b/client/src/assets/player/shared/playlist/playlist-plugin.ts similarity index 82% rename from client/src/assets/player/playlist/playlist-plugin.ts rename to client/src/assets/player/shared/playlist/playlist-plugin.ts index b69d82e3c..44de0da5a 100644 --- a/client/src/assets/player/playlist/playlist-plugin.ts +++ b/client/src/assets/player/shared/playlist/playlist-plugin.ts @@ -1,5 +1,5 @@ import videojs from 'video.js' -import { PlaylistPluginOptions } from '../peertube-videojs-typings' +import { PlaylistPluginOptions } from '../../types' import { PlaylistButton } from './playlist-button' import { PlaylistMenu } from './playlist-menu' @@ -20,7 +20,7 @@ class PlaylistPlugin extends Plugin { }) this.playlistMenu = new PlaylistMenu(player, options) - this.playlistButton = new PlaylistButton(player, Object.assign({}, options, { playlistMenu: this.playlistMenu })) + this.playlistButton = new PlaylistButton(player, { ...options, playlistMenu: this.playlistMenu }) player.addChild(this.playlistMenu, options) player.addChild(this.playlistButton, options) diff --git a/client/src/assets/player/shared/resolutions/index.ts b/client/src/assets/player/shared/resolutions/index.ts new file mode 100644 index 000000000..e56473f43 --- /dev/null +++ b/client/src/assets/player/shared/resolutions/index.ts @@ -0,0 +1 @@ +export * from './peertube-resolutions-plugin' diff --git a/client/src/assets/player/peertube-resolutions-plugin.ts b/client/src/assets/player/shared/resolutions/peertube-resolutions-plugin.ts similarity index 96% rename from client/src/assets/player/peertube-resolutions-plugin.ts rename to client/src/assets/player/shared/resolutions/peertube-resolutions-plugin.ts index cc36f18f3..e7899ac71 100644 --- a/client/src/assets/player/peertube-resolutions-plugin.ts +++ b/client/src/assets/player/shared/resolutions/peertube-resolutions-plugin.ts @@ -1,5 +1,5 @@ import videojs from 'video.js' -import { PeerTubeResolution } from './peertube-videojs-typings' +import { PeerTubeResolution } from '../../types' const Plugin = videojs.getPlugin('plugin') diff --git a/client/src/assets/player/shared/settings/index.ts b/client/src/assets/player/shared/settings/index.ts new file mode 100644 index 000000000..736d50c16 --- /dev/null +++ b/client/src/assets/player/shared/settings/index.ts @@ -0,0 +1,7 @@ +export * from './resolution-menu-button' +export * from './resolution-menu-item' +export * from './settings-dialog' +export * from './settings-menu-button' +export * from './settings-menu-item' +export * from './settings-panel-child' +export * from './settings-panel' diff --git a/client/src/assets/player/settings/resolution-menu-button.ts b/client/src/assets/player/shared/settings/resolution-menu-button.ts similarity index 100% rename from client/src/assets/player/settings/resolution-menu-button.ts rename to client/src/assets/player/shared/settings/resolution-menu-button.ts diff --git a/client/src/assets/player/settings/resolution-menu-item.ts b/client/src/assets/player/shared/settings/resolution-menu-item.ts similarity index 100% rename from client/src/assets/player/settings/resolution-menu-item.ts rename to client/src/assets/player/shared/settings/resolution-menu-item.ts diff --git a/client/src/assets/player/settings/settings-dialog.ts b/client/src/assets/player/shared/settings/settings-dialog.ts similarity index 100% rename from client/src/assets/player/settings/settings-dialog.ts rename to client/src/assets/player/shared/settings/settings-dialog.ts diff --git a/client/src/assets/player/settings/settings-menu-button.ts b/client/src/assets/player/shared/settings/settings-menu-button.ts similarity index 98% rename from client/src/assets/player/settings/settings-menu-button.ts rename to client/src/assets/player/shared/settings/settings-menu-button.ts index 6de390f4d..64866aab2 100644 --- a/client/src/assets/player/settings/settings-menu-button.ts +++ b/client/src/assets/player/shared/settings/settings-menu-button.ts @@ -1,9 +1,7 @@ -// Thanks to Yanko Shterev: https://github.com/yshterev/videojs-settings-menu -import { SettingsMenuItem } from './settings-menu-item' -import { toTitleCase } from '../utils' import videojs from 'video.js' - +import { toTitleCase } from '../common' import { SettingsDialog } from './settings-dialog' +import { SettingsMenuItem } from './settings-menu-item' import { SettingsPanel } from './settings-panel' import { SettingsPanelChild } from './settings-panel-child' diff --git a/client/src/assets/player/settings/settings-menu-item.ts b/client/src/assets/player/shared/settings/settings-menu-item.ts similarity index 98% rename from client/src/assets/player/settings/settings-menu-item.ts rename to client/src/assets/player/shared/settings/settings-menu-item.ts index 31d42c456..8d1819a2d 100644 --- a/client/src/assets/player/settings/settings-menu-item.ts +++ b/client/src/assets/player/shared/settings/settings-menu-item.ts @@ -1,6 +1,5 @@ import videojs from 'video.js' -// Thanks to Yanko Shterev: https://github.com/yshterev/videojs-settings-menu -import { toTitleCase } from '../utils' +import { toTitleCase } from '../common' import { SettingsDialog } from './settings-dialog' import { SettingsButton } from './settings-menu-button' import { SettingsPanel } from './settings-panel' diff --git a/client/src/assets/player/settings/settings-panel-child.ts b/client/src/assets/player/shared/settings/settings-panel-child.ts similarity index 100% rename from client/src/assets/player/settings/settings-panel-child.ts rename to client/src/assets/player/shared/settings/settings-panel-child.ts diff --git a/client/src/assets/player/settings/settings-panel.ts b/client/src/assets/player/shared/settings/settings-panel.ts similarity index 100% rename from client/src/assets/player/settings/settings-panel.ts rename to client/src/assets/player/shared/settings/settings-panel.ts diff --git a/client/src/assets/player/shared/stats/index.ts b/client/src/assets/player/shared/stats/index.ts new file mode 100644 index 000000000..017ec044c --- /dev/null +++ b/client/src/assets/player/shared/stats/index.ts @@ -0,0 +1,2 @@ +export * from './stats-card' +export * from './stats-plugin' diff --git a/client/src/assets/player/stats/stats-card.ts b/client/src/assets/player/shared/stats/stats-card.ts similarity index 99% rename from client/src/assets/player/stats/stats-card.ts rename to client/src/assets/player/shared/stats/stats-card.ts index e76a81a74..1bf631d2c 100644 --- a/client/src/assets/player/stats/stats-card.ts +++ b/client/src/assets/player/shared/stats/stats-card.ts @@ -1,7 +1,7 @@ import videojs from 'video.js' import { secondsToTime } from '@shared/core-utils' -import { PlayerNetworkInfo as EventPlayerNetworkInfo } from '../peertube-videojs-typings' -import { bytes } from '../utils' +import { PlayerNetworkInfo as EventPlayerNetworkInfo } from '../../types' +import { bytes } from '../common' interface StatsCardOptions extends videojs.ComponentOptions { videoUUID: string diff --git a/client/src/assets/player/stats/stats-plugin.ts b/client/src/assets/player/shared/stats/stats-plugin.ts similarity index 100% rename from client/src/assets/player/stats/stats-plugin.ts rename to client/src/assets/player/shared/stats/stats-plugin.ts diff --git a/client/src/assets/player/upnext/end-card.ts b/client/src/assets/player/shared/upnext/end-card.ts similarity index 100% rename from client/src/assets/player/upnext/end-card.ts rename to client/src/assets/player/shared/upnext/end-card.ts diff --git a/client/src/assets/player/shared/upnext/index.ts b/client/src/assets/player/shared/upnext/index.ts new file mode 100644 index 000000000..c63c5fd83 --- /dev/null +++ b/client/src/assets/player/shared/upnext/index.ts @@ -0,0 +1,2 @@ +export * from './end-card' +export * from './upnext-plugin' diff --git a/client/src/assets/player/upnext/upnext-plugin.ts b/client/src/assets/player/shared/upnext/upnext-plugin.ts similarity index 100% rename from client/src/assets/player/upnext/upnext-plugin.ts rename to client/src/assets/player/shared/upnext/upnext-plugin.ts diff --git a/client/src/assets/player/webtorrent/peertube-chunk-store.ts b/client/src/assets/player/shared/webtorrent/peertube-chunk-store.ts similarity index 100% rename from client/src/assets/player/webtorrent/peertube-chunk-store.ts rename to client/src/assets/player/shared/webtorrent/peertube-chunk-store.ts diff --git a/client/src/assets/player/webtorrent/video-renderer.ts b/client/src/assets/player/shared/webtorrent/video-renderer.ts similarity index 100% rename from client/src/assets/player/webtorrent/video-renderer.ts rename to client/src/assets/player/shared/webtorrent/video-renderer.ts diff --git a/client/src/assets/player/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts similarity index 98% rename from client/src/assets/player/webtorrent/webtorrent-plugin.ts rename to client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts index 4bcb2766a..b48203148 100644 --- a/client/src/assets/player/webtorrent/webtorrent-plugin.ts +++ b/client/src/assets/player/shared/webtorrent/webtorrent-plugin.ts @@ -1,10 +1,11 @@ import videojs from 'video.js' import * as WebTorrent from 'webtorrent' +import { isIOS } from '@root-helpers/web-browser' import { timeToInt } from '@shared/core-utils' import { VideoFile } from '@shared/models' -import { getAverageBandwidthInStore, getStoredMute, getStoredVolume, saveAverageBandwidth } from '../peertube-player-local-storage' -import { PeerTubeResolution, PlayerNetworkInfo, WebtorrentPluginOptions } from '../peertube-videojs-typings' -import { getRtcConfig, isIOS, videoFileMaxByResolution, videoFileMinByResolution } from '../utils' +import { getAverageBandwidthInStore, getStoredMute, getStoredVolume, saveAverageBandwidth } from '../../peertube-player-local-storage' +import { PeerTubeResolution, PlayerNetworkInfo, WebtorrentPluginOptions } from '../../types' +import { getRtcConfig, videoFileMaxByResolution, videoFileMinByResolution } from '../common' import { PeertubeChunkStore } from './peertube-chunk-store' import { renderVideo } from './video-renderer' diff --git a/client/src/assets/player/types/index.ts b/client/src/assets/player/types/index.ts new file mode 100644 index 000000000..b73e0b3cb --- /dev/null +++ b/client/src/assets/player/types/index.ts @@ -0,0 +1,2 @@ +export * from './manager-options' +export * from './peertube-videojs-typings' diff --git a/client/src/assets/player/manager-options/manager-options.model.ts b/client/src/assets/player/types/manager-options.ts similarity index 98% rename from client/src/assets/player/manager-options/manager-options.model.ts rename to client/src/assets/player/types/manager-options.ts index 0b0f8b435..b3ad7e337 100644 --- a/client/src/assets/player/manager-options/manager-options.model.ts +++ b/client/src/assets/player/types/manager-options.ts @@ -1,6 +1,6 @@ import { PluginsManager } from '@root-helpers/plugins-manager' import { LiveVideoLatencyMode, VideoFile } from '@shared/models' -import { PlaylistPluginOptions, UserWatching, VideoJSCaption } from '../peertube-videojs-typings' +import { PlaylistPluginOptions, UserWatching, VideoJSCaption } from './peertube-videojs-typings' export type PlayerMode = 'webtorrent' | 'p2p-media-loader' diff --git a/client/src/assets/player/peertube-videojs-typings.ts b/client/src/assets/player/types/peertube-videojs-typings.ts similarity index 82% rename from client/src/assets/player/peertube-videojs-typings.ts rename to client/src/assets/player/types/peertube-videojs-typings.ts index fcaa8a9c3..d9a388681 100644 --- a/client/src/assets/player/peertube-videojs-typings.ts +++ b/client/src/assets/player/types/peertube-videojs-typings.ts @@ -2,18 +2,18 @@ import { HlsConfig, Level } from 'hls.js' import videojs from 'video.js' import { Engine } from '@peertube/p2p-media-loader-hlsjs' import { VideoFile, VideoPlaylist, VideoPlaylistElement } from '@shared/models' -import { PeerTubeDockPluginOptions } from './dock/peertube-dock-plugin' -import { PlayerMode } from './manager-options/manager-options.model' -import { Html5Hlsjs } from './p2p-media-loader/hls-plugin' -import { P2pMediaLoaderPlugin } from './p2p-media-loader/p2p-media-loader-plugin' -import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager' -import { PeerTubePlugin } from './peertube-plugin' -import { PeerTubeResolutionsPlugin } from './peertube-resolutions-plugin' -import { PlaylistPlugin } from './playlist/playlist-plugin' -import { StatsCardOptions } from './stats/stats-card' -import { StatsForNerdsPlugin } from './stats/stats-plugin' -import { EndCardOptions } from './upnext/end-card' -import { WebTorrentPlugin } from './webtorrent/webtorrent-plugin' +import { PeerTubeDockPluginOptions } from '../shared/dock/peertube-dock-plugin' +import { Html5Hlsjs } from '../shared/p2p-media-loader/hls-plugin' +import { P2pMediaLoaderPlugin } from '../shared/p2p-media-loader/p2p-media-loader-plugin' +import { RedundancyUrlManager } from '../shared/p2p-media-loader/redundancy-url-manager' +import { PeerTubePlugin } from '../shared/peertube/peertube-plugin' +import { PlaylistPlugin } from '../shared/playlist/playlist-plugin' +import { PeerTubeResolutionsPlugin } from '../shared/resolutions/peertube-resolutions-plugin' +import { StatsCardOptions } from '../shared/stats/stats-card' +import { StatsForNerdsPlugin } from '../shared/stats/stats-plugin' +import { EndCardOptions } from '../shared/upnext/end-card' +import { WebTorrentPlugin } from '../shared/webtorrent/webtorrent-plugin' +import { PlayerMode } from './manager-options' declare module 'video.js' { diff --git a/client/src/root-helpers/index.ts b/client/src/root-helpers/index.ts index aa3b442dd..3b95b4b99 100644 --- a/client/src/root-helpers/index.ts +++ b/client/src/root-helpers/index.ts @@ -3,5 +3,6 @@ export * from './bytes' export * from './images' export * from './local-storage-utils' export * from './peertube-web-storage' -export * from './utils' export * from './plugins-manager' +export * from './utils' +export * from './video' diff --git a/client/src/root-helpers/video.ts b/client/src/root-helpers/video.ts new file mode 100644 index 000000000..4290992aa --- /dev/null +++ b/client/src/root-helpers/video.ts @@ -0,0 +1,33 @@ +import { HTMLServerConfig, Video } from '@shared/models' + +function buildVideoOrPlaylistEmbed (embedUrl: string, embedTitle: string) { + const iframe = document.createElement('iframe') + + iframe.title = embedTitle + iframe.width = '560' + iframe.height = '315' + iframe.src = embedUrl + iframe.frameBorder = '0' + iframe.allowFullscreen = true + iframe.sandbox.add('allow-same-origin', 'allow-scripts', 'allow-popups') + + return iframe.outerHTML +} + +function isP2PEnabled (video: Video, config: HTMLServerConfig, userP2PEnabled: boolean) { + if (video.isLocal && config.tracker.enabled === false) return false + if (isWebRTCDisabled()) return false + + return userP2PEnabled +} + +export { + buildVideoOrPlaylistEmbed, + isP2PEnabled +} + +// --------------------------------------------------------------------------- + +function isWebRTCDisabled () { + return !!((window as any).RTCPeerConnection || (window as any).mozRTCPeerConnection || (window as any).webkitRTCPeerConnection) === false +} diff --git a/client/src/root-helpers/web-browser.ts b/client/src/root-helpers/web-browser.ts new file mode 100644 index 000000000..9dade20e8 --- /dev/null +++ b/client/src/root-helpers/web-browser.ts @@ -0,0 +1,24 @@ +function isIOS () { + if (/iPad|iPhone|iPod/.test(navigator.platform)) { + return true + } + + // Detect iPad Desktop mode + return !!(navigator.maxTouchPoints && + navigator.maxTouchPoints > 2 && + navigator.platform.includes('MacIntel')) +} + +function isSafari () { + return /^((?!chrome|android).)*safari/i.test(navigator.userAgent) +} + +function isMobile () { + return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) +} + +export { + isIOS, + isSafari, + isMobile +} diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index 9e4d87911..55c26ec3b 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -1,6 +1,6 @@ import './embed.scss' -import '../../assets/player/dock/peertube-dock-component' -import '../../assets/player/dock/peertube-dock-plugin' +import '../../assets/player/shared/dock/peertube-dock-component' +import '../../assets/player/shared/dock/peertube-dock-plugin' import videojs from 'video.js' import { peertubeTranslate } from '../../../../shared/core-utils/i18n' import { @@ -17,15 +17,14 @@ import { VideoPlaylistElement, VideoStreamingPlaylistType } from '../../../../shared/models' -import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../assets/player' -import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings' +import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode, VideoJSCaption } from '../../assets/player' import { TranslationsManager } from '../../assets/player/translations-manager' -import { isP2PEnabled } from '../../assets/player/utils' import { getBoolOrDefault } from '../../root-helpers/local-storage-utils' import { peertubeLocalStorage } from '../../root-helpers/peertube-web-storage' import { PluginsManager } from '../../root-helpers/plugins-manager' import { UserLocalStorageKeys, UserTokens } from '../../root-helpers/users' import { objectToUrlEncoded } from '../../root-helpers/utils' +import { isP2PEnabled } from '../../root-helpers/video' import { RegisterClientHelpers } from '../../types/register-client-option.model' import { PeerTubeEmbedApi } from './embed-api' -- 2.41.0