X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fserver-commands%2Fvideos%2Flive-command.ts;h=3df47ed4d7d8f2799ae84293b71668711197541f;hb=e722fb5923ddf11d72e48cec9788abc64327c22f;hp=c24c7a5fcf48976af7daf74a4071fedb5c7ed0cd;hpb=4ec52d04dcc5d664612331f8e08d7d90da990415;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts index c24c7a5fc..3df47ed4d 100644 --- a/shared/server-commands/videos/live-command.ts +++ b/shared/server-commands/videos/live-command.ts @@ -4,7 +4,17 @@ 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 { + 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 +35,42 @@ export class LiveCommand extends AbstractCommand { }) } + listSessions (options: OverrideCommandOptions & { + videoId: number | string + }) { + const path = `/api/v1/videos/live/${options.videoId}/sessions` + + return this.getRequestBody>({ + ...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({ + ...options, + + path, + implicitToken: true, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + update (options: OverrideCommandOptions & { videoId: number | string fields: LiveVideoUpdate @@ -108,13 +154,33 @@ 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 waitUntilReplacedByReplay (options: OverrideCommandOptions & {