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