1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { FfmpegCommand } from 'fluent-ffmpeg'
6 import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models'
13 flushAndRunMultipleServers,
17 sendRTMPStreamInVideo,
19 setAccessTokensToServers,
20 setDefaultVideoChannel,
22 testFfmpegStreamError,
23 updateCustomSubConfig,
26 waitUntilLivePublished
27 } from '../../../../shared/extra-utils'
28 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
30 const expect = chai.expect
32 describe('Save replay setting', function () {
33 let servers: ServerInfo[] = []
34 let liveVideoUUID: string
35 let ffmpegCommand: FfmpegCommand
37 async function createLiveWrapper (saveReplay: boolean) {
40 await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
41 await waitJobs(servers)
45 const attributes: LiveVideoCreate = {
46 channelId: servers[0].videoChannel.id,
47 privacy: VideoPrivacy.PUBLIC,
48 name: 'my super live',
52 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
53 return res.body.video.uuid
56 async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) {
57 for (const server of servers) {
58 const length = existsInList ? 1 : 0
60 const resVideos = await getVideosList(server.url)
61 expect(resVideos.body.data).to.have.lengthOf(length)
62 expect(resVideos.body.total).to.equal(length)
65 await getVideo(server.url, videoId, getStatus)
70 async function checkVideoState (videoId: string, state: VideoState) {
71 for (const server of servers) {
72 const res = await getVideo(server.url, videoId)
73 expect((res.body as VideoDetails).state.id).to.equal(state)
77 before(async function () {
80 servers = await flushAndRunMultipleServers(2)
82 // Get the access tokens
83 await setAccessTokensToServers(servers)
84 await setDefaultVideoChannel(servers)
86 // Server 1 and server 2 follow each other
87 await doubleFollow(servers[0], servers[1])
89 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
109 describe('With save replay disabled', function () {
111 before(async function () {
115 it('Should correctly create and federate the "waiting for stream" live', async function () {
118 liveVideoUUID = await createLiveWrapper(false)
120 await waitJobs(servers)
122 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200)
123 await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE)
126 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
129 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
130 await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoUUID)
132 await waitJobs(servers)
134 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
135 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
138 it('Should correctly delete the video files after the stream ended', async function () {
141 await stopFfmpeg(ffmpegCommand)
143 await waitJobs(servers)
145 // Live still exist, but cannot be played anymore
146 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200)
147 await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED)
149 await waitJobs(servers)
151 // No resolutions saved since we did not save replay
152 await checkLiveCleanup(servers[0], liveVideoUUID, [])
155 it('Should correctly terminate the stream on blacklist and delete the live', async function () {
158 liveVideoUUID = await createLiveWrapper(false)
160 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
161 await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoUUID)
163 await waitJobs(servers)
164 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
167 addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true),
168 testFfmpegStreamError(ffmpegCommand, true)
171 await waitJobs(servers)
173 await checkVideosExist(liveVideoUUID, false)
175 await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401)
176 await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404)
178 await checkLiveCleanup(servers[0], liveVideoUUID, [])
181 it('Should correctly terminate the stream on delete and delete the video', async function () {
184 liveVideoUUID = await createLiveWrapper(false)
186 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
187 await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoUUID)
189 await waitJobs(servers)
190 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
193 testFfmpegStreamError(ffmpegCommand, true),
194 removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
197 await waitJobs(servers)
199 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
200 await checkLiveCleanup(servers[0], liveVideoUUID, [])
204 describe('With save replay enabled', function () {
206 it('Should correctly create and federate the "waiting for stream" live', async function () {
209 liveVideoUUID = await createLiveWrapper(true)
211 await waitJobs(servers)
213 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200)
214 await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE)
217 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
220 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
221 await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoUUID)
223 await waitJobs(servers)
225 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
226 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
229 it('Should correctly have saved the live and federated it after the streaming', async function () {
232 await stopFfmpeg(ffmpegCommand)
234 await waitJobs(servers)
236 // Live has been transcoded
237 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
238 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
241 it('Should update the saved live and correctly federate the updated attributes', async function () {
244 await updateVideo(servers[0].url, servers[0].accessToken, liveVideoUUID, { name: 'video updated' })
245 await waitJobs(servers)
247 for (const server of servers) {
248 const res = await getVideo(server.url, liveVideoUUID)
249 expect(res.body.name).to.equal('video updated')
250 expect(res.body.isLive).to.be.false
254 it('Should have cleaned up the live files', async function () {
255 await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ])
258 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () {
261 liveVideoUUID = await createLiveWrapper(true)
263 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
264 await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoUUID)
266 await waitJobs(servers)
267 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
270 addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true),
271 testFfmpegStreamError(ffmpegCommand, true)
274 await waitJobs(servers)
276 await checkVideosExist(liveVideoUUID, false)
278 await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401)
279 await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404)
281 await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ])
284 it('Should correctly terminate the stream on delete and delete the video', async function () {
287 liveVideoUUID = await createLiveWrapper(true)
289 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
290 await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoUUID)
292 await waitJobs(servers)
293 await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200)
296 removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID),
297 testFfmpegStreamError(ffmpegCommand, true)
300 await waitJobs(servers)
302 await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404)
303 await checkLiveCleanup(servers[0], liveVideoUUID, [])
307 after(async function () {
308 await cleanupTests(servers)