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 { VideoPrivacy } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
17 waitUntilLivePublishedOnAllServers
18 } from '../../../../shared/extra-utils'
20 const expect = chai.expect
22 describe('Test live', function () {
23 let servers: PeerTubeServer[] = []
25 before(async function () {
28 servers = await createMultipleServers(2)
30 // Get the access tokens
31 await setAccessTokensToServers(servers)
32 await setDefaultVideoChannel(servers)
34 await servers[0].config.updateCustomSubConfig({
46 // Server 1 and server 2 follow each other
47 await doubleFollow(servers[0], servers[1])
50 describe('Live views', function () {
51 let liveVideoId: string
52 let command: FfmpegCommand
54 async function countViews (expected: number) {
55 for (const server of servers) {
56 const video = await server.videos.get({ id: liveVideoId })
57 expect(video.views).to.equal(expected)
61 before(async function () {
64 const liveAttributes = {
66 channelId: servers[0].store.channel.id,
67 privacy: VideoPrivacy.PUBLIC
70 const live = await servers[0].live.create({ fields: liveAttributes })
71 liveVideoId = live.uuid
73 command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId })
74 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
75 await waitJobs(servers)
78 it('Should display no views for a live', async function () {
82 it('Should view a live twice and display 1 view', async function () {
85 await servers[0].videos.view({ id: liveVideoId })
86 await servers[0].videos.view({ id: liveVideoId })
90 await waitJobs(servers)
95 it('Should wait and display 0 views', async function () {
99 await waitJobs(servers)
104 it('Should view a live on a remote and on local and display 2 views', async function () {
107 await servers[0].videos.view({ id: liveVideoId })
108 await servers[1].videos.view({ id: liveVideoId })
109 await servers[1].videos.view({ id: liveVideoId })
112 await waitJobs(servers)
117 after(async function () {
118 await stopFfmpeg(command)
122 after(async function () {
123 await cleanupTests(servers)