]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix live ending job that breaks new live session
authorChocobozzz <me@florianbigard.com>
Thu, 16 Jun 2022 11:39:57 +0000 (13:39 +0200)
committerChocobozzz <me@florianbigard.com>
Thu, 16 Jun 2022 11:39:57 +0000 (13:39 +0200)
server/lib/job-queue/handlers/video-live-ending.ts
server/lib/live/live-manager.ts
server/tests/api/live/live-save-replay.ts
shared/models/server/job.model.ts

index 7607267f84f16f5e163abcccdfedb67925cbcf5b..feec257fca2852198a35bfb22faddc2235de2b1f 100644 (file)
@@ -45,13 +45,13 @@ async function processVideoLiveEnding (job: Job) {
   LiveSegmentShaStore.Instance.cleanupShaSegments(liveVideo.uuid)
 
   if (live.saveReplay !== true) {
-    return cleanupLiveAndFederate({ live, video: liveVideo })
+    return cleanupLiveAndFederate({ live, video: liveVideo, streamingPlaylistId: payload.streamingPlaylistId })
   }
 
   if (live.permanentLive) {
     await saveReplayToExternalVideo({ liveVideo, liveSession, publishedAt: payload.publishedAt, replayDirectory: payload.replayDirectory })
 
-    return cleanupLiveAndFederate({ live, video: liveVideo })
+    return cleanupLiveAndFederate({ live, video: liveVideo, streamingPlaylistId: payload.streamingPlaylistId })
   }
 
   return replaceLiveByReplay({ liveVideo, live, liveSession, replayDirectory: payload.replayDirectory })
@@ -233,15 +233,18 @@ async function assignReplayFilesToVideo (options: {
 async function cleanupLiveAndFederate (options: {
   live: MVideoLive
   video: MVideo
+  streamingPlaylistId: number
 }) {
-  const { live, video } = options
+  const { live, video, streamingPlaylistId } = options
 
-  const streamingPlaylist = await VideoStreamingPlaylistModel.loadHLSPlaylistByVideo(video.id)
+  const streamingPlaylist = await VideoStreamingPlaylistModel.loadWithVideo(streamingPlaylistId)
 
-  if (live.permanentLive) {
-    await cleanupPermanentLive(video, streamingPlaylist)
-  } else {
-    await cleanupNormalLive(video, streamingPlaylist)
+  if (streamingPlaylist) {
+    if (live.permanentLive) {
+      await cleanupPermanentLive(video, streamingPlaylist)
+    } else {
+      await cleanupNormalLive(video, streamingPlaylist)
+    }
   }
 
   try {
index 0f14a68511cd775efab58d8d1f1276f7e4460e59..f2f064b49bc29c596e62b302c76139f3f2fb7db2 100644 (file)
@@ -416,6 +416,7 @@ class LiveManager {
             : undefined,
 
           liveSessionId: liveSession.id,
+          streamingPlaylistId: fullVideo.getHLSPlaylist()?.id,
 
           publishedAt: fullVideo.publishedAt.toISOString()
         }
index 007af51e9669d2edd9c4908a29b569fc25888d5d..99d500711c08ab0883c737a43a7a98df5d54f416 100644 (file)
@@ -12,6 +12,7 @@ import {
   createMultipleServers,
   doubleFollow,
   findExternalSavedVideo,
+  makeRawRequest,
   PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel,
@@ -457,6 +458,12 @@ describe('Save replay setting', function () {
       // Streaming session #2
       ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoUUID })
       await waitUntilLivePublishedOnAllServers(servers, liveVideoUUID)
+
+      await wait(5000)
+      const video = await servers[0].videos.get({ id: liveVideoUUID })
+      expect(video.streamingPlaylists).to.have.lengthOf(1)
+      await makeRawRequest(video.streamingPlaylists[0].playlistUrl)
+
       await stopFfmpeg(ffmpegCommand)
       await waitUntilLiveWaitingOnAllServers(servers, liveVideoUUID)
 
index bc5ffa57092b9ba171d795017df76b3f7a282cfe..073f1587291e068333ac38dd5da69f731a7abc3e 100644 (file)
@@ -161,6 +161,7 @@ export interface VideoLiveEndingPayload {
   videoId: number
   publishedAt: string
   liveSessionId: number
+  streamingPlaylistId: number
 
   replayDirectory?: string
 }