]>
Commit | Line | Data |
---|---|---|
af4ae64f C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5c0904fc | 5 | import { FfmpegCommand } from 'fluent-ffmpeg' |
ca5c612b C |
6 | import { join } from 'path' |
7 | import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' | |
bd54ad19 | 8 | import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io' |
053aed43 | 9 | import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' |
0d8de275 | 10 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
af4ae64f | 11 | import { |
68e70a74 | 12 | addVideoToBlacklist, |
ca5c612b | 13 | buildServerDirectory, |
bd54ad19 | 14 | checkLiveCleanup, |
5c0904fc | 15 | checkLiveSegmentHash, |
bd54ad19 | 16 | checkResolutionsInMasterPlaylist, |
af4ae64f C |
17 | cleanupTests, |
18 | createLive, | |
19 | doubleFollow, | |
20 | flushAndRunMultipleServers, | |
21 | getLive, | |
1fd61899 | 22 | getMyVideosWithFilter, |
5c0904fc | 23 | getPlaylist, |
af4ae64f | 24 | getVideo, |
bd54ad19 | 25 | getVideoIdFromUUID, |
af4ae64f | 26 | getVideosList, |
1fd61899 | 27 | getVideosWithFilters, |
5c0904fc | 28 | killallServers, |
af4ae64f C |
29 | makeRawRequest, |
30 | removeVideo, | |
5c0904fc | 31 | reRunServer, |
68e70a74 | 32 | sendRTMPStream, |
bd54ad19 | 33 | sendRTMPStreamInVideo, |
af4ae64f C |
34 | ServerInfo, |
35 | setAccessTokensToServers, | |
36 | setDefaultVideoChannel, | |
bd54ad19 | 37 | stopFfmpeg, |
97969c4e | 38 | testFfmpegStreamError, |
af4ae64f C |
39 | testImage, |
40 | updateCustomSubConfig, | |
41 | updateLive, | |
1fd61899 | 42 | uploadVideoAndGetId, |
e4bf7856 C |
43 | viewVideo, |
44 | wait, | |
bd54ad19 | 45 | waitJobs, |
0e856b78 | 46 | waitUntilLiveEnded, |
6b67897e | 47 | waitUntilLivePublished, |
5cac83a7 | 48 | waitUntilLiveSegmentGeneration |
af4ae64f C |
49 | } from '../../../../shared/extra-utils' |
50 | ||
51 | const expect = chai.expect | |
52 | ||
53 | describe('Test live', function () { | |
54 | let servers: ServerInfo[] = [] | |
af4ae64f | 55 | |
fae6e4da C |
56 | async function waitUntilLivePublishedOnAllServers (videoId: string) { |
57 | for (const server of servers) { | |
58 | await waitUntilLivePublished(server.url, server.accessToken, videoId) | |
59 | } | |
60 | } | |
61 | ||
af4ae64f C |
62 | before(async function () { |
63 | this.timeout(120000) | |
64 | ||
65 | servers = await flushAndRunMultipleServers(2) | |
66 | ||
67 | // Get the access tokens | |
68 | await setAccessTokensToServers(servers) | |
69 | await setDefaultVideoChannel(servers) | |
70 | ||
71 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
72 | live: { | |
73 | enabled: true, | |
68e70a74 C |
74 | allowReplay: true, |
75 | transcoding: { | |
76 | enabled: false | |
77 | } | |
af4ae64f C |
78 | } |
79 | }) | |
80 | ||
81 | // Server 1 and server 2 follow each other | |
82 | await doubleFollow(servers[0], servers[1]) | |
83 | }) | |
84 | ||
85 | describe('Live creation, update and delete', function () { | |
68e70a74 | 86 | let liveVideoUUID: string |
af4ae64f C |
87 | |
88 | it('Should create a live with the appropriate parameters', async function () { | |
89 | this.timeout(20000) | |
90 | ||
91 | const attributes: LiveVideoCreate = { | |
92 | category: 1, | |
93 | licence: 2, | |
94 | language: 'fr', | |
95 | description: 'super live description', | |
96 | support: 'support field', | |
97 | channelId: servers[0].videoChannel.id, | |
98 | nsfw: false, | |
99 | waitTranscoding: false, | |
100 | name: 'my super live', | |
101 | tags: [ 'tag1', 'tag2' ], | |
102 | commentsEnabled: false, | |
103 | downloadEnabled: false, | |
104 | saveReplay: true, | |
105 | privacy: VideoPrivacy.PUBLIC, | |
106 | previewfile: 'video_short1-preview.webm.jpg', | |
107 | thumbnailfile: 'video_short1.webm.jpg' | |
108 | } | |
109 | ||
110 | const res = await createLive(servers[0].url, servers[0].accessToken, attributes) | |
111 | liveVideoUUID = res.body.video.uuid | |
112 | ||
113 | await waitJobs(servers) | |
114 | ||
115 | for (const server of servers) { | |
116 | const resVideo = await getVideo(server.url, liveVideoUUID) | |
117 | const video: VideoDetails = resVideo.body | |
118 | ||
119 | expect(video.category.id).to.equal(1) | |
120 | expect(video.licence.id).to.equal(2) | |
121 | expect(video.language.id).to.equal('fr') | |
122 | expect(video.description).to.equal('super live description') | |
123 | expect(video.support).to.equal('support field') | |
124 | ||
125 | expect(video.channel.name).to.equal(servers[0].videoChannel.name) | |
126 | expect(video.channel.host).to.equal(servers[0].videoChannel.host) | |
127 | ||
1ab60243 C |
128 | expect(video.isLive).to.be.true |
129 | ||
af4ae64f C |
130 | expect(video.nsfw).to.be.false |
131 | expect(video.waitTranscoding).to.be.false | |
132 | expect(video.name).to.equal('my super live') | |
133 | expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ]) | |
134 | expect(video.commentsEnabled).to.be.false | |
135 | expect(video.downloadEnabled).to.be.false | |
136 | expect(video.privacy.id).to.equal(VideoPrivacy.PUBLIC) | |
137 | ||
138 | await testImage(server.url, 'video_short1-preview.webm', video.previewPath) | |
139 | await testImage(server.url, 'video_short1.webm', video.thumbnailPath) | |
140 | ||
141 | const resLive = await getLive(server.url, server.accessToken, liveVideoUUID) | |
142 | const live: LiveVideo = resLive.body | |
143 | ||
144 | if (server.url === servers[0].url) { | |
c655c9ef | 145 | expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') |
af4ae64f C |
146 | expect(live.streamKey).to.not.be.empty |
147 | } else { | |
148 | expect(live.rtmpUrl).to.be.null | |
149 | expect(live.streamKey).to.be.null | |
150 | } | |
151 | ||
152 | expect(live.saveReplay).to.be.true | |
153 | } | |
154 | }) | |
155 | ||
156 | it('Should have a default preview and thumbnail', async function () { | |
157 | this.timeout(20000) | |
158 | ||
159 | const attributes: LiveVideoCreate = { | |
160 | name: 'default live thumbnail', | |
161 | channelId: servers[0].videoChannel.id, | |
162 | privacy: VideoPrivacy.UNLISTED, | |
163 | nsfw: true | |
164 | } | |
165 | ||
166 | const res = await createLive(servers[0].url, servers[0].accessToken, attributes) | |
167 | const videoId = res.body.video.uuid | |
168 | ||
169 | await waitJobs(servers) | |
170 | ||
171 | for (const server of servers) { | |
172 | const resVideo = await getVideo(server.url, videoId) | |
173 | const video: VideoDetails = resVideo.body | |
174 | ||
175 | expect(video.privacy.id).to.equal(VideoPrivacy.UNLISTED) | |
176 | expect(video.nsfw).to.be.true | |
177 | ||
f2eb23cd RK |
178 | await makeRawRequest(server.url + video.thumbnailPath, HttpStatusCode.OK_200) |
179 | await makeRawRequest(server.url + video.previewPath, HttpStatusCode.OK_200) | |
af4ae64f C |
180 | } |
181 | }) | |
182 | ||
183 | it('Should not have the live listed since nobody streams into', async function () { | |
184 | for (const server of servers) { | |
185 | const res = await getVideosList(server.url) | |
186 | ||
187 | expect(res.body.total).to.equal(0) | |
188 | expect(res.body.data).to.have.lengthOf(0) | |
189 | } | |
190 | }) | |
191 | ||
192 | it('Should not be able to update a live of another server', async function () { | |
f2eb23cd | 193 | await updateLive(servers[1].url, servers[1].accessToken, liveVideoUUID, { saveReplay: false }, HttpStatusCode.FORBIDDEN_403) |
af4ae64f C |
194 | }) |
195 | ||
196 | it('Should update the live', async function () { | |
197 | this.timeout(10000) | |
198 | ||
199 | await updateLive(servers[0].url, servers[0].accessToken, liveVideoUUID, { saveReplay: false }) | |
200 | await waitJobs(servers) | |
201 | }) | |
202 | ||
203 | it('Have the live updated', async function () { | |
204 | for (const server of servers) { | |
205 | const res = await getLive(server.url, server.accessToken, liveVideoUUID) | |
206 | const live: LiveVideo = res.body | |
207 | ||
208 | if (server.url === servers[0].url) { | |
c655c9ef | 209 | expect(live.rtmpUrl).to.equal('rtmp://' + server.hostname + ':' + servers[0].rtmpPort + '/live') |
af4ae64f C |
210 | expect(live.streamKey).to.not.be.empty |
211 | } else { | |
212 | expect(live.rtmpUrl).to.be.null | |
213 | expect(live.streamKey).to.be.null | |
214 | } | |
215 | ||
216 | expect(live.saveReplay).to.be.false | |
217 | } | |
218 | }) | |
219 | ||
220 | it('Delete the live', async function () { | |
221 | this.timeout(10000) | |
222 | ||
223 | await removeVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
224 | await waitJobs(servers) | |
225 | }) | |
226 | ||
227 | it('Should have the live deleted', async function () { | |
228 | for (const server of servers) { | |
f2eb23cd RK |
229 | await getVideo(server.url, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) |
230 | await getLive(server.url, server.accessToken, liveVideoUUID, HttpStatusCode.NOT_FOUND_404) | |
af4ae64f C |
231 | } |
232 | }) | |
233 | }) | |
234 | ||
1fd61899 C |
235 | describe('Live filters', function () { |
236 | let command: any | |
237 | let liveVideoId: string | |
238 | let vodVideoId: string | |
239 | ||
240 | before(async function () { | |
241 | this.timeout(120000) | |
242 | ||
243 | vodVideoId = (await uploadVideoAndGetId({ server: servers[0], videoName: 'vod video' })).uuid | |
244 | ||
245 | const liveOptions = { name: 'live', privacy: VideoPrivacy.PUBLIC, channelId: servers[0].videoChannel.id } | |
246 | const resLive = await createLive(servers[0].url, servers[0].accessToken, liveOptions) | |
247 | liveVideoId = resLive.body.video.uuid | |
248 | ||
249 | command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) | |
250 | await waitUntilLivePublishedOnAllServers(liveVideoId) | |
251 | await waitJobs(servers) | |
252 | }) | |
253 | ||
254 | it('Should only display lives', async function () { | |
255 | const res = await getVideosWithFilters(servers[0].url, { isLive: true }) | |
256 | ||
257 | expect(res.body.total).to.equal(1) | |
258 | expect(res.body.data).to.have.lengthOf(1) | |
259 | expect(res.body.data[0].name).to.equal('live') | |
260 | }) | |
261 | ||
262 | it('Should not display lives', async function () { | |
263 | const res = await getVideosWithFilters(servers[0].url, { isLive: false }) | |
264 | ||
265 | expect(res.body.total).to.equal(1) | |
266 | expect(res.body.data).to.have.lengthOf(1) | |
267 | expect(res.body.data[0].name).to.equal('vod video') | |
268 | }) | |
269 | ||
270 | it('Should display my lives', async function () { | |
271 | this.timeout(60000) | |
272 | ||
273 | await stopFfmpeg(command) | |
274 | await waitJobs(servers) | |
275 | ||
276 | const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: true }) | |
277 | const videos = res.body.data as Video[] | |
278 | ||
279 | const result = videos.every(v => v.isLive) | |
280 | expect(result).to.be.true | |
281 | }) | |
282 | ||
283 | it('Should not display my lives', async function () { | |
284 | const res = await getMyVideosWithFilter(servers[0].url, servers[0].accessToken, { isLive: false }) | |
285 | const videos = res.body.data as Video[] | |
286 | ||
287 | const result = videos.every(v => !v.isLive) | |
288 | expect(result).to.be.true | |
289 | }) | |
290 | ||
291 | after(async function () { | |
292 | await removeVideo(servers[0].url, servers[0].accessToken, vodVideoId) | |
293 | await removeVideo(servers[0].url, servers[0].accessToken, liveVideoId) | |
294 | }) | |
295 | }) | |
296 | ||
68e70a74 C |
297 | describe('Stream checks', function () { |
298 | let liveVideo: LiveVideo & VideoDetails | |
299 | let rtmpUrl: string | |
300 | ||
301 | before(function () { | |
c655c9ef | 302 | rtmpUrl = 'rtmp://' + servers[0].hostname + ':' + servers[0].rtmpPort + '' |
68e70a74 | 303 | }) |
af4ae64f | 304 | |
68e70a74 | 305 | async function createLiveWrapper () { |
97969c4e C |
306 | const liveAttributes = { |
307 | name: 'user live', | |
bd54ad19 | 308 | channelId: servers[0].videoChannel.id, |
97969c4e | 309 | privacy: VideoPrivacy.PUBLIC, |
68e70a74 | 310 | saveReplay: false |
97969c4e C |
311 | } |
312 | ||
bd54ad19 | 313 | const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) |
68e70a74 | 314 | const uuid = res.body.video.uuid |
97969c4e | 315 | |
68e70a74 C |
316 | const resLive = await getLive(servers[0].url, servers[0].accessToken, uuid) |
317 | const resVideo = await getVideo(servers[0].url, uuid) | |
97969c4e | 318 | |
68e70a74 C |
319 | return Object.assign(resVideo.body, resLive.body) as LiveVideo & VideoDetails |
320 | } | |
97969c4e | 321 | |
68e70a74 | 322 | it('Should not allow a stream without the appropriate path', async function () { |
2df6f943 | 323 | this.timeout(60000) |
97969c4e | 324 | |
68e70a74 | 325 | liveVideo = await createLiveWrapper() |
97969c4e | 326 | |
68e70a74 C |
327 | const command = sendRTMPStream(rtmpUrl + '/bad-live', liveVideo.streamKey) |
328 | await testFfmpegStreamError(command, true) | |
af4ae64f C |
329 | }) |
330 | ||
68e70a74 | 331 | it('Should not allow a stream without the appropriate stream key', async function () { |
2df6f943 | 332 | this.timeout(60000) |
97969c4e | 333 | |
68e70a74 C |
334 | const command = sendRTMPStream(rtmpUrl + '/live', 'bad-stream-key') |
335 | await testFfmpegStreamError(command, true) | |
97969c4e C |
336 | }) |
337 | ||
68e70a74 | 338 | it('Should succeed with the correct params', async function () { |
2df6f943 | 339 | this.timeout(60000) |
97969c4e | 340 | |
68e70a74 C |
341 | const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) |
342 | await testFfmpegStreamError(command, false) | |
af4ae64f C |
343 | }) |
344 | ||
1ab60243 C |
345 | it('Should list this live now someone stream into it', async function () { |
346 | for (const server of servers) { | |
347 | const res = await getVideosList(server.url) | |
348 | ||
349 | expect(res.body.total).to.equal(1) | |
350 | expect(res.body.data).to.have.lengthOf(1) | |
351 | ||
352 | const video: Video = res.body.data[0] | |
353 | ||
354 | expect(video.name).to.equal('user live') | |
355 | expect(video.isLive).to.be.true | |
356 | } | |
357 | }) | |
358 | ||
68e70a74 | 359 | it('Should not allow a stream on a live that was blacklisted', async function () { |
2df6f943 | 360 | this.timeout(60000) |
97969c4e | 361 | |
68e70a74 | 362 | liveVideo = await createLiveWrapper() |
af4ae64f | 363 | |
68e70a74 | 364 | await addVideoToBlacklist(servers[0].url, servers[0].accessToken, liveVideo.uuid) |
af4ae64f | 365 | |
68e70a74 C |
366 | const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) |
367 | await testFfmpegStreamError(command, true) | |
af4ae64f C |
368 | }) |
369 | ||
68e70a74 | 370 | it('Should not allow a stream on a live that was deleted', async function () { |
2df6f943 | 371 | this.timeout(60000) |
af4ae64f | 372 | |
68e70a74 | 373 | liveVideo = await createLiveWrapper() |
af4ae64f | 374 | |
68e70a74 | 375 | await removeVideo(servers[0].url, servers[0].accessToken, liveVideo.uuid) |
af4ae64f | 376 | |
68e70a74 C |
377 | const command = sendRTMPStream(rtmpUrl + '/live', liveVideo.streamKey) |
378 | await testFfmpegStreamError(command, true) | |
af4ae64f C |
379 | }) |
380 | }) | |
381 | ||
382 | describe('Live transcoding', function () { | |
bd54ad19 C |
383 | let liveVideoId: string |
384 | ||
385 | async function createLiveWrapper (saveReplay: boolean) { | |
386 | const liveAttributes = { | |
387 | name: 'live video', | |
388 | channelId: servers[0].videoChannel.id, | |
389 | privacy: VideoPrivacy.PUBLIC, | |
390 | saveReplay | |
391 | } | |
392 | ||
393 | const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) | |
394 | return res.body.video.uuid | |
395 | } | |
396 | ||
397 | async function testVideoResolutions (liveVideoId: string, resolutions: number[]) { | |
398 | for (const server of servers) { | |
399 | const resList = await getVideosList(server.url) | |
400 | const videos: Video[] = resList.body.data | |
401 | ||
402 | expect(videos.find(v => v.uuid === liveVideoId)).to.exist | |
403 | ||
404 | const resVideo = await getVideo(server.url, liveVideoId) | |
405 | const video: VideoDetails = resVideo.body | |
406 | ||
407 | expect(video.streamingPlaylists).to.have.lengthOf(1) | |
408 | ||
409 | const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) | |
410 | expect(hlsPlaylist).to.exist | |
411 | ||
412 | // Only finite files are displayed | |
413 | expect(hlsPlaylist.files).to.have.lengthOf(0) | |
414 | ||
415 | await checkResolutionsInMasterPlaylist(hlsPlaylist.playlistUrl, resolutions) | |
5c0904fc C |
416 | |
417 | for (let i = 0; i < resolutions.length; i++) { | |
a800dbf3 | 418 | const segmentNum = 3 |
0d8de275 C |
419 | const segmentName = `${i}-00000${segmentNum}.ts` |
420 | await waitUntilLiveSegmentGeneration(servers[0], video.uuid, i, segmentNum) | |
5c0904fc C |
421 | |
422 | const res = await getPlaylist(`${servers[0].url}/static/streaming-playlists/hls/${video.uuid}/${i}.m3u8`) | |
423 | const subPlaylist = res.text | |
424 | ||
425 | expect(subPlaylist).to.contain(segmentName) | |
426 | ||
427 | const baseUrlAndPath = servers[0].url + '/static/streaming-playlists/hls' | |
428 | await checkLiveSegmentHash(baseUrlAndPath, video.uuid, segmentName, hlsPlaylist) | |
429 | } | |
bd54ad19 C |
430 | } |
431 | } | |
432 | ||
433 | function updateConf (resolutions: number[]) { | |
434 | return updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
435 | live: { | |
436 | enabled: true, | |
437 | allowReplay: true, | |
c9bc850e | 438 | maxDuration: -1, |
bd54ad19 C |
439 | transcoding: { |
440 | enabled: true, | |
441 | resolutions: { | |
442 | '240p': resolutions.includes(240), | |
443 | '360p': resolutions.includes(360), | |
444 | '480p': resolutions.includes(480), | |
445 | '720p': resolutions.includes(720), | |
446 | '1080p': resolutions.includes(1080), | |
447 | '2160p': resolutions.includes(2160) | |
448 | } | |
449 | } | |
450 | } | |
451 | }) | |
452 | } | |
453 | ||
454 | before(async function () { | |
455 | await updateConf([]) | |
456 | }) | |
af4ae64f C |
457 | |
458 | it('Should enable transcoding without additional resolutions', async function () { | |
dbb15e37 | 459 | this.timeout(60000) |
bd54ad19 C |
460 | |
461 | liveVideoId = await createLiveWrapper(false) | |
462 | ||
463 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) | |
fae6e4da | 464 | await waitUntilLivePublishedOnAllServers(liveVideoId) |
bd54ad19 | 465 | await waitJobs(servers) |
af4ae64f | 466 | |
bd54ad19 C |
467 | await testVideoResolutions(liveVideoId, [ 720 ]) |
468 | ||
469 | await stopFfmpeg(command) | |
af4ae64f C |
470 | }) |
471 | ||
472 | it('Should enable transcoding with some resolutions', async function () { | |
dbb15e37 | 473 | this.timeout(60000) |
bd54ad19 C |
474 | |
475 | const resolutions = [ 240, 480 ] | |
476 | await updateConf(resolutions) | |
477 | liveVideoId = await createLiveWrapper(false) | |
478 | ||
479 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) | |
fae6e4da | 480 | await waitUntilLivePublishedOnAllServers(liveVideoId) |
bd54ad19 C |
481 | await waitJobs(servers) |
482 | ||
483 | await testVideoResolutions(liveVideoId, resolutions) | |
484 | ||
485 | await stopFfmpeg(command) | |
af4ae64f C |
486 | }) |
487 | ||
488 | it('Should enable transcoding with some resolutions and correctly save them', async function () { | |
f42c2152 | 489 | this.timeout(200000) |
bd54ad19 C |
490 | |
491 | const resolutions = [ 240, 360, 720 ] | |
ca5c612b | 492 | |
bd54ad19 C |
493 | await updateConf(resolutions) |
494 | liveVideoId = await createLiveWrapper(true) | |
495 | ||
ca5c612b | 496 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId, 'video_short2.webm') |
fae6e4da | 497 | await waitUntilLivePublishedOnAllServers(liveVideoId) |
bd54ad19 C |
498 | await waitJobs(servers) |
499 | ||
500 | await testVideoResolutions(liveVideoId, resolutions) | |
501 | ||
502 | await stopFfmpeg(command) | |
34caef7f C |
503 | await waitUntilLiveEnded(servers[0].url, servers[0].accessToken, liveVideoId) |
504 | ||
bd54ad19 C |
505 | await waitJobs(servers) |
506 | ||
fae6e4da | 507 | await waitUntilLivePublishedOnAllServers(liveVideoId) |
e0783718 | 508 | |
ca5c612b | 509 | const bitrateLimits = { |
4ef9ea48 | 510 | 720: 5000 * 1000, // 60FPS |
6b67897e C |
511 | 360: 1100 * 1000, |
512 | 240: 600 * 1000 | |
ca5c612b C |
513 | } |
514 | ||
bd54ad19 C |
515 | for (const server of servers) { |
516 | const resVideo = await getVideo(server.url, liveVideoId) | |
517 | const video: VideoDetails = resVideo.body | |
518 | ||
e0783718 | 519 | expect(video.state.id).to.equal(VideoState.PUBLISHED) |
bd54ad19 C |
520 | expect(video.duration).to.be.greaterThan(1) |
521 | expect(video.files).to.have.lengthOf(0) | |
522 | ||
523 | const hlsPlaylist = video.streamingPlaylists.find(s => s.type === VideoStreamingPlaylistType.HLS) | |
f2eb23cd RK |
524 | await makeRawRequest(hlsPlaylist.playlistUrl, HttpStatusCode.OK_200) |
525 | await makeRawRequest(hlsPlaylist.segmentsSha256Url, HttpStatusCode.OK_200) | |
bd54ad19 C |
526 | |
527 | expect(hlsPlaylist.files).to.have.lengthOf(resolutions.length) | |
528 | ||
529 | for (const resolution of resolutions) { | |
530 | const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) | |
531 | ||
532 | expect(file).to.exist | |
bd54ad19 C |
533 | expect(file.size).to.be.greaterThan(1) |
534 | ||
884d2c39 C |
535 | if (resolution >= 720) { |
536 | expect(file.fps).to.be.approximately(60, 2) | |
537 | } else { | |
538 | expect(file.fps).to.be.approximately(30, 2) | |
539 | } | |
540 | ||
ca5c612b C |
541 | const filename = `${video.uuid}-${resolution}-fragmented.mp4` |
542 | const segmentPath = buildServerDirectory(servers[0], join('streaming-playlists', 'hls', video.uuid, filename)) | |
543 | ||
544 | const probe = await ffprobePromise(segmentPath) | |
545 | const videoStream = await getVideoStreamFromFile(segmentPath, probe) | |
6b67897e | 546 | |
ca5c612b C |
547 | expect(probe.format.bit_rate).to.be.below(bitrateLimits[videoStream.height]) |
548 | ||
f2eb23cd RK |
549 | await makeRawRequest(file.torrentUrl, HttpStatusCode.OK_200) |
550 | await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200) | |
bd54ad19 C |
551 | } |
552 | } | |
af4ae64f C |
553 | }) |
554 | ||
555 | it('Should correctly have cleaned up the live files', async function () { | |
bd54ad19 C |
556 | this.timeout(30000) |
557 | ||
558 | await checkLiveCleanup(servers[0], liveVideoId, [ 240, 360, 720 ]) | |
af4ae64f C |
559 | }) |
560 | }) | |
561 | ||
e4bf7856 C |
562 | describe('Live views', function () { |
563 | let liveVideoId: string | |
564 | let command: FfmpegCommand | |
565 | ||
566 | async function countViews (expected: number) { | |
567 | for (const server of servers) { | |
568 | const res = await getVideo(server.url, liveVideoId) | |
569 | const video: VideoDetails = res.body | |
570 | ||
571 | expect(video.views).to.equal(expected) | |
572 | } | |
573 | } | |
574 | ||
575 | before(async function () { | |
576 | this.timeout(30000) | |
577 | ||
578 | const liveAttributes = { | |
579 | name: 'live video', | |
580 | channelId: servers[0].videoChannel.id, | |
581 | privacy: VideoPrivacy.PUBLIC | |
582 | } | |
583 | ||
584 | const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) | |
585 | liveVideoId = res.body.video.uuid | |
586 | ||
587 | command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) | |
fae6e4da | 588 | await waitUntilLivePublishedOnAllServers(liveVideoId) |
e4bf7856 C |
589 | await waitJobs(servers) |
590 | }) | |
591 | ||
592 | it('Should display no views for a live', async function () { | |
593 | await countViews(0) | |
594 | }) | |
595 | ||
596 | it('Should view a live twice and display 1 view', async function () { | |
597 | this.timeout(30000) | |
598 | ||
599 | await viewVideo(servers[0].url, liveVideoId) | |
600 | await viewVideo(servers[0].url, liveVideoId) | |
601 | ||
2a9562fc | 602 | await wait(7000) |
e4bf7856 C |
603 | |
604 | await waitJobs(servers) | |
605 | ||
606 | await countViews(1) | |
607 | }) | |
608 | ||
2a9562fc | 609 | it('Should wait and display 0 views', async function () { |
e4bf7856 C |
610 | this.timeout(30000) |
611 | ||
2a9562fc | 612 | await wait(7000) |
e4bf7856 C |
613 | await waitJobs(servers) |
614 | ||
615 | await countViews(0) | |
616 | }) | |
617 | ||
618 | it('Should view a live on a remote and on local and display 2 views', async function () { | |
619 | this.timeout(30000) | |
620 | ||
621 | await viewVideo(servers[0].url, liveVideoId) | |
622 | await viewVideo(servers[1].url, liveVideoId) | |
623 | await viewVideo(servers[1].url, liveVideoId) | |
624 | ||
2a9562fc | 625 | await wait(7000) |
e4bf7856 C |
626 | await waitJobs(servers) |
627 | ||
628 | await countViews(2) | |
629 | }) | |
630 | ||
631 | after(async function () { | |
632 | await stopFfmpeg(command) | |
633 | }) | |
634 | }) | |
635 | ||
af4ae64f C |
636 | describe('Live socket messages', function () { |
637 | ||
bd54ad19 C |
638 | async function createLiveWrapper () { |
639 | const liveAttributes = { | |
640 | name: 'live video', | |
641 | channelId: servers[0].videoChannel.id, | |
642 | privacy: VideoPrivacy.PUBLIC | |
643 | } | |
644 | ||
645 | const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) | |
646 | return res.body.video.uuid | |
647 | } | |
648 | ||
649 | it('Should correctly send a message when the live starts and ends', async function () { | |
650 | this.timeout(60000) | |
651 | ||
652 | const localStateChanges: VideoState[] = [] | |
653 | const remoteStateChanges: VideoState[] = [] | |
654 | ||
655 | const liveVideoUUID = await createLiveWrapper() | |
656 | await waitJobs(servers) | |
657 | ||
658 | { | |
659 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) | |
660 | ||
661 | const localSocket = getLiveNotificationSocket(servers[0].url) | |
662 | localSocket.on('state-change', data => localStateChanges.push(data.state)) | |
663 | localSocket.emit('subscribe', { videoId }) | |
664 | } | |
665 | ||
666 | { | |
667 | const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) | |
668 | ||
669 | const remoteSocket = getLiveNotificationSocket(servers[1].url) | |
670 | remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) | |
671 | remoteSocket.emit('subscribe', { videoId }) | |
672 | } | |
673 | ||
674 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
0484ec9e | 675 | |
fae6e4da | 676 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) |
bd54ad19 C |
677 | await waitJobs(servers) |
678 | ||
679 | for (const stateChanges of [ localStateChanges, remoteStateChanges ]) { | |
e5a516e7 C |
680 | expect(stateChanges).to.have.length.at.least(1) |
681 | expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.PUBLISHED) | |
bd54ad19 C |
682 | } |
683 | ||
684 | await stopFfmpeg(command) | |
0484ec9e C |
685 | |
686 | for (const server of servers) { | |
687 | await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID) | |
688 | } | |
bd54ad19 C |
689 | await waitJobs(servers) |
690 | ||
691 | for (const stateChanges of [ localStateChanges, remoteStateChanges ]) { | |
e5a516e7 C |
692 | expect(stateChanges).to.have.length.at.least(2) |
693 | expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.LIVE_ENDED) | |
bd54ad19 | 694 | } |
af4ae64f C |
695 | }) |
696 | ||
a800dbf3 C |
697 | it('Should correctly send views change notification', async function () { |
698 | this.timeout(60000) | |
699 | ||
700 | let localLastVideoViews = 0 | |
701 | let remoteLastVideoViews = 0 | |
702 | ||
703 | const liveVideoUUID = await createLiveWrapper() | |
704 | await waitJobs(servers) | |
705 | ||
706 | { | |
707 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) | |
708 | ||
709 | const localSocket = getLiveNotificationSocket(servers[0].url) | |
710 | localSocket.on('views-change', data => { localLastVideoViews = data.views }) | |
711 | localSocket.emit('subscribe', { videoId }) | |
712 | } | |
713 | ||
714 | { | |
715 | const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) | |
716 | ||
717 | const remoteSocket = getLiveNotificationSocket(servers[1].url) | |
718 | remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) | |
719 | remoteSocket.emit('subscribe', { videoId }) | |
720 | } | |
721 | ||
722 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
723 | ||
fae6e4da | 724 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) |
a800dbf3 C |
725 | await waitJobs(servers) |
726 | ||
727 | expect(localLastVideoViews).to.equal(0) | |
728 | expect(remoteLastVideoViews).to.equal(0) | |
729 | ||
730 | await viewVideo(servers[0].url, liveVideoUUID) | |
731 | await viewVideo(servers[1].url, liveVideoUUID) | |
732 | ||
733 | await waitJobs(servers) | |
734 | await wait(5000) | |
735 | await waitJobs(servers) | |
736 | ||
737 | expect(localLastVideoViews).to.equal(2) | |
738 | expect(remoteLastVideoViews).to.equal(2) | |
739 | ||
740 | await stopFfmpeg(command) | |
741 | }) | |
742 | ||
bd54ad19 C |
743 | it('Should not receive a notification after unsubscribe', async function () { |
744 | this.timeout(60000) | |
745 | ||
746 | const stateChanges: VideoState[] = [] | |
747 | ||
748 | const liveVideoUUID = await createLiveWrapper() | |
749 | await waitJobs(servers) | |
750 | ||
751 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) | |
752 | ||
753 | const socket = getLiveNotificationSocket(servers[0].url) | |
754 | socket.on('state-change', data => stateChanges.push(data.state)) | |
755 | socket.emit('subscribe', { videoId }) | |
756 | ||
757 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoUUID) | |
fae6e4da C |
758 | |
759 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | |
bd54ad19 C |
760 | await waitJobs(servers) |
761 | ||
762 | expect(stateChanges).to.have.lengthOf(1) | |
763 | socket.emit('unsubscribe', { videoId }) | |
764 | ||
765 | await stopFfmpeg(command) | |
766 | await waitJobs(servers) | |
767 | ||
768 | expect(stateChanges).to.have.lengthOf(1) | |
af4ae64f C |
769 | }) |
770 | }) | |
771 | ||
5c0904fc C |
772 | describe('After a server restart', function () { |
773 | let liveVideoId: string | |
774 | let liveVideoReplayId: string | |
775 | ||
776 | async function createLiveWrapper (saveReplay: boolean) { | |
777 | const liveAttributes = { | |
778 | name: 'live video', | |
779 | channelId: servers[0].videoChannel.id, | |
780 | privacy: VideoPrivacy.PUBLIC, | |
781 | saveReplay | |
782 | } | |
783 | ||
784 | const res = await createLive(servers[0].url, servers[0].accessToken, liveAttributes) | |
785 | return res.body.video.uuid | |
786 | } | |
787 | ||
788 | before(async function () { | |
0d8de275 | 789 | this.timeout(120000) |
5c0904fc C |
790 | |
791 | liveVideoId = await createLiveWrapper(false) | |
792 | liveVideoReplayId = await createLiveWrapper(true) | |
793 | ||
794 | await Promise.all([ | |
795 | sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId), | |
796 | sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoReplayId) | |
797 | ]) | |
798 | ||
799 | await Promise.all([ | |
0d8de275 C |
800 | waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoId), |
801 | waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoReplayId) | |
5c0904fc C |
802 | ]) |
803 | ||
0d8de275 C |
804 | await waitUntilLiveSegmentGeneration(servers[0], liveVideoId, 0, 2) |
805 | await waitUntilLiveSegmentGeneration(servers[0], liveVideoReplayId, 0, 2) | |
806 | ||
5c0904fc C |
807 | await killallServers([ servers[0] ]) |
808 | await reRunServer(servers[0]) | |
809 | ||
810 | await wait(5000) | |
811 | }) | |
812 | ||
813 | it('Should cleanup lives', async function () { | |
814 | this.timeout(60000) | |
815 | ||
0d8de275 | 816 | await waitUntilLiveEnded(servers[0].url, servers[0].accessToken, liveVideoId) |
5c0904fc C |
817 | }) |
818 | ||
819 | it('Should save a live replay', async function () { | |
0d8de275 | 820 | this.timeout(120000) |
5c0904fc | 821 | |
b49f22d8 | 822 | await waitUntilLivePublished(servers[0].url, servers[0].accessToken, liveVideoReplayId) |
5c0904fc C |
823 | }) |
824 | }) | |
825 | ||
af4ae64f C |
826 | after(async function () { |
827 | await cleanupTests(servers) | |
828 | }) | |
829 | }) |