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