Add player mode in watch/embed urls
authorChocobozzz <me@florianbigard.com>
Thu, 7 Feb 2019 14:56:17 +0000 (15:56 +0100)
committerChocobozzz <chocobozzz@cpy.re>
Mon, 11 Feb 2019 08:13:02 +0000 (09:13 +0100)
client/src/app/videos/+video-watch/video-watch.component.ts
client/src/standalone/videos/embed.ts
server/lib/job-queue/handlers/video-file.ts

index e1766255b2ee555b1205403ed93c8b0cf460ca1d..9f3a43a08cef8c59bb1d9a087abf37ec6afa102d 100644 (file)
@@ -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 () => {
index c5c46d0c5a74f7c9b2111d81326d220de66e0a6c..32bf42e125a15a2a8f718eae037ce6221ad2e282 100644 (file)
@@ -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)
     }
index 7119ce0cab8a624904bb196387ed9507371e41ba..04983155ce7a462f9c691beb457b16e636a08e97 100644 (file)
@@ -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)
   }