]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/server-commands/videos/live-command.ts
Correctly wait for live segment generation
[github/Chocobozzz/PeerTube.git] / shared / server-commands / videos / live-command.ts
index cc9502c6f1efe9735092dd84b1cece35eba90857..73f4eefd331a94086c625b55b41c1898d0f6aeff 100644 (file)
@@ -121,7 +121,7 @@ export class LiveCommand extends AbstractCommand {
     permanentLive: boolean
     privacy?: VideoPrivacy
   }) {
-    const { saveReplay, permanentLive, privacy } = options
+    const { saveReplay, permanentLive, privacy = VideoPrivacy.PUBLIC } = options
 
     const { uuid } = await this.create({
       ...options,
@@ -130,6 +130,7 @@ export class LiveCommand extends AbstractCommand {
         name: 'live',
         permanentLive,
         saveReplay,
+        replaySettings: { privacy },
         channelId: this.server.store.channel.id,
         privacy
       }
@@ -192,18 +193,27 @@ export class LiveCommand extends AbstractCommand {
     playlistNumber: number
     segment: number
     objectStorage: boolean
+    objectStorageBaseUrl?: string
   }) {
-    const { server, objectStorage, playlistNumber, segment, videoUUID } = options
+    const {
+      server,
+      objectStorage,
+      playlistNumber,
+      segment,
+      videoUUID,
+      objectStorageBaseUrl = ObjectStorageCommand.getMockPlaylistBaseUrl()
+    } = options
 
     const segmentName = `${playlistNumber}-00000${segment}.ts`
     const baseUrl = objectStorage
-      ? ObjectStorageCommand.getMockPlaylistBaseUrl() + 'hls'
+      ? join(objectStorageBaseUrl, 'hls')
       : server.url + '/static/streaming-playlists/hls'
 
     let error = true
 
     while (error) {
       try {
+        // Check fragment exists
         await this.getRawRequest({
           ...options,
 
@@ -215,12 +225,16 @@ export class LiveCommand extends AbstractCommand {
         const video = await server.videos.get({ id: videoUUID })
         const hlsPlaylist = video.streamingPlaylists[0]
 
-        const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url })
-
+        // Check SHA generation
+        const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url, withRetry: objectStorage })
         if (!shaBody[segmentName]) {
           throw new Error('Segment SHA does not exist')
         }
 
+        // Check fragment is in m3u8 playlist
+        const subPlaylist = await server.streamingPlaylists.get({ url: `${baseUrl}/${video.uuid}/${playlistNumber}.m3u8` })
+        if (!subPlaylist.includes(segmentName)) throw new Error('Fragment does not exist in playlist')
+
         error = false
       } catch {
         error = true