X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fserver-commands%2Fvideos%2Flive-command.ts;h=cc9502c6f1efe9735092dd84b1cece35eba90857;hb=b1dbb9fefc870a90b25f5c0153589f45c9e75e3e;hp=84d127db2b8b19c8dab73140597e3da1f7008546;hpb=cea2fd90ddb3bf57c2fed77128938d12d4c2be6b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts index 84d127db2..cc9502c6f 100644 --- a/shared/server-commands/videos/live-command.ts +++ b/shared/server-commands/videos/live-command.ts @@ -12,10 +12,11 @@ import { ResultList, VideoCreateResult, VideoDetails, + VideoPrivacy, VideoState } from '@shared/models' import { unwrapBody } from '../requests' -import { ObjectStorageCommand } from '../server' +import { ObjectStorageCommand, PeerTubeServer } from '../server' import { AbstractCommand, OverrideCommandOptions } from '../shared' import { sendRTMPStream, testFfmpegStreamError } from './live' @@ -115,6 +116,31 @@ export class LiveCommand extends AbstractCommand { 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 & { @@ -160,27 +186,47 @@ export class LiveCommand extends AbstractCommand { return this.waitUntilState({ videoId, state: VideoState.LIVE_ENDED }) } - waitUntilSegmentGeneration (options: OverrideCommandOptions & { + async waitUntilSegmentGeneration (options: OverrideCommandOptions & { + server: PeerTubeServer videoUUID: string playlistNumber: number segment: number - totalSessions?: number + objectStorage: boolean }) { - const { playlistNumber, segment, videoUUID, totalSessions = 1 } = options + 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' - return this.server.servers.waitUntilLog(`${videoUUID}/${segmentName}`, totalSessions * 2, false) - } + let error = true - waitUntilSegmentUpload (options: OverrideCommandOptions & { - playlistNumber: number - segment: number - totalSessions?: number - }) { - const { playlistNumber, segment, totalSessions = 1 } = options - const segmentName = `${playlistNumber}-00000${segment}.ts` + 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') + } - return this.server.servers.waitUntilLog(`${segmentName} in bucket `, totalSessions * 2, false) + error = false + } catch { + error = true + await wait(100) + } + } } async waitUntilReplacedByReplay (options: OverrideCommandOptions & { @@ -207,7 +253,7 @@ export class LiveCommand extends AbstractCommand { const segmentName = `${playlistNumber}-00000${segment}.ts` const baseUrl = objectStorage - ? ObjectStorageCommand.getPlaylistBaseUrl() + ? ObjectStorageCommand.getMockPlaylistBaseUrl() : `${this.server.url}/static/streaming-playlists/hls` const url = `${baseUrl}/${videoUUID}/${segmentName}` @@ -229,7 +275,7 @@ export class LiveCommand extends AbstractCommand { const { playlistName, videoUUID, objectStorage = false } = options const baseUrl = objectStorage - ? ObjectStorageCommand.getPlaylistBaseUrl() + ? ObjectStorageCommand.getMockPlaylistBaseUrl() : `${this.server.url}/static/streaming-playlists/hls` const url = `${baseUrl}/${videoUUID}/${playlistName}`