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