1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { LiveVideo, LiveVideoCreate, VideoDetails, VideoPrivacy } from '@shared/models'
11 flushAndRunMultipleServers,
18 setAccessTokensToServers,
19 setDefaultVideoChannel,
21 updateCustomSubConfig,
24 } from '../../../../shared/extra-utils'
26 const expect = chai.expect
28 describe('Test live', function () {
29 let servers: ServerInfo[] = []
30 let liveVideoUUID: string
32 before(async function () {
35 servers = await flushAndRunMultipleServers(2)
37 // Get the access tokens
38 await setAccessTokensToServers(servers)
39 await setDefaultVideoChannel(servers)
41 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
48 // Server 1 and server 2 follow each other
49 await doubleFollow(servers[0], servers[1])
52 describe('Live creation, update and delete', function () {
54 it('Should create a live with the appropriate parameters', async function () {
57 const attributes: LiveVideoCreate = {
61 description: 'super live description',
62 support: 'support field',
63 channelId: servers[0].videoChannel.id,
65 waitTranscoding: false,
66 name: 'my super live',
67 tags: [ 'tag1', 'tag2' ],
68 commentsEnabled: false,
69 downloadEnabled: false,
71 privacy: VideoPrivacy.PUBLIC,
72 previewfile: 'video_short1-preview.webm.jpg',
73 thumbnailfile: 'video_short1.webm.jpg'
76 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
77 liveVideoUUID = res.body.video.uuid
79 await waitJobs(servers)
81 for (const server of servers) {
82 const resVideo = await getVideo(server.url, liveVideoUUID)
83 const video: VideoDetails = resVideo.body
85 expect(video.category.id).to.equal(1)
86 expect(video.licence.id).to.equal(2)
87 expect(video.language.id).to.equal('fr')
88 expect(video.description).to.equal('super live description')
89 expect(video.support).to.equal('support field')
91 expect(video.channel.name).to.equal(servers[0].videoChannel.name)
92 expect(video.channel.host).to.equal(servers[0].videoChannel.host)
94 expect(video.nsfw).to.be.false
95 expect(video.waitTranscoding).to.be.false
96 expect(video.name).to.equal('my super live')
97 expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ])
98 expect(video.commentsEnabled).to.be.false
99 expect(video.downloadEnabled).to.be.false
100 expect(video.privacy.id).to.equal(VideoPrivacy.PUBLIC)
102 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
103 await testImage(server.url, 'video_short1.webm', video.thumbnailPath)
105 const resLive = await getLive(server.url, server.accessToken, liveVideoUUID)
106 const live: LiveVideo = resLive.body
108 if (server.url === servers[0].url) {
109 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':1936/live')
110 expect(live.streamKey).to.not.be.empty
112 expect(live.rtmpUrl).to.be.null
113 expect(live.streamKey).to.be.null
116 expect(live.saveReplay).to.be.true
120 it('Should have a default preview and thumbnail', async function () {
123 const attributes: LiveVideoCreate = {
124 name: 'default live thumbnail',
125 channelId: servers[0].videoChannel.id,
126 privacy: VideoPrivacy.UNLISTED,
130 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
131 const videoId = res.body.video.uuid
133 await waitJobs(servers)
135 for (const server of servers) {
136 const resVideo = await getVideo(server.url, videoId)
137 const video: VideoDetails = resVideo.body
139 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
140 expect(video.nsfw).to.be.true
142 await makeRawRequest(server.url + video.thumbnailPath, 200)
143 await makeRawRequest(server.url + video.previewPath, 200)
147 it('Should not have the live listed since nobody streams into', async function () {
148 for (const server of servers) {
149 const res = await getVideosList(server.url)
151 expect(res.body.total).to.equal(0)
152 expect(res.body.data).to.have.lengthOf(0)
156 it('Should not be able to update a live of another server', async function () {
157 await updateLive(servers[1].url, servers[1].accessToken, liveVideoUUID, { saveReplay: false }, 403)
160 it('Should update the live', async function () {
163 await updateLive(servers[0].url, servers[0].accessToken, liveVideoUUID, { saveReplay: false })
164 await waitJobs(servers)
167 it('Have the live updated', async function () {
168 for (const server of servers) {
169 const res = await getLive(server.url, server.accessToken, liveVideoUUID)
170 const live: LiveVideo = res.body
172 if (server.url === servers[0].url) {
173 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':1936/live')
174 expect(live.streamKey).to.not.be.empty
176 expect(live.rtmpUrl).to.be.null
177 expect(live.streamKey).to.be.null
180 expect(live.saveReplay).to.be.false
184 it('Delete the live', async function () {
187 await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
188 await waitJobs(servers)
191 it('Should have the live deleted', async function () {
192 for (const server of servers) {
193 await getVideo(server.url, liveVideoUUID, 404)
194 await getLive(server.url, server.accessToken, liveVideoUUID, 404)
199 describe('Test live constraints', function () {
201 it('Should not have size limit if save replay is disabled', async function () {
205 it('Should have size limit if save replay is enabled', async function () {
206 // daily quota + total quota
210 it('Should have max duration limit', async function () {
215 describe('With save replay disabled', function () {
217 it('Should correctly create and federate the "waiting for stream" live', async function () {
221 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
225 it('Should correctly delete the video and the live after the stream ended', async function () {
228 // get video federation 404
233 it('Should correctly terminate the stream on blacklist and delete the live', async function () {
236 // get video federation 404
241 it('Should correctly terminate the stream on delete and delete the video', async function () {
244 // get video federation 404
250 describe('With save replay enabled', function () {
252 it('Should correctly create and federate the "waiting for stream" live', async function () {
256 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
260 it('Should correctly have saved the live and federated it after the streaming', async function () {
264 it('Should update the saved live and correctly federate the updated attributes', async function () {
268 it('Should have cleaned up the live files', async function () {
272 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () {
274 // get video -> blacklisted
275 // get video federation -> blacklisted
277 // check cleanup live files quand meme
280 it('Should correctly terminate the stream on delete and delete the video', async function () {
283 // get video federation 404
289 describe('Stream checks', function () {
291 it('Should not allow a stream without the appropriate path', async function () {
295 it('Should not allow a stream without the appropriate stream key', async function () {
299 it('Should not allow a stream on a live that was blacklisted', async function () {
303 it('Should not allow a stream on a live that was deleted', async function () {
308 describe('Live transcoding', function () {
310 it('Should enable transcoding without additional resolutions', async function () {
313 // wait federation + test
317 it('Should enable transcoding with some resolutions', async function () {
320 // wait federation + test
323 it('Should enable transcoding with some resolutions and correctly save them', async function () {
327 // wait federation + test
330 it('Should correctly have cleaned up the live files', async function () {
335 describe('Live socket messages', function () {
337 it('Should correctly send a message when the live starts', async function () {
342 it('Should correctly send a message when the live ends', async function () {
348 after(async function () {
349 await cleanupTests(servers)