From 597a9266d426aa04c2f229168e4285a76bea2c12 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Feb 2019 15:56:17 +0100 Subject: [PATCH] Add player mode in watch/embed urls --- .../+video-watch/video-watch.component.ts | 22 ++++++++++--------- client/src/standalone/videos/embed.ts | 2 +- server/lib/job-queue/handlers/video-file.ts | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) 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 e1766255b..9f3a43a08 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts @@ -27,8 +27,7 @@ import { P2PMediaLoaderOptions, PeertubePlayerManager, PeertubePlayerManagerOptions, - PlayerMode, - WebtorrentOptions + PlayerMode } from '../../../assets/player/peertube-player-manager' @Component({ @@ -117,8 +116,9 @@ export class VideoWatchComponent implements OnInit, OnDestroy { .subscribe(([ video, captionsResult ]) => { const startTime = this.route.snapshot.queryParams.start const subtitle = this.route.snapshot.queryParams.subtitle + const playerMode = this.route.snapshot.queryParams.mode - this.onVideoFetched(video, captionsResult.data, { startTime, subtitle }) + this.onVideoFetched(video, captionsResult.data, { startTime, subtitle, playerMode }) .catch(err => this.handleError(err)) }) }) @@ -365,7 +365,11 @@ export class VideoWatchComponent implements OnInit, OnDestroy { ) } - private async onVideoFetched (video: VideoDetails, videoCaptions: VideoCaption[], urlOptions: { startTime: number, subtitle: string }) { + private async onVideoFetched ( + video: VideoDetails, + videoCaptions: VideoCaption[], + urlOptions: { startTime?: number, subtitle?: string, playerMode?: string } + ) { this.video = video // Re init attributes @@ -440,10 +444,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy { } } - let mode: PlayerMode - const hlsPlaylist = this.video.getHlsPlaylist() - if (hlsPlaylist) { - mode = 'p2p-media-loader' + const mode: PlayerMode = urlOptions.playerMode === 'p2p-media-loader' ? 'p2p-media-loader' : 'webtorrent' + + if (mode === 'p2p-media-loader') { + const hlsPlaylist = this.video.getHlsPlaylist() const p2pMediaLoader = { playlistUrl: hlsPlaylist.playlistUrl, @@ -454,8 +458,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy { } as P2PMediaLoaderOptions Object.assign(options, { p2pMediaLoader }) - } else { - mode = 'webtorrent' } this.zone.runOutsideAngular(async () => { diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts index c5c46d0c5..32bf42e12 100644 --- a/client/src/standalone/videos/embed.ts +++ b/client/src/standalone/videos/embed.ts @@ -263,7 +263,7 @@ class PeerTubeEmbed { this.subtitle = this.getParamString(params, 'subtitle') this.startTime = this.getParamString(params, 'start') - this.mode = this.getParamToggle(params, 'p2p-media-loader') ? 'p2p-media-loader' : 'webtorrent' + this.mode = this.getParamString(params, 'mode') === 'p2p-media-loader' ? 'p2p-media-loader' : 'webtorrent' } catch (err) { console.error('Cannot get params from URL.', err) } diff --git a/server/lib/job-queue/handlers/video-file.ts b/server/lib/job-queue/handlers/video-file.ts index 7119ce0ca..04983155c 100644 --- a/server/lib/job-queue/handlers/video-file.ts +++ b/server/lib/job-queue/handlers/video-file.ts @@ -172,7 +172,7 @@ async function onVideoFileOptimizerSuccess (videoArg: VideoModel, payload: Video // don't notify prior to scheduled video update if (!videoDatabase.ScheduleVideoUpdate) { - if (isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase) + if (payload.isNewVideo) Notifier.Instance.notifyOnNewVideo(videoDatabase) if (videoPublished) Notifier.Instance.notifyOnPendingVideoPublished(videoDatabase) } -- 2.25.1