1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { FfmpegCommand } from 'fluent-ffmpeg'
6 import { expectStartWith } from '@server/tests/shared'
7 import { areObjectStorageTestsDisabled } from '@shared/core-utils'
8 import { HttpStatusCode, LiveVideoCreate, VideoFile, VideoPrivacy } from '@shared/models'
10 createMultipleServers,
16 setAccessTokensToServers,
17 setDefaultVideoChannel,
20 waitUntilLivePublishedOnAllServers,
21 waitUntilLiveSavedOnAllServers
22 } from '@shared/server-commands'
24 const expect = chai.expect
26 async function createLive (server: PeerTubeServer) {
27 const attributes: LiveVideoCreate = {
28 channelId: server.store.channel.id,
29 privacy: VideoPrivacy.PUBLIC,
30 name: 'my super live',
34 const { uuid } = await server.live.create({ fields: attributes })
39 async function checkFiles (files: VideoFile[]) {
40 for (const file of files) {
41 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
43 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
47 describe('Object storage for lives', function () {
48 if (areObjectStorageTestsDisabled()) return
50 let ffmpegCommand: FfmpegCommand
51 let servers: PeerTubeServer[]
54 before(async function () {
57 await ObjectStorageCommand.prepareDefaultBuckets()
59 servers = await createMultipleServers(2, ObjectStorageCommand.getDefaultConfig())
61 await setAccessTokensToServers(servers)
62 await setDefaultVideoChannel(servers)
63 await doubleFollow(servers[0], servers[1])
65 await servers[0].config.enableTranscoding()
68 describe('Without live transcoding', async function () {
70 before(async function () {
71 await servers[0].config.enableLive({ transcoding: false })
73 videoUUID = await createLive(servers[0])
76 it('Should create a live and save the replay on object storage', async function () {
79 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
80 await waitUntilLivePublishedOnAllServers(servers, videoUUID)
82 await stopFfmpeg(ffmpegCommand)
84 await waitUntilLiveSavedOnAllServers(servers, videoUUID)
85 await waitJobs(servers)
87 for (const server of servers) {
88 const video = await server.videos.get({ id: videoUUID })
90 expect(video.files).to.have.lengthOf(0)
91 expect(video.streamingPlaylists).to.have.lengthOf(1)
93 const files = video.streamingPlaylists[0].files
95 await checkFiles(files)
100 describe('With live transcoding', async function () {
102 before(async function () {
103 await servers[0].config.enableLive({ transcoding: true })
105 videoUUID = await createLive(servers[0])
108 it('Should import a video and have sent it to object storage', async function () {
111 ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: videoUUID })
112 await waitUntilLivePublishedOnAllServers(servers, videoUUID)
114 await stopFfmpeg(ffmpegCommand)
116 await waitUntilLiveSavedOnAllServers(servers, videoUUID)
117 await waitJobs(servers)
119 for (const server of servers) {
120 const video = await server.videos.get({ id: videoUUID })
122 expect(video.files).to.have.lengthOf(0)
123 expect(video.streamingPlaylists).to.have.lengthOf(1)
125 const files = video.streamingPlaylists[0].files
126 expect(files).to.have.lengthOf(5)
128 await checkFiles(files)
133 after(async function () {
134 await killallServers(servers)