]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/live/live.ts
Try to speed up server tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { FfmpegCommand } from 'fluent-ffmpeg'
6 import { join } from 'path'
7 import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils'
8 import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io'
9 import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
10 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
11 import {
12 addVideoToBlacklist,
13 buildServerDirectory,
14 checkLiveCleanup,
15 checkLiveSegmentHash,
16 checkResolutionsInMasterPlaylist,
17 cleanupTests,
18 createLive,
19 doubleFollow,
20 flushAndRunMultipleServers,
21 getLive,
22 getPlaylist,
23 getVideo,
24 getVideoIdFromUUID,
25 getVideosList,
26 killallServers,
27 makeRawRequest,
28 removeVideo,
29 reRunServer,
30 sendRTMPStream,
31 sendRTMPStreamInVideo,
32 ServerInfo,
33 setAccessTokensToServers,
34 setDefaultVideoChannel,
35 stopFfmpeg,
36 testFfmpegStreamError,
37 testImage,
38 updateCustomSubConfig,
39 updateLive,
40 viewVideo,
41 wait,
42 waitJobs,
43 waitUntilLiveEnded,
44 waitUntilLivePublished,
45 waitUntilLiveSegmentGeneration
46 } from '../../../../shared/extra-utils'
47
48 const expect = chai.expect
49
50 describe('Test live', function () {
51 let servers: ServerInfo[] = []
52
53 async function waitUntilLivePublishedOnAllServers (videoId: string) {
54 for (const server of servers) {
55 await waitUntilLivePublished(server.url, server.accessToken, videoId)
56 }
57 }
58
59 before(async function () {
60 this.timeout(120000)
61
62 servers = await flushAndRunMultipleServers(2)
63
64 // Get the access tokens
65 await setAccessTokensToServers(servers)
66 await setDefaultVideoChannel(servers)
67
68 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
69 live: {
70 enabled: true,
71 allowReplay: true,
72 transcoding: {
73 enabled: false
74 }
75 }
76 })
77
78 // Server 1 and server 2 follow each other
79 await doubleFollow(servers[0], servers[1])
80 })
81
82 describe('Live creation, update and delete', function () {
83 let liveVideoUUID: string
84
85 it('Should create a live with the appropriate parameters', async function () {
86 this.timeout(20000)
87
88 const attributes: LiveVideoCreate = {
89 category: 1,
90 licence: 2,
91 language: 'fr',
92 description: 'super live description',
93 support: 'support field',
94 channelId: servers[0].videoChannel.id,
95 nsfw: false,
96 waitTranscoding: false,
97 name: 'my super live',
98 tags: [ 'tag1', 'tag2' ],
99 commentsEnabled: false,
100 downloadEnabled: false,
101 saveReplay: true,
102 privacy: VideoPrivacy.PUBLIC,
103 previewfile: 'video_short1-preview.webm.jpg',
104 thumbnailfile: 'video_short1.webm.jpg'
105 }
106
107 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
108 liveVideoUUID = res.body.video.uuid
109
110 await waitJobs(servers)
111
112 for (const server of servers) {
113 const resVideo = await getVideo(server.url, liveVideoUUID)
114 const video: VideoDetails = resVideo.body
115
116 expect(video.category.id).to.equal(1)
117 expect(video.licence.id).to.equal(2)
118 expect(video.language.id).to.equal('fr')
119 expect(video.description).to.equal('super live description')
120 expect(video.support).to.equal('support field')
121
122 expect(video.channel.name).to.equal(servers[0].videoChannel.name)
123 expect(video.channel.host).to.equal(servers[0].videoChannel.host)
124
125 expect(video.isLive).to.be.true
126
127 expect(video.nsfw).to.be.false
128 expect(video.waitTranscoding).to.be.false
129 expect(video.name).to.equal('my super live')
130 expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ])
131 expect(video.commentsEnabled).to.be.false
132 expect(video.downloadEnabled).to.be.false
133 expect(video.privacy.id).to.equal(VideoPrivacy.PUBLIC)
134
135 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
136 await testImage(server.url, 'video_short1.webm', video.thumbnailPath)
137
138 const resLive = await getLive(server.url, server.accessToken, liveVideoUUID)
139 const live: LiveVideo = resLive.body
140
141 if (server.url === servers[0].url) {
142 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live')
143 expect(live.streamKey).to.not.be.empty
144 } else {
145 expect(live.rtmpUrl).to.be.null
146 expect(live.streamKey).to.be.null
147 }
148
149 expect(live.saveReplay).to.be.true
150 }
151 })
152
153 it('Should have a default preview and thumbnail', async function () {
154 this.timeout(20000)
155
156 const attributes: LiveVideoCreate = {
157 name: 'default live thumbnail',
158 channelId: servers[0].videoChannel.id,
159 privacy: VideoPrivacy.UNLISTED,
160 nsfw: true
161 }
162
163 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
164 const videoId = res.body.video.uuid
165
166 await waitJobs(servers)
167
168 for (const server of servers) {
169 const resVideo = await getVideo(server.url, videoId)
170 const video: VideoDetails = resVideo.body
171
172 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
173 expect(video.nsfw).to.be.true
174
175 await makeRawRequest(server.url + video.thumbnailPath, HttpStatusCode.OK_200)
176 await makeRawRequest(server.url + video.previewPath, HttpStatusCode.OK_200)
177 }
178 })
179
180 it('Should not have the live listed since nobody streams into', async function () {
181 for (const server of servers) {
182 const res = await getVideosList(server.url)
183
184 expect(res.body.total).to.equal(0)
185 expect(res.body.data).to.have.lengthOf(0)
186 }
187 })
188
189 it('Should not be able to update a live of another server', async function () {
190 await updateLive(servers[1].url, servers[1].accessToken, liveVideoUUID, { saveReplay: false }, HttpStatusCode.FORBIDDEN_403)
191 })
192
193 it('Should update the live', async function () {
194 this.timeout(10000)
195
196 await updateLive(servers[0].url, servers[0].accessToken, liveVideoUUID, { saveReplay: false })
197 await waitJobs(servers)
198 })
199
200 it('Have the live updated', async function () {
201 for (const server of servers) {
202 const res = await getLive(server.url, server.accessToken, liveVideoUUID)
203 const live: LiveVideo = res.body
204
205 if (server.url === servers[0].url) {
206 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live')
207 expect(live.streamKey).to.not.be.empty
208 } else {
209 expect(live.rtmpUrl).to.be.null
210 expect(live.streamKey).to.be.null
211 }
212
213 expect(live.saveReplay).to.be.false
214 }
215 })
216
217 it('Delete the live', async function () {
218 this.timeout(10000)
219
220 await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
221 await waitJobs(servers)
222 })
223
224 it('Should have the live deleted', async function () {
225 for (const server of servers) {
226 await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404)
227 await getLive(server.url, server.accessToken, liveVideoUUID, HttpStatusCode.NOT_FOUND_404)
228 }
229 })
230 })
231
232 describe('Stream checks', function () {
233 let liveVideo: LiveVideo & VideoDetails
234 let rtmpUrl: string
235
236 before(function () {
237 rtmpUrl = 'rtmp://' + servers[0].hostname + ':' + servers[0].rtmpPort + ''
238 })
239
240 async function createLiveWrapper () {
241 const liveAttributes = {
242 name: 'user live',
243 channelId: servers[0].videoChannel.id,
244 privacy: VideoPrivacy.PUBLIC,
245 saveReplay: false
246 }
247
248 const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes)
249 const uuid = res.body.video.uuid
250
251 const resLive = await getLive(servers[0].url, servers[0].accessToken, uuid)
252 const resVideo = await getVideo(servers[0].url, uuid)
253
254 return Object.assign(resVideo.body, resLive.body) as LiveVideo & VideoDetails
255 }
256
257 it('Should not allow a stream without the appropriate path', async function () {
258 this.timeout(30000)
259
260 liveVideo = await createLiveWrapper()
261
262 const command = sendRTMPStream(rtmpUrl + '/bad-live', liveVideo.streamKey)
263 await testFfmpegStreamError(command, true)
264 })
265
266 it('Should not allow a stream without the appropriate stream key', async function () {
267 this.timeout(30000)
268
269 const command = sendRTMPStream(rtmpUrl + '/live', 'bad-stream-key')
270 await testFfmpegStreamError(command, true)
271 })
272
273 it('Should succeed with the correct params', async function () {
274 this.timeout(30000)
275
276 const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey)
277 await testFfmpegStreamError(command, false)
278 })
279
280 it('Should list this live now someone stream into it', async function () {
281 for (const server of servers) {
282 const res = await getVideosList(server.url)
283
284 expect(res.body.total).to.equal(1)
285 expect(res.body.data).to.have.lengthOf(1)
286
287 const video: Video = res.body.data[0]
288
289 expect(video.name).to.equal('user live')
290 expect(video.isLive).to.be.true
291 }
292 })
293
294 it('Should not allow a stream on a live that was blacklisted', async function () {
295 this.timeout(30000)
296
297 liveVideo = await createLiveWrapper()
298
299 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideo.uuid)
300
301 const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey)
302 await testFfmpegStreamError(command, true)
303 })
304
305 it('Should not allow a stream on a live that was deleted', async function () {
306 this.timeout(30000)
307
308 liveVideo = await createLiveWrapper()
309
310 await removeVideo(servers[0].url, servers[0].accessToken, liveVideo.uuid)
311
312 const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey)
313 await testFfmpegStreamError(command, true)
314 })
315 })
316
317 describe('Live transcoding', function () {
318 let liveVideoId: string
319
320 async function createLiveWrapper (saveReplay: boolean) {
321 const liveAttributes = {
322 name: 'live video',
323 channelId: servers[0].videoChannel.id,
324 privacy: VideoPrivacy.PUBLIC,
325 saveReplay
326 }
327
328 const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes)
329 return res.body.video.uuid
330 }
331
332 async function testVideoResolutions (liveVideoId: string, resolutions: number[]) {
333 for (const server of servers) {
334 const resList = await getVideosList(server.url)
335 const videos: Video[] = resList.body.data
336
337 expect(videos.find(v => v.uuid === liveVideoId)).to.exist
338
339 const resVideo = await getVideo(server.url, liveVideoId)
340 const video: VideoDetails = resVideo.body
341
342 expect(video.streamingPlaylists).to.have.lengthOf(1)
343
344 const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS)
345 expect(hlsPlaylist).to.exist
346
347 // Only finite files are displayed
348 expect(hlsPlaylist.files).to.have.lengthOf(0)
349
350 await checkResolutionsInMasterPlaylist(hlsPlaylist.playlistUrl, resolutions)
351
352 for (let i = 0; i < resolutions.length; i++) {
353 const segmentNum = 3
354 const segmentName = `${i}-00000${segmentNum}.ts`
355 await waitUntilLiveSegmentGeneration(servers[0], video.uuid, i, segmentNum)
356
357 const res = await getPlaylist(`${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8`)
358 const subPlaylist = res.text
359
360 expect(subPlaylist).to.contain(segmentName)
361
362 const baseUrlAndPath = servers[0].url + '/static/streaming-playlists/hls'
363 await checkLiveSegmentHash(baseUrlAndPath, video.uuid, segmentName, hlsPlaylist)
364 }
365 }
366 }
367
368 function updateConf (resolutions: number[]) {
369 return updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
370 live: {
371 enabled: true,
372 allowReplay: true,
373 maxDuration: -1,
374 transcoding: {
375 enabled: true,
376 resolutions: {
377 '240p': resolutions.includes(240),
378 '360p': resolutions.includes(360),
379 '480p': resolutions.includes(480),
380 '720p': resolutions.includes(720),
381 '1080p': resolutions.includes(1080),
382 '2160p': resolutions.includes(2160)
383 }
384 }
385 }
386 })
387 }
388
389 before(async function () {
390 await updateConf([])
391 })
392
393 it('Should enable transcoding without additional resolutions', async function () {
394 this.timeout(30000)
395
396 liveVideoId = await createLiveWrapper(false)
397
398 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId)
399 await waitUntilLivePublishedOnAllServers(liveVideoId)
400 await waitJobs(servers)
401
402 await testVideoResolutions(liveVideoId, [ 720 ])
403
404 await stopFfmpeg(command)
405 })
406
407 it('Should enable transcoding with some resolutions', async function () {
408 this.timeout(30000)
409
410 const resolutions = [ 240, 480 ]
411 await updateConf(resolutions)
412 liveVideoId = await createLiveWrapper(false)
413
414 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId)
415 await waitUntilLivePublishedOnAllServers(liveVideoId)
416 await waitJobs(servers)
417
418 await testVideoResolutions(liveVideoId, resolutions)
419
420 await stopFfmpeg(command)
421 })
422
423 it('Should enable transcoding with some resolutions and correctly save them', async function () {
424 this.timeout(200000)
425
426 const resolutions = [ 240, 360, 720 ]
427
428 await updateConf(resolutions)
429 liveVideoId = await createLiveWrapper(true)
430
431 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId, 'video_short2.webm')
432 await waitUntilLivePublishedOnAllServers(liveVideoId)
433 await waitJobs(servers)
434
435 await testVideoResolutions(liveVideoId, resolutions)
436
437 await stopFfmpeg(command)
438 await waitUntilLiveEnded(servers[0].url, servers[0].accessToken, liveVideoId)
439
440 await waitJobs(servers)
441
442 await waitUntilLivePublishedOnAllServers(liveVideoId)
443
444 const bitrateLimits = {
445 720: 5000 * 1000, // 60FPS
446 360: 1100 * 1000,
447 240: 600 * 1000
448 }
449
450 for (const server of servers) {
451 const resVideo = await getVideo(server.url, liveVideoId)
452 const video: VideoDetails = resVideo.body
453
454 expect(video.state.id).to.equal(VideoState.PUBLISHED)
455 expect(video.duration).to.be.greaterThan(1)
456 expect(video.files).to.have.lengthOf(0)
457
458 const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS)
459 await makeRawRequest(hlsPlaylist.playlistUrl, HttpStatusCode.OK_200)
460 await makeRawRequest(hlsPlaylist.segmentsSha256Url, HttpStatusCode.OK_200)
461
462 expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length)
463
464 for (const resolution of resolutions) {
465 const file = hlsPlaylist.files.find(f => f.resolution.id === resolution)
466
467 expect(file).to.exist
468 expect(file.size).to.be.greaterThan(1)
469
470 if (resolution >= 720) {
471 expect(file.fps).to.be.approximately(60, 2)
472 } else {
473 expect(file.fps).to.be.approximately(30, 2)
474 }
475
476 const filename = `${video.uuid}-${resolution}-fragmented.mp4`
477 const segmentPath = buildServerDirectory(servers[0], join('streaming-playlists', 'hls', video.uuid, filename))
478
479 const probe = await ffprobePromise(segmentPath)
480 const videoStream = await getVideoStreamFromFile(segmentPath, probe)
481
482 expect(probe.format.bit_rate).to.be.below(bitrateLimits[videoStream.height])
483
484 await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200)
485 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
486 }
487 }
488 })
489
490 it('Should correctly have cleaned up the live files', async function () {
491 this.timeout(30000)
492
493 await checkLiveCleanup(servers[0], liveVideoId, [ 240, 360, 720 ])
494 })
495 })
496
497 describe('Live views', function () {
498 let liveVideoId: string
499 let command: FfmpegCommand
500
501 async function countViews (expected: number) {
502 for (const server of servers) {
503 const res = await getVideo(server.url, liveVideoId)
504 const video: VideoDetails = res.body
505
506 expect(video.views).to.equal(expected)
507 }
508 }
509
510 before(async function () {
511 this.timeout(30000)
512
513 const liveAttributes = {
514 name: 'live video',
515 channelId: servers[0].videoChannel.id,
516 privacy: VideoPrivacy.PUBLIC
517 }
518
519 const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes)
520 liveVideoId = res.body.video.uuid
521
522 command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId)
523 await waitUntilLivePublishedOnAllServers(liveVideoId)
524 await waitJobs(servers)
525 })
526
527 it('Should display no views for a live', async function () {
528 await countViews(0)
529 })
530
531 it('Should view a live twice and display 1 view', async function () {
532 this.timeout(30000)
533
534 await viewVideo(servers[0].url, liveVideoId)
535 await viewVideo(servers[0].url, liveVideoId)
536
537 await wait(7000)
538
539 await waitJobs(servers)
540
541 await countViews(1)
542 })
543
544 it('Should wait and display 0 views', async function () {
545 this.timeout(30000)
546
547 await wait(7000)
548 await waitJobs(servers)
549
550 await countViews(0)
551 })
552
553 it('Should view a live on a remote and on local and display 2 views', async function () {
554 this.timeout(30000)
555
556 await viewVideo(servers[0].url, liveVideoId)
557 await viewVideo(servers[1].url, liveVideoId)
558 await viewVideo(servers[1].url, liveVideoId)
559
560 await wait(7000)
561 await waitJobs(servers)
562
563 await countViews(2)
564 })
565
566 after(async function () {
567 await stopFfmpeg(command)
568 })
569 })
570
571 describe('Live socket messages', function () {
572
573 async function createLiveWrapper () {
574 const liveAttributes = {
575 name: 'live video',
576 channelId: servers[0].videoChannel.id,
577 privacy: VideoPrivacy.PUBLIC
578 }
579
580 const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes)
581 return res.body.video.uuid
582 }
583
584 it('Should correctly send a message when the live starts and ends', async function () {
585 this.timeout(60000)
586
587 const localStateChanges: VideoState[] = []
588 const remoteStateChanges: VideoState[] = []
589
590 const liveVideoUUID = await createLiveWrapper()
591 await waitJobs(servers)
592
593 {
594 const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
595
596 const localSocket = getLiveNotificationSocket(servers[0].url)
597 localSocket.on('state-change', data => localStateChanges.push(data.state))
598 localSocket.emit('subscribe', { videoId })
599 }
600
601 {
602 const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
603
604 const remoteSocket = getLiveNotificationSocket(servers[1].url)
605 remoteSocket.on('state-change', data => remoteStateChanges.push(data.state))
606 remoteSocket.emit('subscribe', { videoId })
607 }
608
609 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
610
611 await waitUntilLivePublishedOnAllServers(liveVideoUUID)
612 await waitJobs(servers)
613
614 for (const stateChanges of [ localStateChanges, remoteStateChanges ]) {
615 expect(stateChanges).to.have.length.at.least(1)
616 expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.PUBLISHED)
617 }
618
619 await stopFfmpeg(command)
620
621 for (const server of servers) {
622 await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID)
623 }
624 await waitJobs(servers)
625
626 for (const stateChanges of [ localStateChanges, remoteStateChanges ]) {
627 expect(stateChanges).to.have.length.at.least(2)
628 expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.LIVE_ENDED)
629 }
630 })
631
632 it('Should correctly send views change notification', async function () {
633 this.timeout(60000)
634
635 let localLastVideoViews = 0
636 let remoteLastVideoViews = 0
637
638 const liveVideoUUID = await createLiveWrapper()
639 await waitJobs(servers)
640
641 {
642 const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
643
644 const localSocket = getLiveNotificationSocket(servers[0].url)
645 localSocket.on('views-change', data => { localLastVideoViews = data.views })
646 localSocket.emit('subscribe', { videoId })
647 }
648
649 {
650 const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
651
652 const remoteSocket = getLiveNotificationSocket(servers[1].url)
653 remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views })
654 remoteSocket.emit('subscribe', { videoId })
655 }
656
657 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
658
659 await waitUntilLivePublishedOnAllServers(liveVideoUUID)
660 await waitJobs(servers)
661
662 expect(localLastVideoViews).to.equal(0)
663 expect(remoteLastVideoViews).to.equal(0)
664
665 await viewVideo(servers[0].url, liveVideoUUID)
666 await viewVideo(servers[1].url, liveVideoUUID)
667
668 await waitJobs(servers)
669 await wait(5000)
670 await waitJobs(servers)
671
672 expect(localLastVideoViews).to.equal(2)
673 expect(remoteLastVideoViews).to.equal(2)
674
675 await stopFfmpeg(command)
676 })
677
678 it('Should not receive a notification after unsubscribe', async function () {
679 this.timeout(60000)
680
681 const stateChanges: VideoState[] = []
682
683 const liveVideoUUID = await createLiveWrapper()
684 await waitJobs(servers)
685
686 const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
687
688 const socket = getLiveNotificationSocket(servers[0].url)
689 socket.on('state-change', data => stateChanges.push(data.state))
690 socket.emit('subscribe', { videoId })
691
692 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
693
694 await waitUntilLivePublishedOnAllServers(liveVideoUUID)
695 await waitJobs(servers)
696
697 expect(stateChanges).to.have.lengthOf(1)
698 socket.emit('unsubscribe', { videoId })
699
700 await stopFfmpeg(command)
701 await waitJobs(servers)
702
703 expect(stateChanges).to.have.lengthOf(1)
704 })
705 })
706
707 describe('After a server restart', function () {
708 let liveVideoId: string
709 let liveVideoReplayId: string
710
711 async function createLiveWrapper (saveReplay: boolean) {
712 const liveAttributes = {
713 name: 'live video',
714 channelId: servers[0].videoChannel.id,
715 privacy: VideoPrivacy.PUBLIC,
716 saveReplay
717 }
718
719 const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes)
720 return res.body.video.uuid
721 }
722
723 before(async function () {
724 this.timeout(120000)
725
726 liveVideoId = await createLiveWrapper(false)
727 liveVideoReplayId = await createLiveWrapper(true)
728
729 await Promise.all([
730 sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId),
731 sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoReplayId)
732 ])
733
734 await Promise.all([
735 waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId),
736 waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoReplayId)
737 ])
738
739 await waitUntilLiveSegmentGeneration(servers[0], liveVideoId, 0, 2)
740 await waitUntilLiveSegmentGeneration(servers[0], liveVideoReplayId, 0, 2)
741
742 await killallServers([ servers[0] ])
743 await reRunServer(servers[0])
744
745 await wait(5000)
746 })
747
748 it('Should cleanup lives', async function () {
749 this.timeout(60000)
750
751 await waitUntilLiveEnded(servers[0].url, servers[0].accessToken, liveVideoId)
752 })
753
754 it('Should save a live replay', async function () {
755 this.timeout(120000)
756
757 await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoReplayId)
758 })
759 })
760
761 after(async function () {
762 await cleanupTests(servers)
763 })
764 })