X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fextra-utils%2Fvideos%2Flive.ts;h=c8acb90daa5b5f453c410c9546a6bc2d22fef7d4;hb=6b67897e2eab96978daee40aeaf716835856d65d;hp=4bfcc583e49c4580a720d452e9d2054fa8d035b9;hpb=2a9562fc5894509e63016b1fe09f6dce0c4b6e5e;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/extra-utils/videos/live.ts b/shared/extra-utils/videos/live.ts index 4bfcc583e..c8acb90da 100644 --- a/shared/extra-utils/videos/live.ts +++ b/shared/extra-utils/videos/live.ts @@ -53,15 +53,15 @@ function createLive (url: string, token: string, fields: LiveVideoCreate, status }) } -async function sendRTMPStreamInVideo (url: string, token: string, videoId: number | string) { +async function sendRTMPStreamInVideo (url: string, token: string, videoId: number | string, fixtureName?: string) { const res = await getLive(url, token, videoId) const videoLive = res.body as LiveVideo - return sendRTMPStream(videoLive.rtmpUrl, videoLive.streamKey) + return sendRTMPStream(videoLive.rtmpUrl, videoLive.streamKey, fixtureName) } -function sendRTMPStream (rtmpBaseUrl: string, streamKey: string) { - const fixture = buildAbsoluteFixturePath('video_short.mp4') +function sendRTMPStream (rtmpBaseUrl: string, streamKey: string, fixtureName = 'video_short.mp4') { + const fixture = buildAbsoluteFixturePath(fixtureName) const command = ffmpeg(fixture) command.inputOption('-stream_loop -1') @@ -128,7 +128,15 @@ async function stopFfmpeg (command: ffmpeg.FfmpegCommand) { await wait(500) } -async function waitUntilLiveStarts (url: string, token: string, videoId: number | string) { +function waitUntilLiveStarts (url: string, token: string, videoId: number | string) { + return waitWhileLiveState(url, token, videoId, VideoState.WAITING_FOR_LIVE) +} + +function waitUntilLivePublished (url: string, token: string, videoId: number | string) { + return waitWhileLiveState(url, token, videoId, VideoState.PUBLISHED) +} + +async function waitWhileLiveState (url: string, token: string, videoId: number | string, state: VideoState) { let video: VideoDetails do { @@ -136,11 +144,11 @@ async function waitUntilLiveStarts (url: string, token: string, videoId: number video = res.body await wait(500) - } while (video.state.id === VideoState.WAITING_FOR_LIVE) + } while (video.state.id === state) } async function checkLiveCleanup (server: ServerInfo, videoUUID: string, resolutions: number[] = []) { - const basePath = buildServerDirectory(server.internalServerNumber, 'streaming-playlists') + const basePath = buildServerDirectory(server, 'streaming-playlists') const hlsPath = join(basePath, 'hls', videoUUID) if (resolutions.length === 0) { @@ -168,6 +176,7 @@ async function checkLiveCleanup (server: ServerInfo, videoUUID: string, resoluti export { getLive, + waitUntilLivePublished, updateLive, waitUntilLiveStarts, createLive,