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