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,
14 sendRTMPStreamInVideo,
16 setAccessTokensToServers,
17 setDefaultVideoChannel,
19 updateCustomSubConfig,
23 waitUntilLivePublished
24 } from '../../../../shared/extra-utils'
26 const expect = chai.expect
28 describe('Permenant live', function () {
29 let servers: ServerInfo[] = []
32 async function createLiveWrapper (permanentLive: boolean) {
33 const attributes: LiveVideoCreate = {
34 channelId: servers[0].videoChannel.id,
35 privacy: VideoPrivacy.PUBLIC,
36 name: 'my super live',
41 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
42 return res.body.video.uuid
45 async function checkVideoState (videoId: string, state: VideoState) {
46 for (const server of servers) {
47 const res = await getVideo(server.url, videoId)
48 expect((res.body as VideoDetails).state.id).to.equal(state)
52 before(async function () {
55 servers = await flushAndRunMultipleServers(2)
57 // Get the access tokens
58 await setAccessTokensToServers(servers)
59 await setDefaultVideoChannel(servers)
61 // Server 1 and server 2 follow each other
62 await doubleFollow(servers[0], servers[1])
64 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
84 it('Should create a non permanent live and update it to be a permanent live', async function () {
87 const videoUUID = await createLiveWrapper(false)
90 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
91 expect(res.body.permanentLive).to.be.false
94 await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true })
97 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
98 expect(res.body.permanentLive).to.be.true
102 it('Should create a permanent live', async function () {
105 videoUUID = await createLiveWrapper(true)
107 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
108 expect(res.body.permanentLive).to.be.true
110 await waitJobs(servers)
113 it('Should stream into this permanent live', async function () {
116 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
118 for (const server of servers) {
119 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
122 await checkVideoState(videoUUID, VideoState.PUBLISHED)
124 await stopFfmpeg(command)
126 await waitJobs(servers)
129 it('Should not have cleaned up this live', async function () {
133 await waitJobs(servers)
135 for (const server of servers) {
136 const res = await getVideo(server.url, videoUUID)
138 const videoDetails = res.body as VideoDetails
139 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
143 it('Should have set this live to waiting for live state', async function () {
146 await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
149 it('Should be able to stream again in the permanent live', async function () {
152 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
171 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
173 for (const server of servers) {
174 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
177 await checkVideoState(videoUUID, VideoState.PUBLISHED)
179 const count = await getPlaylistsCount(servers[0], videoUUID)
180 // master playlist and 720p playlist
181 expect(count).to.equal(2)
183 await stopFfmpeg(command)
186 after(async function () {
187 await cleanupTests(servers)