1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { wait } from '@shared/core-utils'
5 import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
16 } from '@shared/server-commands'
18 describe('Permanent live', function () {
19 let servers: PeerTubeServer[] = []
22 async function createLiveWrapper (permanentLive: boolean) {
23 const attributes: LiveVideoCreate = {
24 channelId: servers[0].store.channel.id,
25 privacy: VideoPrivacy.PUBLIC,
26 name: 'my super live',
31 const { uuid } = await servers[0].live.create({ fields: attributes })
35 async function checkVideoState (videoId: string, state: VideoState) {
36 for (const server of servers) {
37 const video = await server.videos.get({ id: videoId })
38 expect(video.state.id).to.equal(state)
42 before(async function () {
45 servers = await createMultipleServers(2)
47 // Get the access tokens
48 await setAccessTokensToServers(servers)
49 await setDefaultVideoChannel(servers)
51 // Server 1 and server 2 follow each other
52 await doubleFollow(servers[0], servers[1])
54 await servers[0].config.updateCustomSubConfig({
62 resolutions: ConfigCommand.getCustomConfigResolutions(true)
69 it('Should create a non permanent live and update it to be a permanent live', async function () {
72 const videoUUID = await createLiveWrapper(false)
75 const live = await servers[0].live.get({ videoId: videoUUID })
76 expect(live.permanentLive).to.be.false
79 await servers[0].live.update({ videoId: videoUUID, fields: { permanentLive: true } })
82 const live = await servers[0].live.get({ videoId: videoUUID })
83 expect(live.permanentLive).to.be.true
87 it('Should create a permanent live', async function () {
90 videoUUID = await createLiveWrapper(true)
92 const live = await servers[0].live.get({ videoId: videoUUID })
93 expect(live.permanentLive).to.be.true
95 await waitJobs(servers)
98 it('Should stream into this permanent live', async function () {
101 const beforePublication = new Date()
102 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
104 for (const server of servers) {
105 await server.live.waitUntilPublished({ videoId: videoUUID })
108 await checkVideoState(videoUUID, VideoState.PUBLISHED)
110 for (const server of servers) {
111 const video = await server.videos.get({ id: videoUUID })
112 expect(new Date(video.publishedAt)).greaterThan(beforePublication)
115 await stopFfmpeg(ffmpegCommand)
116 await servers[0].live.waitUntilWaiting({ videoId: videoUUID })
118 await waitJobs(servers)
121 it('Should have cleaned up this live', async function () {
125 await waitJobs(servers)
127 for (const server of servers) {
128 const videoDetails = await server.videos.get({ id: videoUUID })
130 expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
134 it('Should have set this live to waiting for live state', async function () {
137 await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
140 it('Should be able to stream again in the permanent live', async function () {
143 await servers[0].config.updateCustomSubConfig({
151 resolutions: ConfigCommand.getCustomConfigResolutions(false)
157 const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
159 for (const server of servers) {
160 await server.live.waitUntilPublished({ videoId: videoUUID })
163 await checkVideoState(videoUUID, VideoState.PUBLISHED)
165 const count = await servers[0].live.countPlaylists({ videoUUID })
166 // master playlist and 720p playlist
167 expect(count).to.equal(2)
169 await stopFfmpeg(ffmpegCommand)
172 it('Should have appropriate sessions', async function () {
175 await servers[0].live.waitUntilWaiting({ videoId: videoUUID })
177 const { data, total } = await servers[0].live.listSessions({ videoId: videoUUID })
178 expect(total).to.equal(2)
179 expect(data).to.have.lengthOf(2)
181 for (const session of data) {
182 expect(session.startDate).to.exist
183 expect(session.endDate).to.exist
185 expect(session.error).to.not.exist
189 after(async function () {
190 await cleanupTests(servers)