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

172 lines
4.6 KiB
TypeScript
Raw Normal View History

2020-12-03 07:10:54 -06:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import * as chai from 'chai'
2021-07-15 03:02:54 -05:00
import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models'
2020-12-03 07:10:54 -06:00
import {
cleanupTests,
2021-07-07 04:51:09 -05:00
ConfigCommand,
2020-12-03 07:10:54 -06:00
doubleFollow,
flushAndRunMultipleServers,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
stopFfmpeg,
wait,
2021-07-08 03:18:40 -05:00
waitJobs
2020-12-03 07:10:54 -06:00
} from '../../../../shared/extra-utils'
const expect = chai.expect
2021-06-11 09:02:26 -05:00
describe('Permanent live', function () {
2020-12-03 07:10:54 -06:00
let servers: ServerInfo[] = []
let videoUUID: string
async function createLiveWrapper (permanentLive: boolean) {
const attributes: LiveVideoCreate = {
channelId: servers[0].videoChannel.id,
privacy: VideoPrivacy.PUBLIC,
name: 'my super live',
saveReplay: false,
permanentLive
}
2021-07-08 03:25:50 -05:00
const { uuid } = await servers[0].liveCommand.create({ fields: attributes })
2021-07-08 03:18:40 -05:00
return uuid
2020-12-03 07:10:54 -06:00
}
async function checkVideoState (videoId: string, state: VideoState) {
for (const server of servers) {
2021-07-15 03:02:54 -05:00
const video = await server.videosCommand.get({ id: videoId })
expect(video.state.id).to.equal(state)
2020-12-03 07:10:54 -06:00
}
}
before(async function () {
this.timeout(120000)
servers = await flushAndRunMultipleServers(2)
// 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-07 04:51:09 -05:00
await servers[0].configCommand.updateCustomSubConfig({
newConfig: {
live: {
2020-12-03 07:10:54 -06:00
enabled: true,
2021-07-07 04:51:09 -05:00
allowReplay: true,
maxDuration: -1,
transcoding: {
enabled: true,
resolutions: ConfigCommand.getCustomConfigResolutions(true)
}
2020-12-03 07:10:54 -06: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-08 03:25:50 -05:00
const live = await servers[0].liveCommand.get({ videoId: videoUUID })
2021-07-08 03:18:40 -05:00
expect(live.permanentLive).to.be.false
2020-12-03 07:10:54 -06:00
}
2021-07-08 03:25:50 -05:00
await servers[0].liveCommand.update({ videoId: videoUUID, fields: { permanentLive: true } })
2020-12-03 07:10:54 -06:00
{
2021-07-08 03:25:50 -05:00
const live = await servers[0].liveCommand.get({ videoId: videoUUID })
2021-07-08 03:18:40 -05:00
expect(live.permanentLive).to.be.true
2020-12-03 07:10:54 -06:00
}
})
it('Should create a permanent live', async function () {
this.timeout(20000)
videoUUID = await createLiveWrapper(true)
2021-07-08 03:25:50 -05:00
const live = await servers[0].liveCommand.get({ videoId: videoUUID })
2021-07-08 03:18:40 -05:00
expect(live.permanentLive).to.be.true
2020-12-03 07:10:54 -06:00
await waitJobs(servers)
})
it('Should stream into this permanent live', async function () {
2021-06-08 11:15:25 -05:00
this.timeout(120000)
2020-12-03 07:10:54 -06:00
2021-07-08 03:18:40 -05:00
const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID })
2020-12-03 07:10:54 -06:00
for (const server of servers) {
2021-07-08 03:25:50 -05:00
await server.liveCommand.waitUntilPublished({ videoId: videoUUID })
2020-12-03 07:10:54 -06:00
}
await checkVideoState(videoUUID, VideoState.PUBLISHED)
2021-07-08 03:18:40 -05:00
await stopFfmpeg(ffmpegCommand)
2021-07-08 03:25:50 -05:00
await servers[0].liveCommand.waitUntilWaiting({ videoId: videoUUID })
2020-12-03 07:10:54 -06:00
await waitJobs(servers)
})
it('Should not have cleaned up this live', async function () {
this.timeout(40000)
await wait(5000)
await waitJobs(servers)
for (const server of servers) {
2021-07-15 03:02:54 -05:00
const videoDetails = await server.videosCommand.get({ id: videoUUID })
2020-12-03 07:10:54 -06:00
expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
}
})
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 () {
this.timeout(20000)
2021-07-07 04:51:09 -05:00
await servers[0].configCommand.updateCustomSubConfig({
newConfig: {
live: {
2020-12-03 07:10:54 -06:00
enabled: true,
2021-07-07 04:51:09 -05:00
allowReplay: true,
maxDuration: -1,
transcoding: {
enabled: true,
resolutions: ConfigCommand.getCustomConfigResolutions(false)
}
2020-12-03 07:10:54 -06:00
}
}
})
2021-07-08 03:18:40 -05:00
const ffmpegCommand = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: videoUUID })
2020-12-03 07:10:54 -06:00
for (const server of servers) {
2021-07-08 03:25:50 -05:00
await server.liveCommand.waitUntilPublished({ videoId: videoUUID })
2020-12-03 07:10:54 -06:00
}
await checkVideoState(videoUUID, VideoState.PUBLISHED)
2021-07-08 03:25:50 -05:00
const count = await servers[0].liveCommand.countPlaylists({ videoUUID })
2020-12-03 07:10:54 -06:00
// master playlist and 720p playlist
expect(count).to.equal(2)
2021-07-08 03:18:40 -05:00
await stopFfmpeg(ffmpegCommand)
2020-12-03 07:10:54 -06:00
})
after(async function () {
await cleanupTests(servers)
})
})