]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Delay notification when waiting for a live
authorChocobozzz <me@florianbigard.com>
Thu, 12 Nov 2020 16:13:32 +0000 (17:13 +0100)
committerChocobozzz <me@florianbigard.com>
Thu, 12 Nov 2020 16:13:32 +0000 (17:13 +0100)
client/src/assets/player/p2p-media-loader/segment-validator.ts
server/initializers/constants.ts
server/lib/live-manager.ts

index 844956d6a6cb543ed441344af095dbfe91d9afb5..4a0caec5e621cbb469978665513e7f513c2d5057 100644 (file)
@@ -10,7 +10,7 @@ function segmentValidatorFactory (segmentsSha256Url: string, isLive: boolean) {
   let segmentsJSON = fetchSha256Segments(segmentsSha256Url)
   const regex = /bytes=(\d+)-(\d+)/
 
-  return async function segmentValidator (segment: Segment, retry = 1) {
+  return async function segmentValidator (segment: Segment, _method: string, _peerId: string, retry = 1) {
     // Wait for hash generation from the server
     if (isLive) await wait(1000)
 
@@ -28,7 +28,7 @@ function segmentValidatorFactory (segmentsSha256Url: string, isLive: boolean) {
       await wait(1000)
 
       segmentsJSON = fetchSha256Segments(segmentsSha256Url)
-      await segmentValidator(segment, retry + 1)
+      await segmentValidator(segment, _method, _peerId, retry + 1)
 
       return
     }
index 6795037313c3b66e63a2ad71eca8044ec0c5ef1b..02e42a59436e5d503f85581f2d9bd1d2d320106b 100644 (file)
@@ -620,6 +620,7 @@ const VIDEO_LIVE = {
   CLEANUP_DELAY: 1000 * 60 * 5, // 5 minutes
   SEGMENT_TIME_SECONDS: 4, // 4 seconds
   SEGMENTS_LIST_SIZE: 15, // 15 maximum segments in live playlist
+  EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION: 3,
   RTMP: {
     CHUNK_SIZE: 60000,
     GOP_CACHE: true,
@@ -750,6 +751,7 @@ if (isTestInstance() === true) {
 
   VIDEO_LIVE.CLEANUP_DELAY = 5000
   VIDEO_LIVE.SEGMENT_TIME_SECONDS = 2
+  VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1
 }
 
 updateWebserverUrls()
index 60ef30d15641cd5478defb4a0fdab65f018ba5ea..d1a0cee91f129db37f5917f0ec6605893cbd4559 100644 (file)
@@ -323,11 +323,15 @@ class LiveManager {
         await video.save()
         videoLive.Video = video
 
-        await federateVideoIfNeeded(video, false)
+        setTimeout(() => {
+          federateVideoIfNeeded(video, false)
+            .catch(err => logger.error('Cannot federate live video %s.', video.url, { err }))
+
+          PeerTubeSocket.Instance.sendVideoLiveNewState(video)
+        }, VIDEO_LIVE.SEGMENT_TIME_SECONDS * 1000 * VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION)
 
-        PeerTubeSocket.Instance.sendVideoLiveNewState(video)
       } catch (err) {
-        logger.error('Cannot federate video %d.', videoLive.videoId, { err })
+        logger.error('Cannot save/federate live video %d.', videoLive.videoId, { err })
       } finally {
         masterWatcher.close()
           .catch(err => logger.error('Cannot close master watcher of %s.', outPath, { err }))