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('Live views', 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 let liveVideoId: string
51 let command: FfmpegCommand
53 async function countViewers (expectedViewers: number) {
54 for (const server of servers) {
55 const video = await server.videos.get({ id: liveVideoId })
56 expect(video.viewers).to.equal(expectedViewers)
60 async function countViews (expectedViews: number) {
61 for (const server of servers) {
62 const video = await server.videos.get({ id: liveVideoId })
63 expect(video.views).to.equal(expectedViews)
67 before(async function () {
70 const liveAttributes = {
72 channelId: servers[0].store.channel.id,
73 privacy: VideoPrivacy.PUBLIC
76 const live = await servers[0].live.create({ fields: liveAttributes })
77 liveVideoId = live.uuid
79 command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId })
80 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
81 await waitJobs(servers)
84 it('Should display no views and viewers for a live', async function () {
89 it('Should view a live twice and display 1 view/viewer', async function () {
92 await servers[0].videos.view({ id: liveVideoId })
93 await servers[0].videos.view({ id: liveVideoId })
95 await waitJobs(servers)
102 it('Should wait and display 0 viewers while still have 1 view', async function () {
106 await waitJobs(servers)
109 await countViewers(0)
112 it('Should view a live on a remote and on local and display 2 viewers and 3 views', async function () {
115 await servers[0].videos.view({ id: liveVideoId })
116 await servers[1].videos.view({ id: liveVideoId })
117 await servers[1].videos.view({ id: liveVideoId })
118 await waitJobs(servers)
120 await countViewers(2)
123 await waitJobs(servers)
128 after(async function () {
129 await stopFfmpeg(command)
130 await cleanupTests(servers)