1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { VideoDetails, VideoPrivacy } from '@shared/models'
12 flushAndRunMultipleServers,
15 runAndTestFfmpegStreamError,
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
22 waitUntilLivePublished
23 } from '../../../../shared/extra-utils'
25 const expect = chai.expect
27 describe('Test live constraints', function () {
28 let servers: ServerInfo[] = []
30 let userAccessToken: string
31 let userChannelId: number
33 async function createLiveWrapper (saveReplay: boolean) {
34 const liveAttributes = {
36 channelId: userChannelId,
37 privacy: VideoPrivacy.PUBLIC,
41 const res = await createLive(servers[0].url, userAccessToken, liveAttributes)
42 return res.body.video.uuid as string
45 async function checkSaveReplay (videoId: string, resolutions = [ 720 ]) {
46 for (const server of servers) {
47 const res = await getVideo(server.url, videoId)
49 const video: VideoDetails = res.body
50 expect(video.isLive).to.be.false
51 expect(video.duration).to.be.greaterThan(0)
54 await checkLiveCleanup(servers[0], videoId, resolutions)
57 async function waitUntilLivePublishedOnAllServers (videoId: string) {
58 for (const server of servers) {
59 await waitUntilLivePublished(server.url, server.accessToken, videoId)
63 function updateQuota (options: { total: number, daily: number }) {
66 accessToken: servers[0].accessToken,
68 videoQuota: options.total,
69 videoQuotaDaily: options.daily
73 before(async function () {
76 servers = await flushAndRunMultipleServers(2)
78 // Get the access tokens
79 await setAccessTokensToServers(servers)
80 await setDefaultVideoChannel(servers)
82 await servers[0].configCommand.updateCustomSubConfig({
95 const res = await generateUser(servers[0], 'user1')
97 userChannelId = res.userChannelId
98 userAccessToken = res.token
100 await updateQuota({ total: 1, daily: -1 })
103 // Server 1 and server 2 follow each other
104 await doubleFollow(servers[0], servers[1])
107 it('Should not have size limit if save replay is disabled', async function () {
110 const userVideoLiveoId = await createLiveWrapper(false)
111 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
114 it('Should have size limit depending on user global quota if save replay is enabled', async function () {
117 // Wait for user quota memoize cache invalidation
120 const userVideoLiveoId = await createLiveWrapper(true)
121 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
123 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
124 await waitJobs(servers)
126 await checkSaveReplay(userVideoLiveoId)
129 it('Should have size limit depending on user daily quota if save replay is enabled', async function () {
132 // Wait for user quota memoize cache invalidation
135 await updateQuota({ total: -1, daily: 1 })
137 const userVideoLiveoId = await createLiveWrapper(true)
138 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
140 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
141 await waitJobs(servers)
143 await checkSaveReplay(userVideoLiveoId)
146 it('Should succeed without quota limit', async function () {
149 // Wait for user quota memoize cache invalidation
152 await updateQuota({ total: 10 * 1000 * 1000, daily: -1 })
154 const userVideoLiveoId = await createLiveWrapper(true)
155 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
158 it('Should have max duration limit', async function () {
161 await servers[0].configCommand.updateCustomSubConfig({
169 resolutions: ConfigCommand.getCustomConfigResolutions(true)
175 const userVideoLiveoId = await createLiveWrapper(true)
176 await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
178 await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
179 await waitJobs(servers)
181 await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240 ])
184 after(async function () {
185 await cleanupTests(servers)