1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models'
10 flushAndRunMultipleServers,
13 setAccessTokensToServers,
14 setDefaultVideoChannel,
18 } from '../../../../shared/extra-utils'
20 const expect = chai.expect
22 describe('Permanent live', function () {
23 let servers: ServerInfo[] = []
26 async function createLiveWrapper (permanentLive: boolean) {
27 const attributes: LiveVideoCreate = {
28 channelId: servers[0].videoChannel.id,
29 privacy: VideoPrivacy.PUBLIC,
30 name: 'my super live',
35 const { uuid } = await servers[0].liveCommand.create({ fields: attributes })
39 async function checkVideoState (videoId: string, state: VideoState) {
40 for (const server of servers) {
41 const res = await getVideo(server.url, videoId)
42 expect((res.body as VideoDetails).state.id).to.equal(state)
46 before(async function () {
49 servers = await flushAndRunMultipleServers(2)
51 // Get the access tokens
52 await setAccessTokensToServers(servers)
53 await setDefaultVideoChannel(servers)
55 // Server 1 and server 2 follow each other
56 await doubleFollow(servers[0], servers[1])
58 await servers[0].configCommand.updateCustomSubConfig({
66 resolutions: ConfigCommand.getCustomConfigResolutions(true)
73 it('Should create a non permanent live and update it to be a permanent live', async function () {
76 const videoUUID = await createLiveWrapper(false)
79 const live = await servers[0].liveCommand.get({ videoId: videoUUID })
80 expect(live.permanentLive).to.be.false
83 await servers[0].liveCommand.update({ videoId: videoUUID, fields: { permanentLive: true } })
86 const live = await servers[0].liveCommand.get({ videoId: videoUUID })
87 expect(live.permanentLive).to.be.true
91 it('Should create a permanent live', async function () {
94 videoUUID = await createLiveWrapper(true)
96 const live = await servers[0].liveCommand.get({ videoId: videoUUID })
97 expect(live.permanentLive).to.be.true
99 await waitJobs(servers)
102 it('Should stream into this permanent live', async function () {
105 const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID })
107 for (const server of servers) {
108 await server.liveCommand.waitUntilPublished({ videoId: videoUUID })
111 await checkVideoState(videoUUID, VideoState.PUBLISHED)
113 await stopFfmpeg(ffmpegCommand)
114 await servers[0].liveCommand.waitUntilWaiting({ videoId: videoUUID })
116 await waitJobs(servers)
119 it('Should not have cleaned up this live', async function () {
123 await waitJobs(servers)
125 for (const server of servers) {
126 const res = await getVideo(server.url, videoUUID)
128 const videoDetails = res.body as VideoDetails
129 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
133 it('Should have set this live to waiting for live state', async function () {
136 await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
139 it('Should be able to stream again in the permanent live', async function () {
142 await servers[0].configCommand.updateCustomSubConfig({
150 resolutions: ConfigCommand.getCustomConfigResolutions(false)
156 const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID })
158 for (const server of servers) {
159 await server.liveCommand.waitUntilPublished({ videoId: videoUUID })
162 await checkVideoState(videoUUID, VideoState.PUBLISHED)
164 const count = await servers[0].liveCommand.countPlaylists({ videoUUID })
165 // master playlist and 720p playlist
166 expect(count).to.equal(2)
168 await stopFfmpeg(ffmpegCommand)
171 after(async function () {
172 await cleanupTests(servers)