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 beforePublication = new Date()
105 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
107 for (const server of servers) {
108 await server.live.waitUntilPublished({ videoId: videoUUID })
111 await checkVideoState(videoUUID, VideoState.PUBLISHED)
113 for (const server of servers) {
114 const video = await server.videos.get({ id: videoUUID })
115 expect(new Date(video.publishedAt)).greaterThan(beforePublication)
118 await stopFfmpeg(ffmpegCommand)
119 await servers[0].live.waitUntilWaiting({ videoId: videoUUID })
121 await waitJobs(servers)
124 it('Should not have cleaned up this live', async function () {
128 await waitJobs(servers)
130 for (const server of servers) {
131 const videoDetails = await server.videos.get({ id: videoUUID })
132 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
136 it('Should have set this live to waiting for live state', async function () {
139 await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
142 it('Should be able to stream again in the permanent live', async function () {
145 await servers[0].config.updateCustomSubConfig({
153 resolutions: ConfigCommand.getCustomConfigResolutions(false)
159 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
161 for (const server of servers) {
162 await server.live.waitUntilPublished({ videoId: videoUUID })
165 await checkVideoState(videoUUID, VideoState.PUBLISHED)
167 const count = await servers[0].live.countPlaylists({ videoUUID })
168 // master playlist and 720p playlist
169 expect(count).to.equal(2)
171 await stopFfmpeg(ffmpegCommand)
174 after(async function () {
175 await cleanupTests(servers)