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 { VideoDetails, VideoPrivacy } from '@shared/models'
10 flushAndRunMultipleServers,
13 setAccessTokensToServers,
14 setDefaultVideoChannel,
19 waitUntilLivePublishedOnAllServers
20 } from '../../../../shared/extra-utils'
22 const expect = chai.expect
24 describe('Test live', function () {
25 let servers: ServerInfo[] = []
27 before(async function () {
30 servers = await flushAndRunMultipleServers(2)
32 // Get the access tokens
33 await setAccessTokensToServers(servers)
34 await setDefaultVideoChannel(servers)
36 await servers[0].configCommand.updateCustomSubConfig({
48 // Server 1 and server 2 follow each other
49 await doubleFollow(servers[0], servers[1])
52 describe('Live views', function () {
53 let liveVideoId: string
54 let command: FfmpegCommand
56 async function countViews (expected: number) {
57 for (const server of servers) {
58 const res = await getVideo(server.url, liveVideoId)
59 const video: VideoDetails = res.body
61 expect(video.views).to.equal(expected)
65 before(async function () {
68 const liveAttributes = {
70 channelId: servers[0].videoChannel.id,
71 privacy: VideoPrivacy.PUBLIC
74 const live = await servers[0].liveCommand.create({ fields: liveAttributes })
75 liveVideoId = live.uuid
77 command = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId })
78 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
79 await waitJobs(servers)
82 it('Should display no views for a live', async function () {
86 it('Should view a live twice and display 1 view', async function () {
89 await viewVideo(servers[0].url, liveVideoId)
90 await viewVideo(servers[0].url, liveVideoId)
94 await waitJobs(servers)
99 it('Should wait and display 0 views', async function () {
103 await waitJobs(servers)
108 it('Should view a live on a remote and on local and display 2 views', async function () {
111 await viewVideo(servers[0].url, liveVideoId)
112 await viewVideo(servers[1].url, liveVideoId)
113 await viewVideo(servers[1].url, liveVideoId)
116 await waitJobs(servers)
121 after(async function () {
122 await stopFfmpeg(command)
126 after(async function () {
127 await cleanupTests(servers)