aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/live/live.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/live/live.ts')
-rw-r--r--server/tests/api/live/live.ts90
1 files changed, 42 insertions, 48 deletions
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts
index 2c3102994..5b4e479b6 100644
--- a/server/tests/api/live/live.ts
+++ b/server/tests/api/live/live.ts
@@ -13,41 +13,36 @@ import {
13 checkLiveSegmentHash, 13 checkLiveSegmentHash,
14 checkResolutionsInMasterPlaylist, 14 checkResolutionsInMasterPlaylist,
15 cleanupTests, 15 cleanupTests,
16 createLive,
17 doubleFollow, 16 doubleFollow,
18 flushAndRunMultipleServers, 17 flushAndRunMultipleServers,
19 getLive,
20 getMyVideosWithFilter, 18 getMyVideosWithFilter,
21 getPlaylist, 19 getPlaylist,
22 getVideo, 20 getVideo,
23 getVideosList, 21 getVideosList,
24 getVideosWithFilters, 22 getVideosWithFilters,
25 killallServers, 23 killallServers,
24 LiveCommand,
26 makeRawRequest, 25 makeRawRequest,
27 removeVideo, 26 removeVideo,
28 reRunServer, 27 reRunServer,
29 sendRTMPStream, 28 sendRTMPStream,
30 sendRTMPStreamInVideo,
31 ServerInfo, 29 ServerInfo,
32 setAccessTokensToServers, 30 setAccessTokensToServers,
33 setDefaultVideoChannel, 31 setDefaultVideoChannel,
34 stopFfmpeg, 32 stopFfmpeg,
35 testFfmpegStreamError, 33 testFfmpegStreamError,
36 testImage, 34 testImage,
37 updateLive,
38 uploadVideoAndGetId, 35 uploadVideoAndGetId,
39 wait, 36 wait,
40 waitJobs, 37 waitJobs,
41 waitUntilLiveEnded, 38 waitUntilLivePublishedOnAllServers
42 waitUntilLivePublished,
43 waitUntilLivePublishedOnAllServers,
44 waitUntilLiveSegmentGeneration
45} from '../../../../shared/extra-utils' 39} from '../../../../shared/extra-utils'
46 40
47const expect = chai.expect 41const expect = chai.expect
48 42
49describe('Test live', function () { 43describe('Test live', function () {
50 let servers: ServerInfo[] = [] 44 let servers: ServerInfo[] = []
45 let commands: LiveCommand[]
51 46
52 before(async function () { 47 before(async function () {
53 this.timeout(120000) 48 this.timeout(120000)
@@ -72,6 +67,8 @@ describe('Test live', function () {
72 67
73 // Server 1 and server 2 follow each other 68 // Server 1 and server 2 follow each other
74 await doubleFollow(servers[0], servers[1]) 69 await doubleFollow(servers[0], servers[1])
70
71 commands = servers.map(s => s.liveCommand)
75 }) 72 })
76 73
77 describe('Live creation, update and delete', function () { 74 describe('Live creation, update and delete', function () {
@@ -99,8 +96,8 @@ describe('Test live', function () {
99 thumbnailfile: 'video_short1.webm.jpg' 96 thumbnailfile: 'video_short1.webm.jpg'
100 } 97 }
101 98
102 const res = await createLive(servers[0].url, servers[0].accessToken, attributes) 99 const live = await commands[0].createLive({ fields: attributes })
103 liveVideoUUID = res.body.video.uuid 100 liveVideoUUID = live.uuid
104 101
105 await waitJobs(servers) 102 await waitJobs(servers)
106 103
@@ -130,8 +127,7 @@ describe('Test live', function () {
130 await testImage(server.url, 'video_short1-preview.webm', video.previewPath) 127 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
131 await testImage(server.url, 'video_short1.webm', video.thumbnailPath) 128 await testImage(server.url, 'video_short1.webm', video.thumbnailPath)
132 129
133 const resLive = await getLive(server.url, server.accessToken, liveVideoUUID) 130 const live = await server.liveCommand.getLive({ videoId: liveVideoUUID })
134 const live: LiveVideo = resLive.body
135 131
136 if (server.url === servers[0].url) { 132 if (server.url === servers[0].url) {
137 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') 133 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live')
@@ -155,8 +151,8 @@ describe('Test live', function () {
155 nsfw: true 151 nsfw: true
156 } 152 }
157 153
158 const res = await createLive(servers[0].url, servers[0].accessToken, attributes) 154 const live = await commands[0].createLive({ fields: attributes })
159 const videoId = res.body.video.uuid 155 const videoId = live.uuid
160 156
161 await waitJobs(servers) 157 await waitJobs(servers)
162 158
@@ -182,20 +178,19 @@ describe('Test live', function () {
182 }) 178 })
183 179
184 it('Should not be able to update a live of another server', async function () { 180 it('Should not be able to update a live of another server', async function () {
185 await updateLive(servers[1].url, servers[1].accessToken, liveVideoUUID, { saveReplay: false }, HttpStatusCode.FORBIDDEN_403) 181 await commands[1].updateLive({ videoId: liveVideoUUID, fields: { saveReplay: false }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
186 }) 182 })
187 183
188 it('Should update the live', async function () { 184 it('Should update the live', async function () {
189 this.timeout(10000) 185 this.timeout(10000)
190 186
191 await updateLive(servers[0].url, servers[0].accessToken, liveVideoUUID, { saveReplay: false }) 187 await commands[0].updateLive({ videoId: liveVideoUUID, fields: { saveReplay: false } })
192 await waitJobs(servers) 188 await waitJobs(servers)
193 }) 189 })
194 190
195 it('Have the live updated', async function () { 191 it('Have the live updated', async function () {
196 for (const server of servers) { 192 for (const server of servers) {
197 const res = await getLive(server.url, server.accessToken, liveVideoUUID) 193 const live = await server.liveCommand.getLive({ videoId: liveVideoUUID })
198 const live: LiveVideo = res.body
199 194
200 if (server.url === servers[0].url) { 195 if (server.url === servers[0].url) {
201 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') 196 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live')
@@ -219,13 +214,13 @@ describe('Test live', function () {
219 it('Should have the live deleted', async function () { 214 it('Should have the live deleted', async function () {
220 for (const server of servers) { 215 for (const server of servers) {
221 await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) 216 await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404)
222 await getLive(server.url, server.accessToken, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) 217 await server.liveCommand.getLive({ videoId: liveVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
223 } 218 }
224 }) 219 })
225 }) 220 })
226 221
227 describe('Live filters', function () { 222 describe('Live filters', function () {
228 let command: any 223 let ffmpegCommand: any
229 let liveVideoId: string 224 let liveVideoId: string
230 let vodVideoId: string 225 let vodVideoId: string
231 226
@@ -235,10 +230,10 @@ describe('Test live', function () {
235 vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid 230 vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid
236 231
237 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id } 232 const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id }
238 const resLive = await createLive(servers[0].url, servers[0].accessToken, liveOptions) 233 const live = await commands[0].createLive({ fields: liveOptions })
239 liveVideoId = resLive.body.video.uuid 234 liveVideoId = live.uuid
240 235
241 command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) 236 ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId })
242 await waitUntilLivePublishedOnAllServers(servers, liveVideoId) 237 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
243 await waitJobs(servers) 238 await waitJobs(servers)
244 }) 239 })
@@ -262,7 +257,7 @@ describe('Test live', function () {
262 it('Should display my lives', async function () { 257 it('Should display my lives', async function () {
263 this.timeout(60000) 258 this.timeout(60000)
264 259
265 await stopFfmpeg(command) 260 await stopFfmpeg(ffmpegCommand)
266 await waitJobs(servers) 261 await waitJobs(servers)
267 262
268 const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: true }) 263 const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: true })
@@ -302,13 +297,12 @@ describe('Test live', function () {
302 saveReplay: false 297 saveReplay: false
303 } 298 }
304 299
305 const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) 300 const { uuid } = await commands[0].createLive({ fields: liveAttributes })
306 const uuid = res.body.video.uuid
307 301
308 const resLive = await getLive(servers[0].url, servers[0].accessToken, uuid) 302 const live = await commands[0].getLive({ videoId: uuid })
309 const resVideo = await getVideo(servers[0].url, uuid) 303 const resVideo = await getVideo(servers[0].url, uuid)
310 304
311 return Object.assign(resVideo.body, resLive.body) as LiveVideo & VideoDetails 305 return Object.assign(resVideo.body as VideoDetails, live)
312 } 306 }
313 307
314 it('Should not allow a stream without the appropriate path', async function () { 308 it('Should not allow a stream without the appropriate path', async function () {
@@ -382,8 +376,8 @@ describe('Test live', function () {
382 saveReplay 376 saveReplay
383 } 377 }
384 378
385 const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) 379 const { uuid } = await commands[0].createLive({ fields: liveAttributes })
386 return res.body.video.uuid 380 return uuid
387 } 381 }
388 382
389 async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { 383 async function testVideoResolutions (liveVideoId: string, resolutions: number[]) {
@@ -409,7 +403,7 @@ describe('Test live', function () {
409 for (let i = 0; i < resolutions.length; i++) { 403 for (let i = 0; i < resolutions.length; i++) {
410 const segmentNum = 3 404 const segmentNum = 3
411 const segmentName = `${i}-00000${segmentNum}.ts` 405 const segmentName = `${i}-00000${segmentNum}.ts`
412 await waitUntilLiveSegmentGeneration(servers[0], video.uuid, i, segmentNum) 406 await commands[0].waitUntilLiveSegmentGeneration({ videoUUID: video.uuid, resolution: i, segment: segmentNum })
413 407
414 const res = await getPlaylist(`${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8`) 408 const res = await getPlaylist(`${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8`)
415 const subPlaylist = res.text 409 const subPlaylist = res.text
@@ -454,13 +448,13 @@ describe('Test live', function () {
454 448
455 liveVideoId = await createLiveWrapper(false) 449 liveVideoId = await createLiveWrapper(false)
456 450
457 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) 451 const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId })
458 await waitUntilLivePublishedOnAllServers(servers, liveVideoId) 452 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
459 await waitJobs(servers) 453 await waitJobs(servers)
460 454
461 await testVideoResolutions(liveVideoId, [ 720 ]) 455 await testVideoResolutions(liveVideoId, [ 720 ])
462 456
463 await stopFfmpeg(command) 457 await stopFfmpeg(ffmpegCommand)
464 }) 458 })
465 459
466 it('Should enable transcoding with some resolutions', async function () { 460 it('Should enable transcoding with some resolutions', async function () {
@@ -470,13 +464,13 @@ describe('Test live', function () {
470 await updateConf(resolutions) 464 await updateConf(resolutions)
471 liveVideoId = await createLiveWrapper(false) 465 liveVideoId = await createLiveWrapper(false)
472 466
473 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) 467 const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId })
474 await waitUntilLivePublishedOnAllServers(servers, liveVideoId) 468 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
475 await waitJobs(servers) 469 await waitJobs(servers)
476 470
477 await testVideoResolutions(liveVideoId, resolutions) 471 await testVideoResolutions(liveVideoId, resolutions)
478 472
479 await stopFfmpeg(command) 473 await stopFfmpeg(ffmpegCommand)
480 }) 474 })
481 475
482 it('Should enable transcoding with some resolutions and correctly save them', async function () { 476 it('Should enable transcoding with some resolutions and correctly save them', async function () {
@@ -487,14 +481,14 @@ describe('Test live', function () {
487 await updateConf(resolutions) 481 await updateConf(resolutions)
488 liveVideoId = await createLiveWrapper(true) 482 liveVideoId = await createLiveWrapper(true)
489 483
490 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId, 'video_short2.webm') 484 const ffmpegCommand = await commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId, fixtureName: 'video_short2.webm' })
491 await waitUntilLivePublishedOnAllServers(servers, liveVideoId) 485 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
492 await waitJobs(servers) 486 await waitJobs(servers)
493 487
494 await testVideoResolutions(liveVideoId, resolutions) 488 await testVideoResolutions(liveVideoId, resolutions)
495 489
496 await stopFfmpeg(command) 490 await stopFfmpeg(ffmpegCommand)
497 await waitUntilLiveEnded(servers[0].url, servers[0].accessToken, liveVideoId) 491 await commands[0].waitUntilLiveEnded({ videoId: liveVideoId })
498 492
499 await waitJobs(servers) 493 await waitJobs(servers)
500 494
@@ -565,8 +559,8 @@ describe('Test live', function () {
565 saveReplay 559 saveReplay
566 } 560 }
567 561
568 const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) 562 const { uuid } = await commands[0].createLive({ fields: liveAttributes })
569 return res.body.video.uuid 563 return uuid
570 } 564 }
571 565
572 before(async function () { 566 before(async function () {
@@ -576,17 +570,17 @@ describe('Test live', function () {
576 liveVideoReplayId = await createLiveWrapper(true) 570 liveVideoReplayId = await createLiveWrapper(true)
577 571
578 await Promise.all([ 572 await Promise.all([
579 sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId), 573 commands[0].sendRTMPStreamInVideo({ videoId: liveVideoId }),
580 sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoReplayId) 574 commands[0].sendRTMPStreamInVideo({ videoId: liveVideoReplayId })
581 ]) 575 ])
582 576
583 await Promise.all([ 577 await Promise.all([
584 waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId), 578 commands[0].waitUntilLivePublished({ videoId: liveVideoId }),
585 waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoReplayId) 579 commands[0].waitUntilLivePublished({ videoId: liveVideoReplayId })
586 ]) 580 ])
587 581
588 await waitUntilLiveSegmentGeneration(servers[0], liveVideoId, 0, 2) 582 await commands[0].waitUntilLiveSegmentGeneration({ videoUUID: liveVideoId, resolution: 0, segment: 2 })
589 await waitUntilLiveSegmentGeneration(servers[0], liveVideoReplayId, 0, 2) 583 await commands[0].waitUntilLiveSegmentGeneration({ videoUUID: liveVideoReplayId, resolution: 0, segment: 2 })
590 584
591 await killallServers([ servers[0] ]) 585 await killallServers([ servers[0] ])
592 await reRunServer(servers[0]) 586 await reRunServer(servers[0])
@@ -597,13 +591,13 @@ describe('Test live', function () {
597 it('Should cleanup lives', async function () { 591 it('Should cleanup lives', async function () {
598 this.timeout(60000) 592 this.timeout(60000)
599 593
600 await waitUntilLiveEnded(servers[0].url, servers[0].accessToken, liveVideoId) 594 await commands[0].waitUntilLiveEnded({ videoId: liveVideoId })
601 }) 595 })
602 596
603 it('Should save a live replay', async function () { 597 it('Should save a live replay', async function () {
604 this.timeout(120000) 598 this.timeout(120000)
605 599
606 await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoReplayId) 600 await commands[0].waitUntilLivePublished({ videoId: liveVideoReplayId })
607 }) 601 })
608 }) 602 })
609 603