]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' | |
6 | import { | |
7 | cleanupTests, | |
8 | createLive, | |
9 | doubleFollow, | |
10 | flushAndRunMultipleServers, | |
11 | getLive, | |
12 | getPlaylistsCount, | |
13 | getVideo, | |
14 | sendRTMPStreamInVideo, | |
15 | ServerInfo, | |
16 | setAccessTokensToServers, | |
17 | setDefaultVideoChannel, | |
18 | stopFfmpeg, | |
19 | updateCustomSubConfig, | |
20 | updateLive, | |
21 | wait, | |
22 | waitJobs, | |
23 | waitUntilLiveStarts | |
24 | } from '../../../../shared/extra-utils' | |
25 | ||
26 | const expect = chai.expect | |
27 | ||
28 | describe('Permenant live', function () { | |
29 | let servers: ServerInfo[] = [] | |
30 | let videoUUID: string | |
31 | ||
32 | async function createLiveWrapper (permanentLive: boolean) { | |
33 | const attributes: LiveVideoCreate = { | |
34 | channelId: servers[0].videoChannel.id, | |
35 | privacy: VideoPrivacy.PUBLIC, | |
36 | name: 'my super live', | |
37 | saveReplay: false, | |
38 | permanentLive | |
39 | } | |
40 | ||
41 | const res = await createLive(servers[0].url, servers[0].accessToken, attributes) | |
42 | return res.body.video.uuid | |
43 | } | |
44 | ||
45 | async function checkVideoState (videoId: string, state: VideoState) { | |
46 | for (const server of servers) { | |
47 | const res = await getVideo(server.url, videoId) | |
48 | expect((res.body as VideoDetails).state.id).to.equal(state) | |
49 | } | |
50 | } | |
51 | ||
52 | before(async function () { | |
53 | this.timeout(120000) | |
54 | ||
55 | servers = await flushAndRunMultipleServers(2) | |
56 | ||
57 | // Get the access tokens | |
58 | await setAccessTokensToServers(servers) | |
59 | await setDefaultVideoChannel(servers) | |
60 | ||
61 | // Server 1 and server 2 follow each other | |
62 | await doubleFollow(servers[0], servers[1]) | |
63 | ||
64 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
65 | live: { | |
66 | enabled: true, | |
67 | allowReplay: true, | |
68 | maxDuration: null, | |
69 | transcoding: { | |
70 | enabled: true, | |
71 | resolutions: { | |
72 | '240p': true, | |
73 | '360p': true, | |
74 | '480p': true, | |
75 | '720p': true, | |
76 | '1080p': true, | |
77 | '2160p': true | |
78 | } | |
79 | } | |
80 | } | |
81 | }) | |
82 | }) | |
83 | ||
84 | it('Should create a non permanent live and update it to be a permanent live', async function () { | |
85 | this.timeout(20000) | |
86 | ||
87 | const videoUUID = await createLiveWrapper(false) | |
88 | ||
89 | { | |
90 | const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) | |
91 | expect(res.body.permanentLive).to.be.false | |
92 | } | |
93 | ||
94 | await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true }) | |
95 | ||
96 | { | |
97 | const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) | |
98 | expect(res.body.permanentLive).to.be.true | |
99 | } | |
100 | }) | |
101 | ||
102 | it('Should create a permanent live', async function () { | |
103 | this.timeout(20000) | |
104 | ||
105 | videoUUID = await createLiveWrapper(true) | |
106 | ||
107 | const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) | |
108 | expect(res.body.permanentLive).to.be.true | |
109 | ||
110 | await waitJobs(servers) | |
111 | }) | |
112 | ||
113 | it('Should stream into this permanent live', async function () { | |
114 | this.timeout(40000) | |
115 | ||
116 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID) | |
117 | ||
118 | for (const server of servers) { | |
119 | await waitUntilLiveStarts(server.url, server.accessToken, videoUUID) | |
120 | } | |
121 | ||
122 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
123 | ||
124 | await stopFfmpeg(command) | |
125 | ||
126 | await waitJobs(servers) | |
127 | }) | |
128 | ||
129 | it('Should not have cleaned up this live', async function () { | |
130 | this.timeout(40000) | |
131 | ||
132 | await wait(5000) | |
133 | await waitJobs(servers) | |
134 | ||
135 | for (const server of servers) { | |
136 | const res = await getVideo(server.url, videoUUID) | |
137 | ||
138 | const videoDetails = res.body as VideoDetails | |
139 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) | |
140 | } | |
141 | }) | |
142 | ||
143 | it('Should have set this live to waiting for live state', async function () { | |
144 | this.timeout(20000) | |
145 | ||
146 | await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE) | |
147 | }) | |
148 | ||
149 | it('Should be able to stream again in the permanent live', async function () { | |
150 | this.timeout(20000) | |
151 | ||
152 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
153 | live: { | |
154 | enabled: true, | |
155 | allowReplay: true, | |
156 | maxDuration: null, | |
157 | transcoding: { | |
158 | enabled: true, | |
159 | resolutions: { | |
160 | '240p': false, | |
161 | '360p': false, | |
162 | '480p': false, | |
163 | '720p': false, | |
164 | '1080p': false, | |
165 | '2160p': false | |
166 | } | |
167 | } | |
168 | } | |
169 | }) | |
170 | ||
171 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID) | |
172 | ||
173 | for (const server of servers) { | |
174 | await waitUntilLiveStarts(server.url, server.accessToken, videoUUID) | |
175 | } | |
176 | ||
177 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
178 | ||
179 | const count = await getPlaylistsCount(servers[0], videoUUID) | |
180 | // master playlist and 720p playlist | |
181 | expect(count).to.equal(2) | |
182 | ||
183 | await stopFfmpeg(command) | |
184 | }) | |
185 | ||
186 | after(async function () { | |
187 | await cleanupTests(servers) | |
188 | }) | |
189 | }) |