]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/assets/player/peertube-player-manager.ts
Upgrade client dependencies
[github/Chocobozzz/PeerTube.git] / client / src / assets / player / peertube-player-manager.ts
index 8e0a9109f6c41d8bf0cdfb1020a607c273b38941..da23c59a749dad2a2a0b33b5018b7e47592c4850 100644 (file)
@@ -98,6 +98,8 @@ export interface CommonOptions extends CustomizationOptions {
   videoViewUrl: string
   embedUrl: string
 
+  isLive: boolean
+
   language?: string
 
   videoCaptions: VideoJSCaption[]
@@ -119,6 +121,10 @@ export class PeertubePlayerManager {
 
   private static alreadyPlayed = false
 
+  static initState () {
+    PeertubePlayerManager.alreadyPlayed = false
+  }
+
   static async initialize (mode: PlayerMode, options: PeertubePlayerManagerOptions, onPlayerChange: (player: videojs.Player) => void) {
     let p2pMediaLoader: any
 
@@ -319,9 +325,9 @@ export class PeertubePlayerManager {
     const p2pMediaLoaderConfig = {
       loader: {
         trackerAnnounce,
-        segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url),
+        segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url, options.common.isLive),
         rtcConfig: getRtcConfig(),
-        requiredSegmentsPriority: 5,
+        requiredSegmentsPriority: 1,
         segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager),
         useP2P: getStoredP2PEnabled(),
         consumeOnly
@@ -335,10 +341,8 @@ export class PeertubePlayerManager {
         const resolution = Math.min(level.height || 0, level.width || 0)
 
         const file = p2pMediaLoaderOptions.videoFiles.find(f => f.resolution.id === resolution)
-        if (!file) {
-          console.error('Cannot find video file for level %d.', level.height)
-          return level.height
-        }
+        // We don't have files for live videos
+        if (!file) return level.height
 
         let label = file.resolution.label
         if (file.fps >= 50) label += file.fps
@@ -349,7 +353,7 @@ export class PeertubePlayerManager {
         hlsjsConfig: {
           capLevelToPlayerSize: true,
           autoStartLoad: false,
-          liveSyncDurationCount: 7,
+          liveSyncDurationCount: 5,
           loader: new p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass()
         }
       }
@@ -365,8 +369,12 @@ export class PeertubePlayerManager {
     const commonOptions = options.common
     const webtorrentOptions = options.webtorrent
 
+    const autoplay = this.getAutoPlayValue(commonOptions.autoplay) === 'play'
+      ? true
+      : false
+
     const webtorrent = {
-      autoplay: commonOptions.autoplay,
+      autoplay,
       videoDuration: commonOptions.videoDuration,
       playerElement: commonOptions.playerElement,
       videoFiles: webtorrentOptions.videoFiles,
@@ -586,13 +594,9 @@ export class PeertubePlayerManager {
   private static getAutoPlayValue (autoplay: any) {
     if (autoplay !== true) return autoplay
 
-    // We have issues with autoplay and Safari with webtorrent
-    if (isIOS()) {
-      // On first play, disable autoplay to avoid issues
-      // But if the player already played videos, we can safely autoplay next ones
-      return PeertubePlayerManager.alreadyPlayed ? 'play' : false
-    } else if (isSafari()) {
-      // Issues with Safari and webtorrent on first play
+    // On first play, disable autoplay to avoid issues
+    // But if the player already played videos, we can safely autoplay next ones
+    if (isIOS() || isSafari()) {
       return PeertubePlayerManager.alreadyPlayed ? 'play' : false
     }