1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { LiveVideo, LiveVideoCreate, User, VideoDetails, VideoPrivacy } from '@shared/models'
11 flushAndRunMultipleServers,
19 setAccessTokensToServers,
20 setDefaultVideoChannel,
21 testFfmpegStreamError,
23 updateCustomSubConfig,
29 } from '../../../../shared/extra-utils'
31 const expect = chai.expect
33 describe('Test live', function () {
34 let servers: ServerInfo[] = []
35 let liveVideoUUID: string
37 let userAccessToken: string
38 let userChannelId: number
40 before(async function () {
43 servers = await flushAndRunMultipleServers(2)
45 // Get the access tokens
46 await setAccessTokensToServers(servers)
47 await setDefaultVideoChannel(servers)
49 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
57 const user = { username: 'user1', password: 'superpassword' }
58 const res = await createUser({
60 accessToken: servers[0].accessToken,
61 username: user.username,
62 password: user.password
64 userId = res.body.user.id
66 userAccessToken = await userLogin(servers[0], user)
68 const resMe = await getMyUserInformation(servers[0].url, userAccessToken)
69 userChannelId = (resMe.body as User).videoChannels[0].id
72 // Server 1 and server 2 follow each other
73 await doubleFollow(servers[0], servers[1])
76 describe('Live creation, update and delete', function () {
78 it('Should create a live with the appropriate parameters', async function () {
81 const attributes: LiveVideoCreate = {
85 description: 'super live description',
86 support: 'support field',
87 channelId: servers[0].videoChannel.id,
89 waitTranscoding: false,
90 name: 'my super live',
91 tags: [ 'tag1', 'tag2' ],
92 commentsEnabled: false,
93 downloadEnabled: false,
95 privacy: VideoPrivacy.PUBLIC,
96 previewfile: 'video_short1-preview.webm.jpg',
97 thumbnailfile: 'video_short1.webm.jpg'
100 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
101 liveVideoUUID = res.body.video.uuid
103 await waitJobs(servers)
105 for (const server of servers) {
106 const resVideo = await getVideo(server.url, liveVideoUUID)
107 const video: VideoDetails = resVideo.body
109 expect(video.category.id).to.equal(1)
110 expect(video.licence.id).to.equal(2)
111 expect(video.language.id).to.equal('fr')
112 expect(video.description).to.equal('super live description')
113 expect(video.support).to.equal('support field')
115 expect(video.channel.name).to.equal(servers[0].videoChannel.name)
116 expect(video.channel.host).to.equal(servers[0].videoChannel.host)
118 expect(video.nsfw).to.be.false
119 expect(video.waitTranscoding).to.be.false
120 expect(video.name).to.equal('my super live')
121 expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ])
122 expect(video.commentsEnabled).to.be.false
123 expect(video.downloadEnabled).to.be.false
124 expect(video.privacy.id).to.equal(VideoPrivacy.PUBLIC)
126 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
127 await testImage(server.url, 'video_short1.webm', video.thumbnailPath)
129 const resLive = await getLive(server.url, server.accessToken, liveVideoUUID)
130 const live: LiveVideo = resLive.body
132 if (server.url === servers[0].url) {
133 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':1936/live')
134 expect(live.streamKey).to.not.be.empty
136 expect(live.rtmpUrl).to.be.null
137 expect(live.streamKey).to.be.null
140 expect(live.saveReplay).to.be.true
144 it('Should have a default preview and thumbnail', async function () {
147 const attributes: LiveVideoCreate = {
148 name: 'default live thumbnail',
149 channelId: servers[0].videoChannel.id,
150 privacy: VideoPrivacy.UNLISTED,
154 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
155 const videoId = res.body.video.uuid
157 await waitJobs(servers)
159 for (const server of servers) {
160 const resVideo = await getVideo(server.url, videoId)
161 const video: VideoDetails = resVideo.body
163 expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED)
164 expect(video.nsfw).to.be.true
166 await makeRawRequest(server.url + video.thumbnailPath, 200)
167 await makeRawRequest(server.url + video.previewPath, 200)
171 it('Should not have the live listed since nobody streams into', async function () {
172 for (const server of servers) {
173 const res = await getVideosList(server.url)
175 expect(res.body.total).to.equal(0)
176 expect(res.body.data).to.have.lengthOf(0)
180 it('Should not be able to update a live of another server', async function () {
181 await updateLive(servers[1].url, servers[1].accessToken, liveVideoUUID, { saveReplay: false }, 403)
184 it('Should update the live', async function () {
187 await updateLive(servers[0].url, servers[0].accessToken, liveVideoUUID, { saveReplay: false })
188 await waitJobs(servers)
191 it('Have the live updated', async function () {
192 for (const server of servers) {
193 const res = await getLive(server.url, server.accessToken, liveVideoUUID)
194 const live: LiveVideo = res.body
196 if (server.url === servers[0].url) {
197 expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':1936/live')
198 expect(live.streamKey).to.not.be.empty
200 expect(live.rtmpUrl).to.be.null
201 expect(live.streamKey).to.be.null
204 expect(live.saveReplay).to.be.false
208 it('Delete the live', async function () {
211 await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID)
212 await waitJobs(servers)
215 it('Should have the live deleted', async function () {
216 for (const server of servers) {
217 await getVideo(server.url, liveVideoUUID, 404)
218 await getLive(server.url, server.accessToken, liveVideoUUID, 404)
223 describe('Test live constraints', function () {
225 async function createLiveWrapper (saveReplay: boolean) {
226 const liveAttributes = {
228 channelId: userChannelId,
229 privacy: VideoPrivacy.PUBLIC,
233 const res = await createLive(servers[0].url, userAccessToken, liveAttributes)
234 return res.body.video.uuid as string
237 before(async function () {
238 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
248 accessToken: servers[0].accessToken,
254 it('Should not have size limit if save replay is disabled', async function () {
257 const userVideoLiveoId = await createLiveWrapper(false)
258 await testFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
261 it('Should have size limit depending on user global quota if save replay is enabled', async function () {
264 const userVideoLiveoId = await createLiveWrapper(true)
265 await testFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
267 await waitJobs(servers)
269 for (const server of servers) {
270 const res = await getVideo(server.url, userVideoLiveoId)
272 const video: VideoDetails = res.body
273 expect(video.isLive).to.be.false
274 expect(video.duration).to.be.greaterThan(0)
277 // TODO: check stream correctly saved + cleaned
280 it('Should have size limit depending on user daily quota if save replay is enabled', async function () {
286 accessToken: servers[0].accessToken,
291 const userVideoLiveoId = await createLiveWrapper(true)
292 await testFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
294 // TODO: check stream correctly saved + cleaned
297 it('Should succeed without quota limit', async function () {
300 // Wait for user quota memoize cache invalidation
306 accessToken: servers[0].accessToken,
307 videoQuota: 10 * 1000 * 1000,
311 const userVideoLiveoId = await createLiveWrapper(true)
312 await testFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
315 it('Should have max duration limit', async function () {
318 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
326 const userVideoLiveoId = await createLiveWrapper(true)
327 await testFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
329 // TODO: check stream correctly saved + cleaned
333 describe('With save replay disabled', function () {
335 it('Should correctly create and federate the "waiting for stream" live', async function () {
339 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
343 it('Should correctly delete the video and the live after the stream ended', async function () {
346 // get video federation 404
351 it('Should correctly terminate the stream on blacklist and delete the live', async function () {
354 // get video federation 404
359 it('Should correctly terminate the stream on delete and delete the video', async function () {
362 // get video federation 404
368 describe('With save replay enabled', function () {
370 it('Should correctly create and federate the "waiting for stream" live', async function () {
374 it('Should correctly have updated the live and federated it when streaming in the live', async function () {
378 it('Should correctly have saved the live and federated it after the streaming', async function () {
382 it('Should update the saved live and correctly federate the updated attributes', async function () {
386 it('Should have cleaned up the live files', async function () {
390 it('Should correctly terminate the stream on blacklist and blacklist the saved replay video', async function () {
392 // get video -> blacklisted
393 // get video federation -> blacklisted
395 // check cleanup live files quand meme
398 it('Should correctly terminate the stream on delete and delete the video', async function () {
401 // get video federation 404
407 describe('Stream checks', function () {
409 it('Should not allow a stream without the appropriate path', async function () {
413 it('Should not allow a stream without the appropriate stream key', async function () {
417 it('Should not allow a stream on a live that was blacklisted', async function () {
421 it('Should not allow a stream on a live that was deleted', async function () {
426 describe('Live transcoding', function () {
428 it('Should enable transcoding without additional resolutions', async function () {
431 // wait federation + test
435 it('Should enable transcoding with some resolutions', async function () {
438 // wait federation + test
441 it('Should enable transcoding with some resolutions and correctly save them', async function () {
445 // wait federation + test
448 it('Should correctly have cleaned up the live files', async function () {
453 describe('Live socket messages', function () {
455 it('Should correctly send a message when the live starts', async function () {
460 it('Should correctly send a message when the live ends', async function () {
466 after(async function () {
467 await cleanupTests(servers)