/* 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,
+ VideoPrivacy,
+ VideoState
+} from '@shared/models'
import { unwrapBody } from '../requests'
+import { ObjectStorageCommand, PeerTubeServer } from '../server'
import { AbstractCommand, OverrideCommandOptions } from '../shared'
import { sendRTMPStream, testFfmpegStreamError } from './live'
})
}
+ // ---------------------------------------------------------------------------
+
+ 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
path,
attaches,
- fields: omit(fields, 'thumbnailfile', 'previewfile'),
+ fields: omit(fields, [ 'thumbnailfile', 'previewfile' ]),
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
}))
return body.video
}
+ async quickCreate (options: OverrideCommandOptions & {
+ saveReplay: boolean
+ permanentLive: boolean
+ privacy?: VideoPrivacy
+ }) {
+ const { saveReplay, permanentLive, privacy } = options
+
+ const { uuid } = await this.create({
+ ...options,
+
+ fields: {
+ name: 'live',
+ permanentLive,
+ saveReplay,
+ channelId: this.server.store.channel.id,
+ privacy
+ }
+ })
+
+ const video = await this.server.videos.getWithToken({ id: uuid })
+ const live = await this.get({ videoId: uuid })
+
+ return { video, live }
+ }
+
+ // ---------------------------------------------------------------------------
+
async sendRTMPStreamInVideo (options: OverrideCommandOptions & {
videoId: number | string
fixtureName?: string
return testFfmpegStreamError(command, options.shouldHaveError)
}
+ // ---------------------------------------------------------------------------
+
waitUntilPublished (options: OverrideCommandOptions & {
videoId: number | string
}) {
return this.waitUntilState({ videoId, state: VideoState.LIVE_ENDED })
}
- waitUntilSegmentGeneration (options: OverrideCommandOptions & {
+ async waitUntilSegmentGeneration (options: OverrideCommandOptions & {
+ server: PeerTubeServer
videoUUID: string
- resolution: number
+ playlistNumber: number
segment: number
+ objectStorage: boolean
}) {
- const { resolution, segment, videoUUID } = options
- const segmentName = `${resolution}-00000${segment}.ts`
+ const { server, objectStorage, playlistNumber, segment, videoUUID } = options
+
+ const segmentName = `${playlistNumber}-00000${segment}.ts`
+ const baseUrl = objectStorage
+ ? ObjectStorageCommand.getMockPlaylistBaseUrl() + 'hls'
+ : server.url + '/static/streaming-playlists/hls'
+
+ let error = true
+
+ while (error) {
+ try {
+ await this.getRawRequest({
+ ...options,
+
+ url: `${baseUrl}/${videoUUID}/${segmentName}`,
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+
+ const video = await server.videos.get({ id: videoUUID })
+ const hlsPlaylist = video.streamingPlaylists[0]
- return this.server.servers.waitUntilLog(`${videoUUID}/${segmentName}`, 2, false)
+ const shaBody = await server.streamingPlaylists.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url })
+
+ if (!shaBody[segmentName]) {
+ throw new Error('Segment SHA does not exist')
+ }
+
+ error = false
+ } catch {
+ error = true
+ await wait(100)
+ }
+ }
}
- async waitUntilSaved (options: OverrideCommandOptions & {
+ async waitUntilReplacedByReplay (options: OverrideCommandOptions & {
videoId: number | string
}) {
let video: VideoDetails
} while (video.isLive === true || video.state.id !== VideoState.PUBLISHED)
}
+ // ---------------------------------------------------------------------------
+
+ getSegmentFile (options: OverrideCommandOptions & {
+ videoUUID: string
+ playlistNumber: number
+ segment: number
+ objectStorage?: boolean // default false
+ }) {
+ const { playlistNumber, segment, videoUUID, objectStorage = false } = options
+
+ const segmentName = `${playlistNumber}-00000${segment}.ts`
+ const baseUrl = objectStorage
+ ? ObjectStorageCommand.getMockPlaylistBaseUrl()
+ : `${this.server.url}/static/streaming-playlists/hls`
+
+ const url = `${baseUrl}/${videoUUID}/${segmentName}`
+
+ return this.getRawRequest({
+ ...options,
+
+ url,
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ getPlaylistFile (options: OverrideCommandOptions & {
+ videoUUID: string
+ playlistName: string
+ objectStorage?: boolean // default false
+ }) {
+ const { playlistName, videoUUID, objectStorage = false } = options
+
+ const baseUrl = objectStorage
+ ? ObjectStorageCommand.getMockPlaylistBaseUrl()
+ : `${this.server.url}/static/streaming-playlists/hls`
+
+ const url = `${baseUrl}/${videoUUID}/${playlistName}`
+
+ return this.getRawRequest({
+ ...options,
+
+ url,
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
async countPlaylists (options: OverrideCommandOptions & {
videoUUID: string
}) {