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'
11 flushAndRunMultipleServers,
13 sendRTMPStreamInVideo,
15 setAccessTokensToServers,
16 setDefaultVideoChannel,
18 updateCustomSubConfig,
22 waitUntilLivePublishedOnAllServers
23 } from '../../../../shared/extra-utils'
25 const expect = chai.expect
27 describe('Test live', function () {
28 let servers: ServerInfo[] = []
30 before(async function () {
33 servers = await flushAndRunMultipleServers(2)
35 // Get the access tokens
36 await setAccessTokensToServers(servers)
37 await setDefaultVideoChannel(servers)
39 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
49 // Server 1 and server 2 follow each other
50 await doubleFollow(servers[0], servers[1])
53 describe('Live views', function () {
54 let liveVideoId: string
55 let command: FfmpegCommand
57 async function countViews (expected: number) {
58 for (const server of servers) {
59 const res = await getVideo(server.url, liveVideoId)
60 const video: VideoDetails = res.body
62 expect(video.views).to.equal(expected)
66 before(async function () {
69 const liveAttributes = {
71 channelId: servers[0].videoChannel.id,
72 privacy: VideoPrivacy.PUBLIC
75 const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes)
76 liveVideoId = res.body.video.uuid
78 command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId)
79 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
80 await waitJobs(servers)
83 it('Should display no views for a live', async function () {
87 it('Should view a live twice and display 1 view', async function () {
90 await viewVideo(servers[0].url, liveVideoId)
91 await viewVideo(servers[0].url, liveVideoId)
95 await waitJobs(servers)
100 it('Should wait and display 0 views', async function () {
104 await waitJobs(servers)
109 it('Should view a live on a remote and on local and display 2 views', async function () {
112 await viewVideo(servers[0].url, liveVideoId)
113 await viewVideo(servers[1].url, liveVideoId)
114 await viewVideo(servers[1].url, liveVideoId)
117 await waitJobs(servers)
122 after(async function () {
123 await stopFfmpeg(command)
127 after(async function () {
128 await cleanupTests(servers)