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