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

179 lines
4.7 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 */
import 'mocha'
import * as chai from 'chai'
import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models'
import {
cleanupTests,
createLive,
doubleFollow,
flushAndRunMultipleServers,
2021-05-07 11:53:46 +02:00
getCustomConfigResolutions,
2020-12-03 14:10:54 +01:00
getLive,
getPlaylistsCount,
getVideo,
sendRTMPStreamInVideo,
ServerInfo,
setAccessTokensToServers,
setDefaultVideoChannel,
stopFfmpeg,
updateCustomSubConfig,
updateLive,
wait,
waitJobs,
2020-12-11 10:36:05 +01:00
waitUntilLivePublished,
waitUntilLiveWaiting
2020-12-03 14:10:54 +01:00
} from '../../../../shared/extra-utils'
const expect = chai.expect
2021-06-11 16:02:26 +02:00
describe('Permanent live', function () {
2020-12-03 14:10:54 +01: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
}
const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
return res.body.video.uuid
}
async function checkVideoState (videoId: string, state: VideoState) {
for (const server of servers) {
const res = await getVideo(server.url, videoId)
expect((res.body as VideoDetails).state.id).to.equal(state)
}
}
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])
await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
live: {
enabled: true,
allowReplay: true,
2020-12-15 09:23:28 +01:00
maxDuration: -1,
2020-12-03 14:10:54 +01:00
transcoding: {
enabled: true,
2021-05-07 11:53:46 +02:00
resolutions: 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)
{
const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
expect(res.body.permanentLive).to.be.false
}
await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true })
{
const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
expect(res.body.permanentLive).to.be.true
}
})
it('Should create a permanent live', async function () {
this.timeout(20000)
videoUUID = await createLiveWrapper(true)
const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
expect(res.body.permanentLive).to.be.true
await waitJobs(servers)
})
it('Should stream into this permanent live', async function () {
2021-06-08 18:15:25 +02:00
this.timeout(120000)
2020-12-03 14:10:54 +01:00
const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
for (const server of servers) {
2020-12-09 14:42:42 +01:00
await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
2020-12-03 14:10:54 +01:00
}
await checkVideoState(videoUUID, VideoState.PUBLISHED)
await stopFfmpeg(command)
2020-12-11 10:36:05 +01:00
await waitUntilLiveWaiting(servers[0].url, servers[0].accessToken, videoUUID)
2020-12-03 14:10:54 +01: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) {
const res = await getVideo(server.url, videoUUID)
const videoDetails = res.body as VideoDetails
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)
await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
live: {
enabled: true,
allowReplay: true,
2020-12-15 09:23:28 +01:00
maxDuration: -1,
2020-12-03 14:10:54 +01:00
transcoding: {
enabled: true,
2021-05-07 11:53:46 +02:00
resolutions: getCustomConfigResolutions(false)
2020-12-03 14:10:54 +01:00
}
}
})
const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)
for (const server of servers) {
2020-12-09 14:42:42 +01:00
await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
2020-12-03 14:10:54 +01:00
}
await checkVideoState(videoUUID, VideoState.PUBLISHED)
const count = await getPlaylistsCount(servers[0], videoUUID)
// master playlist and 720p playlist
expect(count).to.equal(2)
await stopFfmpeg(command)
})
after(async function () {
await cleanupTests(servers)
})
})