]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/live/live-views.ts
Introduce videos command
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live-views.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { FfmpegCommand } from 'fluent-ffmpeg'
6 import { VideoPrivacy } from '@shared/models'
7 import {
8 cleanupTests,
9 doubleFollow,
10 flushAndRunMultipleServers,
11 ServerInfo,
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
14 stopFfmpeg,
15 wait,
16 waitJobs,
17 waitUntilLivePublishedOnAllServers
18 } from '../../../../shared/extra-utils'
19
20 const expect = chai.expect
21
22 describe('Test live', function () {
23 let servers: ServerInfo[] = []
24
25 before(async function () {
26 this.timeout(120000)
27
28 servers = await flushAndRunMultipleServers(2)
29
30 // Get the access tokens
31 await setAccessTokensToServers(servers)
32 await setDefaultVideoChannel(servers)
33
34 await servers[0].configCommand.updateCustomSubConfig({
35 newConfig: {
36 live: {
37 enabled: true,
38 allowReplay: true,
39 transcoding: {
40 enabled: false
41 }
42 }
43 }
44 })
45
46 // Server 1 and server 2 follow each other
47 await doubleFollow(servers[0], servers[1])
48 })
49
50 describe('Live views', function () {
51 let liveVideoId: string
52 let command: FfmpegCommand
53
54 async function countViews (expected: number) {
55 for (const server of servers) {
56 const video = await server.videosCommand.get({ id: liveVideoId })
57 expect(video.views).to.equal(expected)
58 }
59 }
60
61 before(async function () {
62 this.timeout(30000)
63
64 const liveAttributes = {
65 name: 'live video',
66 channelId: servers[0].videoChannel.id,
67 privacy: VideoPrivacy.PUBLIC
68 }
69
70 const live = await servers[0].liveCommand.create({ fields: liveAttributes })
71 liveVideoId = live.uuid
72
73 command = await servers[0].liveCommand.sendRTMPStreamInVideo({ videoId: liveVideoId })
74 await waitUntilLivePublishedOnAllServers(servers, liveVideoId)
75 await waitJobs(servers)
76 })
77
78 it('Should display no views for a live', async function () {
79 await countViews(0)
80 })
81
82 it('Should view a live twice and display 1 view', async function () {
83 this.timeout(30000)
84
85 await servers[0].videosCommand.view({ id: liveVideoId })
86 await servers[0].videosCommand.view({ id: liveVideoId })
87
88 await wait(7000)
89
90 await waitJobs(servers)
91
92 await countViews(1)
93 })
94
95 it('Should wait and display 0 views', async function () {
96 this.timeout(30000)
97
98 await wait(12000)
99 await waitJobs(servers)
100
101 await countViews(0)
102 })
103
104 it('Should view a live on a remote and on local and display 2 views', async function () {
105 this.timeout(30000)
106
107 await servers[0].videosCommand.view({ id: liveVideoId })
108 await servers[1].videosCommand.view({ id: liveVideoId })
109 await servers[1].videosCommand.view({ id: liveVideoId })
110
111 await wait(7000)
112 await waitJobs(servers)
113
114 await countViews(2)
115 })
116
117 after(async function () {
118 await stopFfmpeg(command)
119 })
120 })
121
122 after(async function () {
123 await cleanupTests(servers)
124 })
125 })