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