]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/standalone/videos/embed.ts
Auto load HLS player in embed too
[github/Chocobozzz/PeerTube.git] / client / src / standalone / videos / embed.ts
index 6ff3efef1afd6ebc551b6da4417404b253e665cd..40d945824919c2f6f0fd949cfb0302a65f68936f 100644 (file)
@@ -116,7 +116,7 @@ export class PeerTubeEmbed {
     this.api.initialize()
   }
 
-  private loadParams () {
+  private loadParams (video: VideoDetails) {
     try {
       const params = new URL(window.location.toString()).searchParams
 
@@ -136,7 +136,15 @@ export class PeerTubeEmbed {
       this.bigPlayBackgroundColor = this.getParamString(params, 'bigPlayBackgroundColor')
       this.foregroundColor = this.getParamString(params, 'foregroundColor')
 
-      this.mode = this.getParamString(params, 'mode') === 'p2p-media-loader' ? 'p2p-media-loader' : 'webtorrent'
+      const modeParam = this.getParamString(params, 'mode')
+
+      if (modeParam) {
+        if (modeParam === 'p2p-media-loader') this.mode = 'p2p-media-loader'
+        else this.mode = 'webtorrent'
+      } else {
+        if (Array.isArray(video.streamingPlaylists) && video.streamingPlaylists.length !== 0) this.mode = 'p2p-media-loader'
+        else this.mode = 'webtorrent'
+      }
     } catch (err) {
       console.error('Cannot get params from URL.', err)
     }
@@ -162,7 +170,7 @@ export class PeerTubeEmbed {
     const videoInfo: VideoDetails = await videoResponse.json()
     const videoCaptions = await this.buildCaptions(serverTranslations, captionsResponse)
 
-    this.loadParams()
+    this.loadParams(videoInfo)
 
     const options: PeertubePlayerManagerOptions = {
       common: {
@@ -207,7 +215,7 @@ export class PeerTubeEmbed {
           segmentsSha256Url: hlsPlaylist.segmentsSha256Url,
           redundancyBaseUrls: hlsPlaylist.redundancies.map(r => r.baseUrl),
           trackerAnnounce: videoInfo.trackerUrls,
-          videoFiles: videoInfo.files
+          videoFiles: hlsPlaylist.files
         } as P2PMediaLoaderOptions
       })
     }
@@ -239,7 +247,7 @@ export class PeerTubeEmbed {
 
       const config: ServerConfig = await configResponse.json()
       const description = config.tracker.enabled && this.warningTitle
-        ? '<span class="text">' + this.player.localize('Uses P2P, others may know your IP is downloading this video.') + '</span>'
+        ? '<span class="text">' + this.player.localize('Watching this video may reveal your IP address to others.') + '</span>'
         : undefined
 
       this.player.dock({