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,
27 } from '../../../../shared/extra-utils'
29 const expect = chai.expect
31 describe('Save replay setting', function () {
32 let servers: ServerInfo[] = []
33 let liveVideoUUID: string
34 let ffmpegCommand: FfmpegCommand
36 async function createLiveWrapper (saveReplay: boolean) {
39 await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
40 await waitJobs(servers)
44 const attributes: LiveVideoCreate = {
45 channelId: servers[0].videoChannel.id,
46 privacy: VideoPrivacy.PUBLIC,
47 name: 'my super live',
51 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
52 return res.body.video.uuid
55 async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) {
56 for (const server of servers) {
57 const length = existsInList ? 1 : 0
59 const resVideos = await getVideosList(server.url)
60 expect(resVideos.body.data).to.have.lengthOf(length)
61 expect(resVideos.body.total).to.equal(length)
64 await getVideo(server.url, videoId, getStatus)
69 async function checkVideoState (videoId: string, state: VideoState) {
70 for (const server of servers) {
71 const res = await getVideo(server.url, videoId)
72 expect((res.body as VideoDetails).state.id).to.equal(state)
76 before(async function () {
79 servers = await flushAndRunMultipleServers(2)
81 // Get the access tokens
82 await setAccessTokensToServers(servers)
83 await setDefaultVideoChannel(servers)
85 // Server 1 and server 2 follow each other
86 await doubleFollow(servers[0], servers[1])
88 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
108 describe('With save replay disabled', function () {
110 before(async function () {
114 it('Should correctly create and federate the "waiting for stream" live', async function () {
117 liveVideoUUID = await createLiveWrapper(false)
119 await waitJobs(servers)
121 await checkVideosExist(liveVideoUUID, false, 200)
122 await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE)
125 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
128 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
129 await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
131 await waitJobs(servers)
133 await checkVideosExist(liveVideoUUID, true, 200)
134 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
137 it('Should correctly delete the video files after the stream ended', async function () {
140 await stopFfmpeg(ffmpegCommand)
142 await waitJobs(servers)
144 // Live still exist, but cannot be played anymore
145 await checkVideosExist(liveVideoUUID, false, 200)
146 await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED)
148 // No resolutions saved since we did not save replay
149 await checkLiveCleanup(servers[0], liveVideoUUID, [])
152 it('Should correctly terminate the stream on blacklist and delete the live', async function () {
155 liveVideoUUID = await createLiveWrapper(false)
157 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
158 await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
160 await waitJobs(servers)
161 await checkVideosExist(liveVideoUUID, true, 200)
164 addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true),
165 testFfmpegStreamError(ffmpegCommand, true)
168 await waitJobs(servers)
170 await checkVideosExist(liveVideoUUID, false)
172 await getVideo(servers[0].url, liveVideoUUID, 401)
173 await getVideo(servers[1].url, liveVideoUUID, 404)
175 await checkLiveCleanup(servers[0], liveVideoUUID, [])
178 it('Should correctly terminate the stream on delete and delete the video', async function () {
181 liveVideoUUID = await createLiveWrapper(false)
183 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
184 await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
186 await waitJobs(servers)
187 await checkVideosExist(liveVideoUUID, true, 200)
190 testFfmpegStreamError(ffmpegCommand, true),
191 removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
194 await waitJobs(servers)
196 await checkVideosExist(liveVideoUUID, false, 404)
197 await checkLiveCleanup(servers[0], liveVideoUUID, [])
201 describe('With save replay enabled', function () {
203 it('Should correctly create and federate the "waiting for stream" live', async function () {
206 liveVideoUUID = await createLiveWrapper(true)
208 await waitJobs(servers)
210 await checkVideosExist(liveVideoUUID, false, 200)
211 await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE)
214 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
217 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
218 await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
220 await waitJobs(servers)
222 await checkVideosExist(liveVideoUUID, true, 200)
223 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
226 it('Should correctly have saved the live and federated it after the streaming', async function () {
229 await stopFfmpeg(ffmpegCommand)
231 await waitJobs(servers)
233 // Live has been transcoded
234 await checkVideosExist(liveVideoUUID, true, 200)
235 await checkVideoState(liveVideoUUID, VideoState.PUBLISHED)
238 it('Should update the saved live and correctly federate the updated attributes', async function () {
241 await updateVideo(servers[0].url, servers[0].accessToken, liveVideoUUID, { name: 'video updated' })
242 await waitJobs(servers)
244 for (const server of servers) {
245 const res = await getVideo(server.url, liveVideoUUID)
246 expect(res.body.name).to.equal('video updated')
247 expect(res.body.isLive).to.be.false
251 it('Should have cleaned up the live files', async function () {
252 await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ])
255 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () {
258 liveVideoUUID = await createLiveWrapper(true)
260 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
261 await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
263 await waitJobs(servers)
264 await checkVideosExist(liveVideoUUID, true, 200)
267 addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true),
268 testFfmpegStreamError(ffmpegCommand, true)
271 await waitJobs(servers)
273 await checkVideosExist(liveVideoUUID, false)
275 await getVideo(servers[0].url, liveVideoUUID, 401)
276 await getVideo(servers[1].url, liveVideoUUID, 404)
278 await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ])
281 it('Should correctly terminate the stream on delete and delete the video', async function () {
284 liveVideoUUID = await createLiveWrapper(true)
286 ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
287 await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID)
289 await waitJobs(servers)
290 await checkVideosExist(liveVideoUUID, true, 200)
293 removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID),
294 testFfmpegStreamError(ffmpegCommand, true)
297 await waitJobs(servers)
299 await checkVideosExist(liveVideoUUID, false, 404)
300 await checkLiveCleanup(servers[0], liveVideoUUID, [])
304 after(async function () {
305 await cleanupTests(servers)