]>
Commit | Line | Data |
---|---|---|
8ebf2a5d C |
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' | |
d23dd9fb | 6 | import { VideoPrivacy } from '@shared/models' |
8ebf2a5d C |
7 | import { |
8 | cleanupTests, | |
254d3579 | 9 | createMultipleServers, |
4c7e60bc | 10 | doubleFollow, |
254d3579 | 11 | PeerTubeServer, |
8ebf2a5d C |
12 | setAccessTokensToServers, |
13 | setDefaultVideoChannel, | |
14 | stopFfmpeg, | |
8ebf2a5d C |
15 | wait, |
16 | waitJobs, | |
17 | waitUntilLivePublishedOnAllServers | |
18 | } from '../../../../shared/extra-utils' | |
19 | ||
20 | const expect = chai.expect | |
21 | ||
22 | describe('Test live', function () { | |
254d3579 | 23 | let servers: PeerTubeServer[] = [] |
8ebf2a5d C |
24 | |
25 | before(async function () { | |
26 | this.timeout(120000) | |
27 | ||
254d3579 | 28 | servers = await createMultipleServers(2) |
8ebf2a5d C |
29 | |
30 | // Get the access tokens | |
31 | await setAccessTokensToServers(servers) | |
32 | await setDefaultVideoChannel(servers) | |
33 | ||
89d241a7 | 34 | await servers[0].config.updateCustomSubConfig({ |
65e6e260 C |
35 | newConfig: { |
36 | live: { | |
37 | enabled: true, | |
38 | allowReplay: true, | |
39 | transcoding: { | |
40 | enabled: false | |
41 | } | |
8ebf2a5d C |
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) { | |
89d241a7 | 56 | const video = await server.videos.get({ id: liveVideoId }) |
8ebf2a5d C |
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', | |
89d241a7 | 66 | channelId: servers[0].store.channel.id, |
8ebf2a5d C |
67 | privacy: VideoPrivacy.PUBLIC |
68 | } | |
69 | ||
89d241a7 | 70 | const live = await servers[0].live.create({ fields: liveAttributes }) |
4f219914 | 71 | liveVideoId = live.uuid |
8ebf2a5d | 72 | |
89d241a7 | 73 | command = await servers[0].live.sendRTMPStreamInVideo({ videoId: liveVideoId }) |
8ebf2a5d C |
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 | ||
89d241a7 C |
85 | await servers[0].videos.view({ id: liveVideoId }) |
86 | await servers[0].videos.view({ id: liveVideoId }) | |
8ebf2a5d C |
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 | ||
89d241a7 C |
107 | await servers[0].videos.view({ id: liveVideoId }) |
108 | await servers[1].videos.view({ id: liveVideoId }) | |
109 | await servers[1].videos.view({ id: liveVideoId }) | |
8ebf2a5d C |
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 | }) |