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