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