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