1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
17 } from '../../../../shared/extra-utils'
19 const expect = chai.expect
21 describe('Permanent live', function () {
22 let servers: PeerTubeServer[] = []
25 async function createLiveWrapper (permanentLive: boolean) {
26 const attributes: LiveVideoCreate = {
27 channelId: servers[0].store.channel.id,
28 privacy: VideoPrivacy.PUBLIC,
29 name: 'my super live',
34 const { uuid } = await servers[0].live.create({ fields: attributes })
38 async function checkVideoState (videoId: string, state: VideoState) {
39 for (const server of servers) {
40 const video = await server.videos.get({ id: videoId })
41 expect(video.state.id).to.equal(state)
45 before(async function () {
48 servers = await createMultipleServers(2)
50 // Get the access tokens
51 await setAccessTokensToServers(servers)
52 await setDefaultVideoChannel(servers)
54 // Server 1 and server 2 follow each other
55 await doubleFollow(servers[0], servers[1])
57 await servers[0].config.updateCustomSubConfig({
65 resolutions: ConfigCommand.getCustomConfigResolutions(true)
72 it('Should create a non permanent live and update it to be a permanent live', async function () {
75 const videoUUID = await createLiveWrapper(false)
78 const live = await servers[0].live.get({ videoId: videoUUID })
79 expect(live.permanentLive).to.be.false
82 await servers[0].live.update({ videoId: videoUUID, fields: { permanentLive: true } })
85 const live = await servers[0].live.get({ videoId: videoUUID })
86 expect(live.permanentLive).to.be.true
90 it('Should create a permanent live', async function () {
93 videoUUID = await createLiveWrapper(true)
95 const live = await servers[0].live.get({ videoId: videoUUID })
96 expect(live.permanentLive).to.be.true
98 await waitJobs(servers)
101 it('Should stream into this permanent live', async function () {
104 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
106 for (const server of servers) {
107 await server.live.waitUntilPublished({ videoId: videoUUID })
110 await checkVideoState(videoUUID, VideoState.PUBLISHED)
112 await stopFfmpeg(ffmpegCommand)
113 await servers[0].live.waitUntilWaiting({ videoId: videoUUID })
115 await waitJobs(servers)
118 it('Should not have cleaned up this live', async function () {
122 await waitJobs(servers)
124 for (const server of servers) {
125 const videoDetails = await server.videos.get({ id: videoUUID })
126 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
130 it('Should have set this live to waiting for live state', async function () {
133 await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
136 it('Should be able to stream again in the permanent live', async function () {
139 await servers[0].config.updateCustomSubConfig({
147 resolutions: ConfigCommand.getCustomConfigResolutions(false)
153 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
155 for (const server of servers) {
156 await server.live.waitUntilPublished({ videoId: videoUUID })
159 await checkVideoState(videoUUID, VideoState.PUBLISHED)
161 const count = await servers[0].live.countPlaylists({ videoUUID })
162 // master playlist and 720p playlist
163 expect(count).to.equal(2)
165 await stopFfmpeg(ffmpegCommand)
168 after(async function () {
169 await cleanupTests(servers)