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