]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/server-commands/videos/live-command.ts
Merge branch 'release/4.3.0' into develop
[github/Chocobozzz/PeerTube.git] / shared / server-commands / videos / live-command.ts
index f7816eca0d592292b5d2eb32ff6d672a378f9d3f..d804fd883b53287b2656b1fe5e369525e4e60215 100644 (file)
@@ -1,10 +1,19 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import { readdir } from 'fs-extra'
-import { omit } from 'lodash'
 import { join } from 'path'
-import { wait } from '@shared/core-utils'
-import { HttpStatusCode, LiveVideo, LiveVideoCreate, LiveVideoUpdate, VideoCreateResult, VideoDetails, VideoState } from '@shared/models'
+import { omit, wait } from '@shared/core-utils'
+import {
+  HttpStatusCode,
+  LiveVideo,
+  LiveVideoCreate,
+  LiveVideoSession,
+  LiveVideoUpdate,
+  ResultList,
+  VideoCreateResult,
+  VideoDetails,
+  VideoState
+} from '@shared/models'
 import { unwrapBody } from '../requests'
 import { AbstractCommand, OverrideCommandOptions } from '../shared'
 import { sendRTMPStream, testFfmpegStreamError } from './live'
@@ -25,6 +34,42 @@ export class LiveCommand extends AbstractCommand {
     })
   }
 
+  listSessions (options: OverrideCommandOptions & {
+    videoId: number | string
+  }) {
+    const path = `/api/v1/videos/live/${options.videoId}/sessions`
+
+    return this.getRequestBody<ResultList<LiveVideoSession>>({
+      ...options,
+
+      path,
+      implicitToken: true,
+      defaultExpectedStatus: HttpStatusCode.OK_200
+    })
+  }
+
+  async findLatestSession (options: OverrideCommandOptions & {
+    videoId: number | string
+  }) {
+    const { data: sessions } = await this.listSessions(options)
+
+    return sessions[sessions.length - 1]
+  }
+
+  getReplaySession (options: OverrideCommandOptions & {
+    videoId: number | string
+  }) {
+    const path = `/api/v1/videos/${options.videoId}/live-session`
+
+    return this.getRequestBody<LiveVideoSession>({
+      ...options,
+
+      path,
+      implicitToken: true,
+      defaultExpectedStatus: HttpStatusCode.OK_200
+    })
+  }
+
   update (options: OverrideCommandOptions & {
     videoId: number | string
     fields: LiveVideoUpdate
@@ -57,7 +102,7 @@ export class LiveCommand extends AbstractCommand {
 
       path,
       attaches,
-      fields: omit(fields, 'thumbnailfile', 'previewfile'),
+      fields: omit(fields, [ 'thumbnailfile', 'previewfile' ]),
       implicitToken: true,
       defaultExpectedStatus: HttpStatusCode.OK_200
     }))
@@ -108,16 +153,36 @@ export class LiveCommand extends AbstractCommand {
 
   waitUntilSegmentGeneration (options: OverrideCommandOptions & {
     videoUUID: string
-    resolution: number
+    playlistNumber: number
     segment: number
+    totalSessions?: number
   }) {
-    const { resolution, segment, videoUUID } = options
-    const segmentName = `${resolution}-00000${segment}.ts`
+    const { playlistNumber, segment, videoUUID, totalSessions = 1 } = options
+    const segmentName = `${playlistNumber}-00000${segment}.ts`
+
+    return this.server.servers.waitUntilLog(`${videoUUID}/${segmentName}`, totalSessions * 2, false)
+  }
 
-    return this.server.servers.waitUntilLog(`${videoUUID}/${segmentName}`, 2, false)
+  getSegment (options: OverrideCommandOptions & {
+    videoUUID: string
+    playlistNumber: number
+    segment: number
+  }) {
+    const { playlistNumber, segment, videoUUID } = options
+
+    const segmentName = `${playlistNumber}-00000${segment}.ts`
+    const url = `${this.server.url}/static/streaming-playlists/hls/${videoUUID}/${segmentName}`
+
+    return this.getRawRequest({
+      ...options,
+
+      url,
+      implicitToken: false,
+      defaultExpectedStatus: HttpStatusCode.OK_200
+    })
   }
 
-  async waitUntilSaved (options: OverrideCommandOptions & {
+  async waitUntilReplacedByReplay (options: OverrideCommandOptions & {
     videoId: number | string
   }) {
     let video: VideoDetails