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