]>
Commit | Line | Data |
---|---|---|
af4ae64f C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
ca5c612b C |
5 | import { join } from 'path' |
6 | import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' | |
053aed43 | 7 | import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' |
0d8de275 | 8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
af4ae64f | 9 | import { |
68e70a74 | 10 | addVideoToBlacklist, |
ca5c612b | 11 | buildServerDirectory, |
bd54ad19 | 12 | checkLiveCleanup, |
5c0904fc | 13 | checkLiveSegmentHash, |
bd54ad19 | 14 | checkResolutionsInMasterPlaylist, |
af4ae64f C |
15 | cleanupTests, |
16 | createLive, | |
17 | doubleFollow, | |
18 | flushAndRunMultipleServers, | |
19 | getLive, | |
1fd61899 | 20 | getMyVideosWithFilter, |
5c0904fc | 21 | getPlaylist, |
af4ae64f C |
22 | getVideo, |
23 | getVideosList, | |
1fd61899 | 24 | getVideosWithFilters, |
5c0904fc | 25 | killallServers, |
af4ae64f C |
26 | makeRawRequest, |
27 | removeVideo, | |
5c0904fc | 28 | reRunServer, |
68e70a74 | 29 | sendRTMPStream, |
bd54ad19 | 30 | sendRTMPStreamInVideo, |
af4ae64f C |
31 | ServerInfo, |
32 | setAccessTokensToServers, | |
33 | setDefaultVideoChannel, | |
bd54ad19 | 34 | stopFfmpeg, |
97969c4e | 35 | testFfmpegStreamError, |
af4ae64f C |
36 | testImage, |
37 | updateCustomSubConfig, | |
38 | updateLive, | |
1fd61899 | 39 | uploadVideoAndGetId, |
e4bf7856 | 40 | wait, |
bd54ad19 | 41 | waitJobs, |
0e856b78 | 42 | waitUntilLiveEnded, |
6b67897e | 43 | waitUntilLivePublished, |
8ebf2a5d | 44 | waitUntilLivePublishedOnAllServers, |
5cac83a7 | 45 | waitUntilLiveSegmentGeneration |
af4ae64f C |
46 | } from '../../../../shared/extra-utils' |
47 | ||
48 | const expect = chai.expect | |
49 | ||
50 | describe('Test live', function () { | |
51 | let servers: ServerInfo[] = [] | |
af4ae64f C |
52 | |
53 | before(async function () { | |
54 | this.timeout(120000) | |
55 | ||
56 | servers = await flushAndRunMultipleServers(2) | |
57 | ||
58 | // Get the access tokens | |
59 | await setAccessTokensToServers(servers) | |
60 | await setDefaultVideoChannel(servers) | |
61 | ||
62 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
63 | live: { | |
64 | enabled: true, | |
68e70a74 C |
65 | allowReplay: true, |
66 | transcoding: { | |
67 | enabled: false | |
68 | } | |
af4ae64f C |
69 | } |
70 | }) | |
71 | ||
72 | // Server 1 and server 2 follow each other | |
73 | await doubleFollow(servers[0], servers[1]) | |
74 | }) | |
75 | ||
76 | describe('Live creation, update and delete', function () { | |
68e70a74 | 77 | let liveVideoUUID: string |
af4ae64f C |
78 | |
79 | it('Should create a live with the appropriate parameters', async function () { | |
80 | this.timeout(20000) | |
81 | ||
82 | const attributes: LiveVideoCreate = { | |
83 | category: 1, | |
84 | licence: 2, | |
85 | language: 'fr', | |
86 | description: 'super live description', | |
87 | support: 'support field', | |
88 | channelId: servers[0].videoChannel.id, | |
89 | nsfw: false, | |
90 | waitTranscoding: false, | |
91 | name: 'my super live', | |
92 | tags: [ 'tag1', 'tag2' ], | |
93 | commentsEnabled: false, | |
94 | downloadEnabled: false, | |
95 | saveReplay: true, | |
96 | privacy: VideoPrivacy.PUBLIC, | |
97 | previewfile: 'video_short1-preview.webm.jpg', | |
98 | thumbnailfile: 'video_short1.webm.jpg' | |
99 | } | |
100 | ||
101 | const res = await createLive(servers[0].url, servers[0].accessToken, attributes) | |
102 | liveVideoUUID = res.body.video.uuid | |
103 | ||
104 | await waitJobs(servers) | |
105 | ||
106 | for (const server of servers) { | |
107 | const resVideo = await getVideo(server.url, liveVideoUUID) | |
108 | const video: VideoDetails = resVideo.body | |
109 | ||
110 | expect(video.category.id).to.equal(1) | |
111 | expect(video.licence.id).to.equal(2) | |
112 | expect(video.language.id).to.equal('fr') | |
113 | expect(video.description).to.equal('super live description') | |
114 | expect(video.support).to.equal('support field') | |
115 | ||
116 | expect(video.channel.name).to.equal(servers[0].videoChannel.name) | |
117 | expect(video.channel.host).to.equal(servers[0].videoChannel.host) | |
118 | ||
1ab60243 C |
119 | expect(video.isLive).to.be.true |
120 | ||
af4ae64f C |
121 | expect(video.nsfw).to.be.false |
122 | expect(video.waitTranscoding).to.be.false | |
123 | expect(video.name).to.equal('my super live') | |
124 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ]) | |
125 | expect(video.commentsEnabled).to.be.false | |
126 | expect(video.downloadEnabled).to.be.false | |
127 | expect(video.privacy.id).to.equal(VideoPrivacy.PUBLIC) | |
128 | ||
129 | await testImage(server.url, 'video_short1-preview.webm', video.previewPath) | |
130 | await testImage(server.url, 'video_short1.webm', video.thumbnailPath) | |
131 | ||
132 | const resLive = await getLive(server.url, server.accessToken, liveVideoUUID) | |
133 | const live: LiveVideo = resLive.body | |
134 | ||
135 | if (server.url === servers[0].url) { | |
c655c9ef | 136 | expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') |
af4ae64f C |
137 | expect(live.streamKey).to.not.be.empty |
138 | } else { | |
139 | expect(live.rtmpUrl).to.be.null | |
140 | expect(live.streamKey).to.be.null | |
141 | } | |
142 | ||
143 | expect(live.saveReplay).to.be.true | |
144 | } | |
145 | }) | |
146 | ||
147 | it('Should have a default preview and thumbnail', async function () { | |
148 | this.timeout(20000) | |
149 | ||
150 | const attributes: LiveVideoCreate = { | |
151 | name: 'default live thumbnail', | |
152 | channelId: servers[0].videoChannel.id, | |
153 | privacy: VideoPrivacy.UNLISTED, | |
154 | nsfw: true | |
155 | } | |
156 | ||
157 | const res = await createLive(servers[0].url, servers[0].accessToken, attributes) | |
158 | const videoId = res.body.video.uuid | |
159 | ||
160 | await waitJobs(servers) | |
161 | ||
162 | for (const server of servers) { | |
163 | const resVideo = await getVideo(server.url, videoId) | |
164 | const video: VideoDetails = resVideo.body | |
165 | ||
166 | expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) | |
167 | expect(video.nsfw).to.be.true | |
168 | ||
f2eb23cd RK |
169 | await makeRawRequest(server.url + video.thumbnailPath, HttpStatusCode.OK_200) |
170 | await makeRawRequest(server.url + video.previewPath, HttpStatusCode.OK_200) | |
af4ae64f C |
171 | } |
172 | }) | |
173 | ||
174 | it('Should not have the live listed since nobody streams into', async function () { | |
175 | for (const server of servers) { | |
176 | const res = await getVideosList(server.url) | |
177 | ||
178 | expect(res.body.total).to.equal(0) | |
179 | expect(res.body.data).to.have.lengthOf(0) | |
180 | } | |
181 | }) | |
182 | ||
183 | it('Should not be able to update a live of another server', async function () { | |
f2eb23cd | 184 | await updateLive(servers[1].url, servers[1].accessToken, liveVideoUUID, { saveReplay: false }, HttpStatusCode.FORBIDDEN_403) |
af4ae64f C |
185 | }) |
186 | ||
187 | it('Should update the live', async function () { | |
188 | this.timeout(10000) | |
189 | ||
190 | await updateLive(servers[0].url, servers[0].accessToken, liveVideoUUID, { saveReplay: false }) | |
191 | await waitJobs(servers) | |
192 | }) | |
193 | ||
194 | it('Have the live updated', async function () { | |
195 | for (const server of servers) { | |
196 | const res = await getLive(server.url, server.accessToken, liveVideoUUID) | |
197 | const live: LiveVideo = res.body | |
198 | ||
199 | if (server.url === servers[0].url) { | |
c655c9ef | 200 | expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') |
af4ae64f C |
201 | expect(live.streamKey).to.not.be.empty |
202 | } else { | |
203 | expect(live.rtmpUrl).to.be.null | |
204 | expect(live.streamKey).to.be.null | |
205 | } | |
206 | ||
207 | expect(live.saveReplay).to.be.false | |
208 | } | |
209 | }) | |
210 | ||
211 | it('Delete the live', async function () { | |
212 | this.timeout(10000) | |
213 | ||
214 | await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
215 | await waitJobs(servers) | |
216 | }) | |
217 | ||
218 | it('Should have the live deleted', async function () { | |
219 | for (const server of servers) { | |
f2eb23cd RK |
220 | await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) |
221 | await getLive(server.url, server.accessToken, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) | |
af4ae64f C |
222 | } |
223 | }) | |
224 | }) | |
225 | ||
1fd61899 C |
226 | describe('Live filters', function () { |
227 | let command: any | |
228 | let liveVideoId: string | |
229 | let vodVideoId: string | |
230 | ||
231 | before(async function () { | |
232 | this.timeout(120000) | |
233 | ||
234 | vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid | |
235 | ||
236 | const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id } | |
237 | const resLive = await createLive(servers[0].url, servers[0].accessToken, liveOptions) | |
238 | liveVideoId = resLive.body.video.uuid | |
239 | ||
240 | command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) | |
8ebf2a5d | 241 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
1fd61899 C |
242 | await waitJobs(servers) |
243 | }) | |
244 | ||
245 | it('Should only display lives', async function () { | |
246 | const res = await getVideosWithFilters(servers[0].url, { isLive: true }) | |
247 | ||
248 | expect(res.body.total).to.equal(1) | |
249 | expect(res.body.data).to.have.lengthOf(1) | |
250 | expect(res.body.data[0].name).to.equal('live') | |
251 | }) | |
252 | ||
253 | it('Should not display lives', async function () { | |
254 | const res = await getVideosWithFilters(servers[0].url, { isLive: false }) | |
255 | ||
256 | expect(res.body.total).to.equal(1) | |
257 | expect(res.body.data).to.have.lengthOf(1) | |
258 | expect(res.body.data[0].name).to.equal('vod video') | |
259 | }) | |
260 | ||
261 | it('Should display my lives', async function () { | |
262 | this.timeout(60000) | |
263 | ||
264 | await stopFfmpeg(command) | |
265 | await waitJobs(servers) | |
266 | ||
267 | const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: true }) | |
268 | const videos = res.body.data as Video[] | |
269 | ||
270 | const result = videos.every(v => v.isLive) | |
271 | expect(result).to.be.true | |
272 | }) | |
273 | ||
274 | it('Should not display my lives', async function () { | |
275 | const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: false }) | |
276 | const videos = res.body.data as Video[] | |
277 | ||
278 | const result = videos.every(v => !v.isLive) | |
279 | expect(result).to.be.true | |
280 | }) | |
281 | ||
282 | after(async function () { | |
283 | await removeVideo(servers[0].url, servers[0].accessToken, vodVideoId) | |
284 | await removeVideo(servers[0].url, servers[0].accessToken, liveVideoId) | |
285 | }) | |
286 | }) | |
287 | ||
68e70a74 C |
288 | describe('Stream checks', function () { |
289 | let liveVideo: LiveVideo & VideoDetails | |
290 | let rtmpUrl: string | |
291 | ||
292 | before(function () { | |
c655c9ef | 293 | rtmpUrl = 'rtmp://' + servers[0].hostname + ':' + servers[0].rtmpPort + '' |
68e70a74 | 294 | }) |
af4ae64f | 295 | |
68e70a74 | 296 | async function createLiveWrapper () { |
97969c4e C |
297 | const liveAttributes = { |
298 | name: 'user live', | |
bd54ad19 | 299 | channelId: servers[0].videoChannel.id, |
97969c4e | 300 | privacy: VideoPrivacy.PUBLIC, |
68e70a74 | 301 | saveReplay: false |
97969c4e C |
302 | } |
303 | ||
bd54ad19 | 304 | const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) |
68e70a74 | 305 | const uuid = res.body.video.uuid |
97969c4e | 306 | |
68e70a74 C |
307 | const resLive = await getLive(servers[0].url, servers[0].accessToken, uuid) |
308 | const resVideo = await getVideo(servers[0].url, uuid) | |
97969c4e | 309 | |
68e70a74 C |
310 | return Object.assign(resVideo.body, resLive.body) as LiveVideo & VideoDetails |
311 | } | |
97969c4e | 312 | |
68e70a74 | 313 | it('Should not allow a stream without the appropriate path', async function () { |
2df6f943 | 314 | this.timeout(60000) |
97969c4e | 315 | |
68e70a74 | 316 | liveVideo = await createLiveWrapper() |
97969c4e | 317 | |
68e70a74 C |
318 | const command = sendRTMPStream(rtmpUrl + '/bad-live', liveVideo.streamKey) |
319 | await testFfmpegStreamError(command, true) | |
af4ae64f C |
320 | }) |
321 | ||
68e70a74 | 322 | it('Should not allow a stream without the appropriate stream key', async function () { |
2df6f943 | 323 | this.timeout(60000) |
97969c4e | 324 | |
68e70a74 C |
325 | const command = sendRTMPStream(rtmpUrl + '/live', 'bad-stream-key') |
326 | await testFfmpegStreamError(command, true) | |
97969c4e C |
327 | }) |
328 | ||
68e70a74 | 329 | it('Should succeed with the correct params', async function () { |
2df6f943 | 330 | this.timeout(60000) |
97969c4e | 331 | |
68e70a74 C |
332 | const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) |
333 | await testFfmpegStreamError(command, false) | |
af4ae64f C |
334 | }) |
335 | ||
1ab60243 C |
336 | it('Should list this live now someone stream into it', async function () { |
337 | for (const server of servers) { | |
338 | const res = await getVideosList(server.url) | |
339 | ||
340 | expect(res.body.total).to.equal(1) | |
341 | expect(res.body.data).to.have.lengthOf(1) | |
342 | ||
343 | const video: Video = res.body.data[0] | |
344 | ||
345 | expect(video.name).to.equal('user live') | |
346 | expect(video.isLive).to.be.true | |
347 | } | |
348 | }) | |
349 | ||
68e70a74 | 350 | it('Should not allow a stream on a live that was blacklisted', async function () { |
2df6f943 | 351 | this.timeout(60000) |
97969c4e | 352 | |
68e70a74 | 353 | liveVideo = await createLiveWrapper() |
af4ae64f | 354 | |
68e70a74 | 355 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideo.uuid) |
af4ae64f | 356 | |
68e70a74 C |
357 | const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) |
358 | await testFfmpegStreamError(command, true) | |
af4ae64f C |
359 | }) |
360 | ||
68e70a74 | 361 | it('Should not allow a stream on a live that was deleted', async function () { |
2df6f943 | 362 | this.timeout(60000) |
af4ae64f | 363 | |
68e70a74 | 364 | liveVideo = await createLiveWrapper() |
af4ae64f | 365 | |
68e70a74 | 366 | await removeVideo(servers[0].url, servers[0].accessToken, liveVideo.uuid) |
af4ae64f | 367 | |
68e70a74 C |
368 | const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) |
369 | await testFfmpegStreamError(command, true) | |
af4ae64f C |
370 | }) |
371 | }) | |
372 | ||
373 | describe('Live transcoding', function () { | |
bd54ad19 C |
374 | let liveVideoId: string |
375 | ||
376 | async function createLiveWrapper (saveReplay: boolean) { | |
377 | const liveAttributes = { | |
378 | name: 'live video', | |
379 | channelId: servers[0].videoChannel.id, | |
380 | privacy: VideoPrivacy.PUBLIC, | |
381 | saveReplay | |
382 | } | |
383 | ||
384 | const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) | |
385 | return res.body.video.uuid | |
386 | } | |
387 | ||
388 | async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { | |
389 | for (const server of servers) { | |
390 | const resList = await getVideosList(server.url) | |
391 | const videos: Video[] = resList.body.data | |
392 | ||
393 | expect(videos.find(v => v.uuid === liveVideoId)).to.exist | |
394 | ||
395 | const resVideo = await getVideo(server.url, liveVideoId) | |
396 | const video: VideoDetails = resVideo.body | |
397 | ||
398 | expect(video.streamingPlaylists).to.have.lengthOf(1) | |
399 | ||
400 | const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) | |
401 | expect(hlsPlaylist).to.exist | |
402 | ||
403 | // Only finite files are displayed | |
404 | expect(hlsPlaylist.files).to.have.lengthOf(0) | |
405 | ||
406 | await checkResolutionsInMasterPlaylist(hlsPlaylist.playlistUrl, resolutions) | |
5c0904fc C |
407 | |
408 | for (let i = 0; i < resolutions.length; i++) { | |
a800dbf3 | 409 | const segmentNum = 3 |
0d8de275 C |
410 | const segmentName = `${i}-00000${segmentNum}.ts` |
411 | await waitUntilLiveSegmentGeneration(servers[0], video.uuid, i, segmentNum) | |
5c0904fc C |
412 | |
413 | const res = await getPlaylist(`${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8`) | |
414 | const subPlaylist = res.text | |
415 | ||
416 | expect(subPlaylist).to.contain(segmentName) | |
417 | ||
418 | const baseUrlAndPath = servers[0].url + '/static/streaming-playlists/hls' | |
419 | await checkLiveSegmentHash(baseUrlAndPath, video.uuid, segmentName, hlsPlaylist) | |
420 | } | |
bd54ad19 C |
421 | } |
422 | } | |
423 | ||
424 | function updateConf (resolutions: number[]) { | |
425 | return updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
426 | live: { | |
427 | enabled: true, | |
428 | allowReplay: true, | |
c9bc850e | 429 | maxDuration: -1, |
bd54ad19 C |
430 | transcoding: { |
431 | enabled: true, | |
432 | resolutions: { | |
433 | '240p': resolutions.includes(240), | |
434 | '360p': resolutions.includes(360), | |
435 | '480p': resolutions.includes(480), | |
436 | '720p': resolutions.includes(720), | |
437 | '1080p': resolutions.includes(1080), | |
438 | '2160p': resolutions.includes(2160) | |
439 | } | |
440 | } | |
441 | } | |
442 | }) | |
443 | } | |
444 | ||
445 | before(async function () { | |
446 | await updateConf([]) | |
447 | }) | |
af4ae64f C |
448 | |
449 | it('Should enable transcoding without additional resolutions', async function () { | |
dbb15e37 | 450 | this.timeout(60000) |
bd54ad19 C |
451 | |
452 | liveVideoId = await createLiveWrapper(false) | |
453 | ||
454 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) | |
8ebf2a5d | 455 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 | 456 | await waitJobs(servers) |
af4ae64f | 457 | |
bd54ad19 C |
458 | await testVideoResolutions(liveVideoId, [ 720 ]) |
459 | ||
460 | await stopFfmpeg(command) | |
af4ae64f C |
461 | }) |
462 | ||
463 | it('Should enable transcoding with some resolutions', async function () { | |
dbb15e37 | 464 | this.timeout(60000) |
bd54ad19 C |
465 | |
466 | const resolutions = [ 240, 480 ] | |
467 | await updateConf(resolutions) | |
468 | liveVideoId = await createLiveWrapper(false) | |
469 | ||
470 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) | |
8ebf2a5d | 471 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 C |
472 | await waitJobs(servers) |
473 | ||
474 | await testVideoResolutions(liveVideoId, resolutions) | |
475 | ||
476 | await stopFfmpeg(command) | |
af4ae64f C |
477 | }) |
478 | ||
479 | it('Should enable transcoding with some resolutions and correctly save them', async function () { | |
f42c2152 | 480 | this.timeout(200000) |
bd54ad19 C |
481 | |
482 | const resolutions = [ 240, 360, 720 ] | |
ca5c612b | 483 | |
bd54ad19 C |
484 | await updateConf(resolutions) |
485 | liveVideoId = await createLiveWrapper(true) | |
486 | ||
ca5c612b | 487 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId, 'video_short2.webm') |
8ebf2a5d | 488 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
bd54ad19 C |
489 | await waitJobs(servers) |
490 | ||
491 | await testVideoResolutions(liveVideoId, resolutions) | |
492 | ||
493 | await stopFfmpeg(command) | |
34caef7f C |
494 | await waitUntilLiveEnded(servers[0].url, servers[0].accessToken, liveVideoId) |
495 | ||
bd54ad19 C |
496 | await waitJobs(servers) |
497 | ||
8ebf2a5d | 498 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
e0783718 | 499 | |
ca5c612b | 500 | const bitrateLimits = { |
4ef9ea48 | 501 | 720: 5000 * 1000, // 60FPS |
6b67897e C |
502 | 360: 1100 * 1000, |
503 | 240: 600 * 1000 | |
ca5c612b C |
504 | } |
505 | ||
bd54ad19 C |
506 | for (const server of servers) { |
507 | const resVideo = await getVideo(server.url, liveVideoId) | |
508 | const video: VideoDetails = resVideo.body | |
509 | ||
e0783718 | 510 | expect(video.state.id).to.equal(VideoState.PUBLISHED) |
bd54ad19 C |
511 | expect(video.duration).to.be.greaterThan(1) |
512 | expect(video.files).to.have.lengthOf(0) | |
513 | ||
514 | const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) | |
f2eb23cd RK |
515 | await makeRawRequest(hlsPlaylist.playlistUrl, HttpStatusCode.OK_200) |
516 | await makeRawRequest(hlsPlaylist.segmentsSha256Url, HttpStatusCode.OK_200) | |
bd54ad19 C |
517 | |
518 | expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length) | |
519 | ||
520 | for (const resolution of resolutions) { | |
521 | const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) | |
522 | ||
523 | expect(file).to.exist | |
bd54ad19 C |
524 | expect(file.size).to.be.greaterThan(1) |
525 | ||
884d2c39 C |
526 | if (resolution >= 720) { |
527 | expect(file.fps).to.be.approximately(60, 2) | |
528 | } else { | |
529 | expect(file.fps).to.be.approximately(30, 2) | |
530 | } | |
531 | ||
ca5c612b C |
532 | const filename = `${video.uuid}-${resolution}-fragmented.mp4` |
533 | const segmentPath = buildServerDirectory(servers[0], join('streaming-playlists', 'hls', video.uuid, filename)) | |
534 | ||
535 | const probe = await ffprobePromise(segmentPath) | |
536 | const videoStream = await getVideoStreamFromFile(segmentPath, probe) | |
6b67897e | 537 | |
ca5c612b C |
538 | expect(probe.format.bit_rate).to.be.below(bitrateLimits[videoStream.height]) |
539 | ||
f2eb23cd RK |
540 | await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200) |
541 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) | |
bd54ad19 C |
542 | } |
543 | } | |
af4ae64f C |
544 | }) |
545 | ||
546 | it('Should correctly have cleaned up the live files', async function () { | |
bd54ad19 C |
547 | this.timeout(30000) |
548 | ||
549 | await checkLiveCleanup(servers[0], liveVideoId, [ 240, 360, 720 ]) | |
af4ae64f C |
550 | }) |
551 | }) | |
552 | ||
5c0904fc C |
553 | describe('After a server restart', function () { |
554 | let liveVideoId: string | |
555 | let liveVideoReplayId: string | |
556 | ||
557 | async function createLiveWrapper (saveReplay: boolean) { | |
558 | const liveAttributes = { | |
559 | name: 'live video', | |
560 | channelId: servers[0].videoChannel.id, | |
561 | privacy: VideoPrivacy.PUBLIC, | |
562 | saveReplay | |
563 | } | |
564 | ||
565 | const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) | |
566 | return res.body.video.uuid | |
567 | } | |
568 | ||
569 | before(async function () { | |
0d8de275 | 570 | this.timeout(120000) |
5c0904fc C |
571 | |
572 | liveVideoId = await createLiveWrapper(false) | |
573 | liveVideoReplayId = await createLiveWrapper(true) | |
574 | ||
575 | await Promise.all([ | |
576 | sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId), | |
577 | sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoReplayId) | |
578 | ]) | |
579 | ||
580 | await Promise.all([ | |
0d8de275 C |
581 | waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId), |
582 | waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoReplayId) | |
5c0904fc C |
583 | ]) |
584 | ||
0d8de275 C |
585 | await waitUntilLiveSegmentGeneration(servers[0], liveVideoId, 0, 2) |
586 | await waitUntilLiveSegmentGeneration(servers[0], liveVideoReplayId, 0, 2) | |
587 | ||
5c0904fc C |
588 | await killallServers([ servers[0] ]) |
589 | await reRunServer(servers[0]) | |
590 | ||
591 | await wait(5000) | |
592 | }) | |
593 | ||
594 | it('Should cleanup lives', async function () { | |
595 | this.timeout(60000) | |
596 | ||
0d8de275 | 597 | await waitUntilLiveEnded(servers[0].url, servers[0].accessToken, liveVideoId) |
5c0904fc C |
598 | }) |
599 | ||
600 | it('Should save a live replay', async function () { | |
0d8de275 | 601 | this.timeout(120000) |
5c0904fc | 602 | |
b49f22d8 | 603 | await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoReplayId) |
5c0904fc C |
604 | }) |
605 | }) | |
606 | ||
af4ae64f C |
607 | after(async function () { |
608 | await cleanupTests(servers) | |
609 | }) | |
610 | }) |