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'
11 flushAndRunMultipleServers,
15 sendRTMPStreamInVideo,
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
23 waitUntilLivePublished,
25 } from '../../../../shared/extra-utils'
27 const expect = chai.expect
29 describe('Permanent live', function () {
30 let servers: ServerInfo[] = []
33 async function createLiveWrapper (permanentLive: boolean) {
34 const attributes: LiveVideoCreate = {
35 channelId: servers[0].videoChannel.id,
36 privacy: VideoPrivacy.PUBLIC,
37 name: 'my super live',
42 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
43 return res.body.video.uuid
46 async function checkVideoState (videoId: string, state: VideoState) {
47 for (const server of servers) {
48 const res = await getVideo(server.url, videoId)
49 expect((res.body as VideoDetails).state.id).to.equal(state)
53 before(async function () {
56 servers = await flushAndRunMultipleServers(2)
58 // Get the access tokens
59 await setAccessTokensToServers(servers)
60 await setDefaultVideoChannel(servers)
62 // Server 1 and server 2 follow each other
63 await doubleFollow(servers[0], servers[1])
65 await servers[0].configCommand.updateCustomSubConfig({
73 resolutions: ConfigCommand.getCustomConfigResolutions(true)
80 it('Should create a non permanent live and update it to be a permanent live', async function () {
83 const videoUUID = await createLiveWrapper(false)
86 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
87 expect(res.body.permanentLive).to.be.false
90 await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true })
93 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
94 expect(res.body.permanentLive).to.be.true
98 it('Should create a permanent live', async function () {
101 videoUUID = await createLiveWrapper(true)
103 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
104 expect(res.body.permanentLive).to.be.true
106 await waitJobs(servers)
109 it('Should stream into this permanent live', async function () {
112 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
114 for (const server of servers) {
115 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
118 await checkVideoState(videoUUID, VideoState.PUBLISHED)
120 await stopFfmpeg(command)
121 await waitUntilLiveWaiting(servers[0].url, servers[0].accessToken, videoUUID)
123 await waitJobs(servers)
126 it('Should not have cleaned up this live', async function () {
130 await waitJobs(servers)
132 for (const server of servers) {
133 const res = await getVideo(server.url, videoUUID)
135 const videoDetails = res.body as VideoDetails
136 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
140 it('Should have set this live to waiting for live state', async function () {
143 await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
146 it('Should be able to stream again in the permanent live', async function () {
149 await servers[0].configCommand.updateCustomSubConfig({
157 resolutions: ConfigCommand.getCustomConfigResolutions(false)
163 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
165 for (const server of servers) {
166 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
169 await checkVideoState(videoUUID, VideoState.PUBLISHED)
171 const count = await getPlaylistsCount(servers[0], videoUUID)
172 // master playlist and 720p playlist
173 expect(count).to.equal(2)
175 await stopFfmpeg(command)
178 after(async function () {
179 await cleanupTests(servers)