]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/live-manager.ts
Fix redundancy federation in some cases
[github/Chocobozzz/PeerTube.git] / server / lib / live-manager.ts
index c2dd116a99847f34188a066af824268a196a6a03..379f61bdf332de10b9491f2346b4631cb011bdf3 100644 (file)
@@ -1,7 +1,8 @@
 
+import * as Bluebird from 'bluebird'
 import * as chokidar from 'chokidar'
 import { FfmpegCommand } from 'fluent-ffmpeg'
-import { appendFile, copy, ensureDir, readFile, stat } from 'fs-extra'
+import { appendFile, ensureDir, readFile, stat } from 'fs-extra'
 import { basename, join } from 'path'
 import { isTestInstance } from '@server/helpers/core-utils'
 import { getLiveMuxingCommand, getLiveTranscodingCommand } from '@server/helpers/ffmpeg-utils'
@@ -24,7 +25,6 @@ import { PeerTubeSocket } from './peertube-socket'
 import { isAbleToUploadVideo } from './user'
 import { getHLSDirectory } from './video-paths'
 import { availableEncoders } from './video-transcoding-profiles'
-import * as Bluebird from 'bluebird'
 
 import memoizee = require('memoizee')
 
@@ -287,16 +287,17 @@ class LiveManager {
     for (let i = 0; i < allResolutions.length; i++) {
       const resolution = allResolutions[i]
 
-      VideoFileModel.upsert({
+      const file = new VideoFileModel({
         resolution,
         size: -1,
         extname: '.ts',
         infoHash: null,
         fps,
         videoStreamingPlaylistId: playlist.id
-      }).catch(err => {
-        logger.error('Cannot create file for live streaming.', { err })
       })
+
+      VideoFileModel.customUpsert(file, 'streaming-playlist', null)
+        .catch(err => logger.error('Cannot create file for live streaming.', { err }))
     }
 
     const outPath = getHLSDirectory(videoLive.Video)
@@ -504,7 +505,7 @@ class LiveManager {
   private isDurationConstraintValid (streamingStartTime: number) {
     const maxDuration = CONFIG.LIVE.MAX_DURATION
     // No limit
-    if (maxDuration === null) return true
+    if (maxDuration < 0) return true
 
     const now = new Date().getTime()
     const max = streamingStartTime + maxDuration
@@ -536,6 +537,8 @@ class LiveManager {
 
       await federateVideoIfNeeded(video, false)
 
+      PeerTubeSocket.Instance.sendVideoViewsUpdate(video)
+
       // Only keep not expired watchers
       const newWatchers = watchers.filter(w => w > notBefore)
       this.watchersPerVideo.set(videoId, newWatchers)