]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { FfmpegCommand } from 'fluent-ffmpeg' | |
6 | import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' | |
7 | import { | |
8 | addVideoToBlacklist, | |
9 | checkLiveCleanup, | |
10 | cleanupTests, | |
11 | createLive, | |
12 | doubleFollow, | |
13 | flushAndRunMultipleServers, | |
14 | getVideo, | |
15 | getVideosList, | |
16 | removeVideo, | |
17 | sendRTMPStreamInVideo, | |
18 | ServerInfo, | |
19 | setAccessTokensToServers, | |
20 | setDefaultVideoChannel, | |
21 | stopFfmpeg, | |
22 | testFfmpegStreamError, | |
23 | updateCustomSubConfig, | |
24 | updateVideo, | |
25 | waitJobs, | |
26 | waitUntilLiveStarts | |
27 | } from '../../../../shared/extra-utils' | |
28 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
29 | ||
30 | const expect = chai.expect | |
31 | ||
32 | describe('Save replay setting', function () { | |
33 | let servers: ServerInfo[] = [] | |
34 | let liveVideoUUID: string | |
35 | let ffmpegCommand: FfmpegCommand | |
36 | ||
37 | async function createLiveWrapper (saveReplay: boolean) { | |
38 | if (liveVideoUUID) { | |
39 | try { | |
40 | await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
41 | await waitJobs(servers) | |
42 | } catch {} | |
43 | } | |
44 | ||
45 | const attributes: LiveVideoCreate = { | |
46 | channelId: servers[0].videoChannel.id, | |
47 | privacy: VideoPrivacy.PUBLIC, | |
48 | name: 'my super live', | |
49 | saveReplay | |
50 | } | |
51 | ||
52 | const res = await createLive(servers[0].url, servers[0].accessToken, attributes) | |
53 | return res.body.video.uuid | |
54 | } | |
55 | ||
56 | async function checkVideosExist (videoId: string, existsInList: boolean, getStatus?: number) { | |
57 | for (const server of servers) { | |
58 | const length = existsInList ? 1 : 0 | |
59 | ||
60 | const resVideos = await getVideosList(server.url) | |
61 | expect(resVideos.body.data).to.have.lengthOf(length) | |
62 | expect(resVideos.body.total).to.equal(length) | |
63 | ||
64 | if (getStatus) { | |
65 | await getVideo(server.url, videoId, getStatus) | |
66 | } | |
67 | } | |
68 | } | |
69 | ||
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) | |
74 | } | |
75 | } | |
76 | ||
77 | before(async function () { | |
78 | this.timeout(120000) | |
79 | ||
80 | servers = await flushAndRunMultipleServers(2) | |
81 | ||
82 | // Get the access tokens | |
83 | await setAccessTokensToServers(servers) | |
84 | await setDefaultVideoChannel(servers) | |
85 | ||
86 | // Server 1 and server 2 follow each other | |
87 | await doubleFollow(servers[0], servers[1]) | |
88 | ||
89 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
90 | live: { | |
91 | enabled: true, | |
92 | allowReplay: true, | |
93 | maxDuration: null, | |
94 | transcoding: { | |
95 | enabled: false, | |
96 | resolutions: { | |
97 | '240p': true, | |
98 | '360p': true, | |
99 | '480p': true, | |
100 | '720p': true, | |
101 | '1080p': true, | |
102 | '2160p': true | |
103 | } | |
104 | } | |
105 | } | |
106 | }) | |
107 | }) | |
108 | ||
109 | describe('With save replay disabled', function () { | |
110 | ||
111 | before(async function () { | |
112 | this.timeout(10000) | |
113 | }) | |
114 | ||
115 | it('Should correctly create and federate the "waiting for stream" live', async function () { | |
116 | this.timeout(20000) | |
117 | ||
118 | liveVideoUUID = await createLiveWrapper(false) | |
119 | ||
120 | await waitJobs(servers) | |
121 | ||
122 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) | |
123 | await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE) | |
124 | }) | |
125 | ||
126 | it('Should correctly have updated the live and federated it when streaming in the live', async function () { | |
127 | this.timeout(20000) | |
128 | ||
129 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
130 | await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
131 | ||
132 | await waitJobs(servers) | |
133 | ||
134 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | |
135 | await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) | |
136 | }) | |
137 | ||
138 | it('Should correctly delete the video files after the stream ended', async function () { | |
139 | this.timeout(30000) | |
140 | ||
141 | await stopFfmpeg(ffmpegCommand) | |
142 | ||
143 | await waitJobs(servers) | |
144 | ||
145 | // Live still exist, but cannot be played anymore | |
146 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) | |
147 | await checkVideoState(liveVideoUUID, VideoState.LIVE_ENDED) | |
148 | ||
149 | // No resolutions saved since we did not save replay | |
150 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | |
151 | }) | |
152 | ||
153 | it('Should correctly terminate the stream on blacklist and delete the live', async function () { | |
154 | this.timeout(40000) | |
155 | ||
156 | liveVideoUUID = await createLiveWrapper(false) | |
157 | ||
158 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
159 | await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
160 | ||
161 | await waitJobs(servers) | |
162 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | |
163 | ||
164 | await Promise.all([ | |
165 | addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), | |
166 | testFfmpegStreamError(ffmpegCommand, true) | |
167 | ]) | |
168 | ||
169 | await waitJobs(servers) | |
170 | ||
171 | await checkVideosExist(liveVideoUUID, false) | |
172 | ||
173 | await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) | |
174 | await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) | |
175 | ||
176 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | |
177 | }) | |
178 | ||
179 | it('Should correctly terminate the stream on delete and delete the video', async function () { | |
180 | this.timeout(40000) | |
181 | ||
182 | liveVideoUUID = await createLiveWrapper(false) | |
183 | ||
184 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
185 | await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
186 | ||
187 | await waitJobs(servers) | |
188 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | |
189 | ||
190 | await Promise.all([ | |
191 | testFfmpegStreamError(ffmpegCommand, true), | |
192 | removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
193 | ]) | |
194 | ||
195 | await waitJobs(servers) | |
196 | ||
197 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) | |
198 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | |
199 | }) | |
200 | }) | |
201 | ||
202 | describe('With save replay enabled', function () { | |
203 | ||
204 | it('Should correctly create and federate the "waiting for stream" live', async function () { | |
205 | this.timeout(20000) | |
206 | ||
207 | liveVideoUUID = await createLiveWrapper(true) | |
208 | ||
209 | await waitJobs(servers) | |
210 | ||
211 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.OK_200) | |
212 | await checkVideoState(liveVideoUUID, VideoState.WAITING_FOR_LIVE) | |
213 | }) | |
214 | ||
215 | it('Should correctly have updated the live and federated it when streaming in the live', async function () { | |
216 | this.timeout(20000) | |
217 | ||
218 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
219 | await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
220 | ||
221 | await waitJobs(servers) | |
222 | ||
223 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | |
224 | await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) | |
225 | }) | |
226 | ||
227 | it('Should correctly have saved the live and federated it after the streaming', async function () { | |
228 | this.timeout(30000) | |
229 | ||
230 | await stopFfmpeg(ffmpegCommand) | |
231 | ||
232 | await waitJobs(servers) | |
233 | ||
234 | // Live has been transcoded | |
235 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | |
236 | await checkVideoState(liveVideoUUID, VideoState.PUBLISHED) | |
237 | }) | |
238 | ||
239 | it('Should update the saved live and correctly federate the updated attributes', async function () { | |
240 | this.timeout(30000) | |
241 | ||
242 | await updateVideo(servers[0].url, servers[0].accessToken, liveVideoUUID, { name: 'video updated' }) | |
243 | await waitJobs(servers) | |
244 | ||
245 | for (const server of servers) { | |
246 | const res = await getVideo(server.url, liveVideoUUID) | |
247 | expect(res.body.name).to.equal('video updated') | |
248 | expect(res.body.isLive).to.be.false | |
249 | } | |
250 | }) | |
251 | ||
252 | it('Should have cleaned up the live files', async function () { | |
253 | await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) | |
254 | }) | |
255 | ||
256 | it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () { | |
257 | this.timeout(40000) | |
258 | ||
259 | liveVideoUUID = await createLiveWrapper(true) | |
260 | ||
261 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
262 | await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
263 | ||
264 | await waitJobs(servers) | |
265 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | |
266 | ||
267 | await Promise.all([ | |
268 | addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideoUUID, 'bad live', true), | |
269 | testFfmpegStreamError(ffmpegCommand, true) | |
270 | ]) | |
271 | ||
272 | await waitJobs(servers) | |
273 | ||
274 | await checkVideosExist(liveVideoUUID, false) | |
275 | ||
276 | await getVideo(servers[0].url, liveVideoUUID, HttpStatusCode.UNAUTHORIZED_401) | |
277 | await getVideo(servers[1].url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) | |
278 | ||
279 | await checkLiveCleanup(servers[0], liveVideoUUID, [ 720 ]) | |
280 | }) | |
281 | ||
282 | it('Should correctly terminate the stream on delete and delete the video', async function () { | |
283 | this.timeout(40000) | |
284 | ||
285 | liveVideoUUID = await createLiveWrapper(true) | |
286 | ||
287 | ffmpegCommand = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
288 | await waitUntilLiveStarts(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
289 | ||
290 | await waitJobs(servers) | |
291 | await checkVideosExist(liveVideoUUID, true, HttpStatusCode.OK_200) | |
292 | ||
293 | await Promise.all([ | |
294 | removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID), | |
295 | testFfmpegStreamError(ffmpegCommand, true) | |
296 | ]) | |
297 | ||
298 | await waitJobs(servers) | |
299 | ||
300 | await checkVideosExist(liveVideoUUID, false, HttpStatusCode.NOT_FOUND_404) | |
301 | await checkLiveCleanup(servers[0], liveVideoUUID, []) | |
302 | }) | |
303 | }) | |
304 | ||
305 | after(async function () { | |
306 | await cleanupTests(servers) | |
307 | }) | |
308 | }) |