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,
11 getCustomConfigResolutions,
15 sendRTMPStreamInVideo,
17 setAccessTokensToServers,
18 setDefaultVideoChannel,
20 updateCustomSubConfig,
24 waitUntilLivePublished,
26 } from '../../../../shared/extra-utils'
28 const expect = chai.expect
30 describe('Permanent live', function () {
31 let servers: ServerInfo[] = []
34 async function createLiveWrapper (permanentLive: boolean) {
35 const attributes: LiveVideoCreate = {
36 channelId: servers[0].videoChannel.id,
37 privacy: VideoPrivacy.PUBLIC,
38 name: 'my super live',
43 const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
44 return res.body.video.uuid
47 async function checkVideoState (videoId: string, state: VideoState) {
48 for (const server of servers) {
49 const res = await getVideo(server.url, videoId)
50 expect((res.body as VideoDetails).state.id).to.equal(state)
54 before(async function () {
57 servers = await flushAndRunMultipleServers(2)
59 // Get the access tokens
60 await setAccessTokensToServers(servers)
61 await setDefaultVideoChannel(servers)
63 // Server 1 and server 2 follow each other
64 await doubleFollow(servers[0], servers[1])
66 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
73 resolutions: getCustomConfigResolutions(true)
79 it('Should create a non permanent live and update it to be a permanent live', async function () {
82 const videoUUID = await createLiveWrapper(false)
85 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
86 expect(res.body.permanentLive).to.be.false
89 await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true })
92 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
93 expect(res.body.permanentLive).to.be.true
97 it('Should create a permanent live', async function () {
100 videoUUID = await createLiveWrapper(true)
102 const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
103 expect(res.body.permanentLive).to.be.true
105 await waitJobs(servers)
108 it('Should stream into this permanent live', async function () {
111 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
113 for (const server of servers) {
114 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
117 await checkVideoState(videoUUID, VideoState.PUBLISHED)
119 await stopFfmpeg(command)
120 await waitUntilLiveWaiting(servers[0].url, servers[0].accessToken, videoUUID)
122 await waitJobs(servers)
125 it('Should not have cleaned up this live', async function () {
129 await waitJobs(servers)
131 for (const server of servers) {
132 const res = await getVideo(server.url, videoUUID)
134 const videoDetails = res.body as VideoDetails
135 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
139 it('Should have set this live to waiting for live state', async function () {
142 await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
145 it('Should be able to stream again in the permanent live', async function () {
148 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
155 resolutions: getCustomConfigResolutions(false)
160 const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
162 for (const server of servers) {
163 await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
166 await checkVideoState(videoUUID, VideoState.PUBLISHED)
168 const count = await getPlaylistsCount(servers[0], videoUUID)
169 // master playlist and 720p playlist
170 expect(count).to.equal(2)
172 await stopFfmpeg(command)
175 after(async function () {
176 await cleanupTests(servers)