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