X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fserver-commands%2Fvideos%2Flive-command.ts;h=dc3c5a86ef8f45862665448648bcf47644633f00;hb=fabe350bcac2d24c8524d4b6bb776dba7e374c8d;hp=2ff65881be3a108c95ab87d13937befa8a943428;hpb=26e3e98ff0e222a9fb9226938ac6902af77921bd;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts index 2ff65881b..dc3c5a86e 100644 --- a/shared/server-commands/videos/live-command.ts +++ b/shared/server-commands/videos/live-command.ts @@ -1,9 +1,8 @@ /* 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 { omit, wait } from '@shared/core-utils' import { HttpStatusCode, LiveVideo, @@ -13,9 +12,11 @@ import { 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' @@ -35,6 +36,8 @@ export class LiveCommand extends AbstractCommand { }) } + // --------------------------------------------------------------------------- + listSessions (options: OverrideCommandOptions & { videoId: number | string }) { @@ -71,6 +74,8 @@ export class LiveCommand extends AbstractCommand { }) } + // --------------------------------------------------------------------------- + update (options: OverrideCommandOptions & { videoId: number | string fields: LiveVideoUpdate @@ -103,7 +108,7 @@ export class LiveCommand extends AbstractCommand { path, attaches, - fields: omit(fields, 'thumbnailfile', 'previewfile'), + fields: omit(fields, [ 'thumbnailfile', 'previewfile' ]), implicitToken: true, defaultExpectedStatus: HttpStatusCode.OK_200 })) @@ -111,6 +116,34 @@ export class LiveCommand extends AbstractCommand { return body.video } + async quickCreate (options: OverrideCommandOptions & { + saveReplay: boolean + permanentLive: boolean + privacy?: VideoPrivacy + }) { + const { saveReplay, permanentLive, privacy = VideoPrivacy.PUBLIC } = options + + const { uuid } = await this.create({ + ...options, + + fields: { + name: 'live', + permanentLive, + saveReplay, + replaySettings: { privacy }, + 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 @@ -131,6 +164,8 @@ export class LiveCommand extends AbstractCommand { return testFfmpegStreamError(command, options.shouldHaveError) } + // --------------------------------------------------------------------------- + waitUntilPublished (options: OverrideCommandOptions & { videoId: number | string }) { @@ -152,15 +187,55 @@ export class LiveCommand extends AbstractCommand { 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 + objectStorageBaseUrl?: string }) { - const { resolution, segment, videoUUID } = options - const segmentName = `${resolution}-00000${segment}.ts` - - return this.server.servers.waitUntilLog(`${videoUUID}/${segmentName}`, 2, false) + const { + server, + objectStorage, + playlistNumber, + segment, + videoUUID, + objectStorageBaseUrl = ObjectStorageCommand.getMockPlaylistBaseUrl() + } = options + + const segmentName = `${playlistNumber}-00000${segment}.ts` + const baseUrl = objectStorage + ? join(objectStorageBaseUrl, '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] + + 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 waitUntilReplacedByReplay (options: OverrideCommandOptions & { @@ -175,6 +250,56 @@ export class LiveCommand extends AbstractCommand { } 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 }) {