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,
21 waitUntilLivePublishedOnAllServers
22 } from '../../../../shared/extra-utils'
24 const expect = chai.expect
26 describe('Test live', function () {
27 let servers: ServerInfo[] = []
29 before(async function () {
32 servers = await flushAndRunMultipleServers(2)
34 // Get the access tokens
35 await setAccessTokensToServers(servers)
36 await setDefaultVideoChannel(servers)
38 await servers[0].configCommand.updateCustomSubConfig({
50 // Server 1 and server 2 follow each other
51 await doubleFollow(servers[0], servers[1])
54 describe('Live views', function () {
55 let liveVideoId: string
56 let command: FfmpegCommand
58 async function countViews (expected: number) {
59 for (const server of servers) {
60 const res = await getVideo(server.url, liveVideoId)
61 const video: VideoDetails = res.body
63 expect(video.views).to.equal(expected)
67 before(async function () {
70 const liveAttributes = {
72 channelId: servers[0].videoChannel.id,
73 privacy: VideoPrivacy.PUBLIC
76 const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes)
77 liveVideoId = res.body.video.uuid
79 command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId)
80 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
81 await waitJobs(servers)
84 it('Should display no views for a live', async function () {
88 it('Should view a live twice and display 1 view', async function () {
91 await viewVideo(servers[0].url, liveVideoId)
92 await viewVideo(servers[0].url, liveVideoId)
96 await waitJobs(servers)
101 it('Should wait and display 0 views', async function () {
105 await waitJobs(servers)
110 it('Should view a live on a remote and on local and display 2 views', async function () {
113 await viewVideo(servers[0].url, liveVideoId)
114 await viewVideo(servers[1].url, liveVideoId)
115 await viewVideo(servers[1].url, liveVideoId)
118 await waitJobs(servers)
123 after(async function () {
124 await stopFfmpeg(command)
128 after(async function () {
129 await cleanupTests(servers)