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