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