PeerTube/server/tests/api/live/live-permanent.ts

205 lines
5.5 KiB
TypeScript
Raw Normal View History

2020-12-03 14:10:54 +01:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2022-08-17 15:44:32 +02:00
import { expect } from 'chai'
import { checkLiveCleanup } from '@server/tests/shared'
import { wait } from '@shared/core-utils'
2021-07-15 10:02:54 +02:00
import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
2020-12-03 14:10:54 +01:00
import {
cleanupTests,
2021-07-07 11:51:09 +02:00
ConfigCommand,
2021-07-16 09:47:51 +02:00
createMultipleServers,
2021-07-16 14:27:30 +02:00
doubleFollow,
2021-07-16 09:47:51 +02:00
PeerTubeServer,
2020-12-03 14:10:54 +01:00
setAccessTokensToServers,
setDefaultVideoChannel,
stopFfmpeg,
2021-07-08 10:18:40 +02:00
waitJobs
} from '@shared/server-commands'
2020-12-03 14:10:54 +01:00
2021-06-11 16:02:26 +02:00
describe('Permanent live', function () {
2021-07-16 09:47:51 +02:00
let servers: PeerTubeServer[] = []
2020-12-03 14:10:54 +01:00
let videoUUID: string
async function createLiveWrapper (permanentLive: boolean) {
const attributes: LiveVideoCreate = {
2021-07-16 09:04:35 +02:00
channelId: servers[0].store.channel.id,
2020-12-03 14:10:54 +01:00
privacy: VideoPrivacy.PUBLIC,
name: 'my super live',
saveReplay: false,
permanentLive
}
2021-07-16 09:04:35 +02:00
const { uuid } = await servers[0].live.create({ fields: attributes })
2021-07-08 10:18:40 +02:00
return uuid
2020-12-03 14:10:54 +01:00
}
async function checkVideoState (videoId: string, state: VideoState) {
for (const server of servers) {
2021-07-16 09:04:35 +02:00
const video = await server.videos.get({ id: videoId })
2021-07-15 10:02:54 +02:00
expect(video.state.id).to.equal(state)
2020-12-03 14:10:54 +01:00
}
}
before(async function () {
this.timeout(120000)
2021-07-16 09:47:51 +02:00
servers = await createMultipleServers(2)
2020-12-03 14:10:54 +01:00
// Get the access tokens
await setAccessTokensToServers(servers)
await setDefaultVideoChannel(servers)
// Server 1 and server 2 follow each other
await doubleFollow(servers[0], servers[1])
2021-07-16 09:04:35 +02:00
await servers[0].config.updateCustomSubConfig({
2021-07-07 11:51:09 +02:00
newConfig: {
live: {
2020-12-03 14:10:54 +01:00
enabled: true,
2021-07-07 11:51:09 +02:00
allowReplay: true,
maxDuration: -1,
transcoding: {
enabled: true,
resolutions: ConfigCommand.getCustomConfigResolutions(true)
}
2020-12-03 14:10:54 +01:00
}
}
})
})
it('Should create a non permanent live and update it to be a permanent live', async function () {
this.timeout(20000)
const videoUUID = await createLiveWrapper(false)
{
2021-07-16 09:04:35 +02:00
const live = await servers[0].live.get({ videoId: videoUUID })
2021-07-08 10:18:40 +02:00
expect(live.permanentLive).to.be.false
2020-12-03 14:10:54 +01:00
}
2021-07-16 09:04:35 +02:00
await servers[0].live.update({ videoId: videoUUID, fields: { permanentLive: true } })
2020-12-03 14:10:54 +01:00
{
2021-07-16 09:04:35 +02:00
const live = await servers[0].live.get({ videoId: videoUUID })
2021-07-08 10:18:40 +02:00
expect(live.permanentLive).to.be.true
2020-12-03 14:10:54 +01:00
}
})
it('Should create a permanent live', async function () {
this.timeout(20000)
videoUUID = await createLiveWrapper(true)
2021-07-16 09:04:35 +02:00
const live = await servers[0].live.get({ videoId: videoUUID })
2021-07-08 10:18:40 +02:00
expect(live.permanentLive).to.be.true
2020-12-03 14:10:54 +01:00
await waitJobs(servers)
})
it('Should stream into this permanent live', async function () {
2022-08-16 14:49:16 +02:00
this.timeout(240_000)
2020-12-03 14:10:54 +01:00
const beforePublication = new Date()
2021-07-16 09:04:35 +02:00
const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
2020-12-03 14:10:54 +01:00
for (const server of servers) {
2021-07-16 09:04:35 +02:00
await server.live.waitUntilPublished({ videoId: videoUUID })
2020-12-03 14:10:54 +01:00
}
await checkVideoState(videoUUID, VideoState.PUBLISHED)
for (const server of servers) {
const video = await server.videos.get({ id: videoUUID })
expect(new Date(video.publishedAt)).greaterThan(beforePublication)
}
2021-07-08 10:18:40 +02:00
await stopFfmpeg(ffmpegCommand)
2021-07-16 09:04:35 +02:00
await servers[0].live.waitUntilWaiting({ videoId: videoUUID })
2020-12-03 14:10:54 +01:00
await waitJobs(servers)
})
it('Should have cleaned up this live', async function () {
2020-12-03 14:10:54 +01:00
this.timeout(40000)
await wait(5000)
await waitJobs(servers)
for (const server of servers) {
2021-07-16 09:04:35 +02:00
const videoDetails = await server.videos.get({ id: videoUUID })
expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
2020-12-03 14:10:54 +01:00
}
await checkLiveCleanup({ server: servers[0], permanent: true, videoUUID })
2020-12-03 14:10:54 +01:00
})
it('Should have set this live to waiting for live state', async function () {
this.timeout(20000)
await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
})
it('Should be able to stream again in the permanent live', async function () {
2021-12-24 15:19:45 +01:00
this.timeout(60000)
2020-12-03 14:10:54 +01:00
2021-07-16 09:04:35 +02:00
await servers[0].config.updateCustomSubConfig({
2021-07-07 11:51:09 +02:00
newConfig: {
live: {
2020-12-03 14:10:54 +01:00
enabled: true,
2021-07-07 11:51:09 +02:00
allowReplay: true,
maxDuration: -1,
transcoding: {
enabled: true,
resolutions: ConfigCommand.getCustomConfigResolutions(false)
}
2020-12-03 14:10:54 +01:00
}
}
})
2021-07-16 09:04:35 +02:00
const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
2020-12-03 14:10:54 +01:00
for (const server of servers) {
2021-07-16 09:04:35 +02:00
await server.live.waitUntilPublished({ videoId: videoUUID })
2020-12-03 14:10:54 +01:00
}
await checkVideoState(videoUUID, VideoState.PUBLISHED)
2021-07-16 09:04:35 +02:00
const count = await servers[0].live.countPlaylists({ videoUUID })
2020-12-03 14:10:54 +01:00
// master playlist and 720p playlist
expect(count).to.equal(2)
2021-07-08 10:18:40 +02:00
await stopFfmpeg(ffmpegCommand)
2020-12-03 14:10:54 +01:00
})
2022-05-03 11:38:07 +02:00
it('Should have appropriate sessions', async function () {
this.timeout(60000)
await servers[0].live.waitUntilWaiting({ videoId: videoUUID })
const { data, total } = await servers[0].live.listSessions({ videoId: videoUUID })
expect(total).to.equal(2)
expect(data).to.have.lengthOf(2)
for (const session of data) {
expect(session.startDate).to.exist
expect(session.endDate).to.exist
expect(session.error).to.not.exist
}
})
it('Should remove the live and have cleaned up the directory', async function () {
this.timeout(60000)
await servers[0].videos.remove({ id: videoUUID })
await waitJobs(servers)
await checkLiveCleanup({ server: servers[0], permanent: true, videoUUID })
})
2020-12-03 14:10:54 +01:00
after(async function () {
await cleanupTests(servers)
})
})