diff options
Diffstat (limited to 'server/tests/api/live/live.ts')
-rw-r--r-- | server/tests/api/live/live.ts | 231 |
1 files changed, 6 insertions, 225 deletions
diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 57fb58150..50397924e 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts | |||
@@ -2,10 +2,8 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { FfmpegCommand } from 'fluent-ffmpeg' | ||
6 | import { join } from 'path' | 5 | import { join } from 'path' |
7 | import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' | 6 | import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' |
8 | import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io' | ||
9 | import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' | 7 | import { LiveVideo, LiveVideoCreate, Video, VideoDetails, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' |
10 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 8 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
11 | import { | 9 | import { |
@@ -22,7 +20,6 @@ import { | |||
22 | getMyVideosWithFilter, | 20 | getMyVideosWithFilter, |
23 | getPlaylist, | 21 | getPlaylist, |
24 | getVideo, | 22 | getVideo, |
25 | getVideoIdFromUUID, | ||
26 | getVideosList, | 23 | getVideosList, |
27 | getVideosWithFilters, | 24 | getVideosWithFilters, |
28 | killallServers, | 25 | killallServers, |
@@ -40,11 +37,11 @@ import { | |||
40 | updateCustomSubConfig, | 37 | updateCustomSubConfig, |
41 | updateLive, | 38 | updateLive, |
42 | uploadVideoAndGetId, | 39 | uploadVideoAndGetId, |
43 | viewVideo, | ||
44 | wait, | 40 | wait, |
45 | waitJobs, | 41 | waitJobs, |
46 | waitUntilLiveEnded, | 42 | waitUntilLiveEnded, |
47 | waitUntilLivePublished, | 43 | waitUntilLivePublished, |
44 | waitUntilLivePublishedOnAllServers, | ||
48 | waitUntilLiveSegmentGeneration | 45 | waitUntilLiveSegmentGeneration |
49 | } from '../../../../shared/extra-utils' | 46 | } from '../../../../shared/extra-utils' |
50 | 47 | ||
@@ -53,12 +50,6 @@ const expect = chai.expect | |||
53 | describe('Test live', function () { | 50 | describe('Test live', function () { |
54 | let servers: ServerInfo[] = [] | 51 | let servers: ServerInfo[] = [] |
55 | 52 | ||
56 | async function waitUntilLivePublishedOnAllServers (videoId: string) { | ||
57 | for (const server of servers) { | ||
58 | await waitUntilLivePublished(server.url, server.accessToken, videoId) | ||
59 | } | ||
60 | } | ||
61 | |||
62 | before(async function () { | 53 | before(async function () { |
63 | this.timeout(120000) | 54 | this.timeout(120000) |
64 | 55 | ||
@@ -247,7 +238,7 @@ describe('Test live', function () { | |||
247 | liveVideoId = resLive.body.video.uuid | 238 | liveVideoId = resLive.body.video.uuid |
248 | 239 | ||
249 | command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) | 240 | command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) |
250 | await waitUntilLivePublishedOnAllServers(liveVideoId) | 241 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
251 | await waitJobs(servers) | 242 | await waitJobs(servers) |
252 | }) | 243 | }) |
253 | 244 | ||
@@ -461,7 +452,7 @@ describe('Test live', function () { | |||
461 | liveVideoId = await createLiveWrapper(false) | 452 | liveVideoId = await createLiveWrapper(false) |
462 | 453 | ||
463 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) | 454 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) |
464 | await waitUntilLivePublishedOnAllServers(liveVideoId) | 455 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
465 | await waitJobs(servers) | 456 | await waitJobs(servers) |
466 | 457 | ||
467 | await testVideoResolutions(liveVideoId, [ 720 ]) | 458 | await testVideoResolutions(liveVideoId, [ 720 ]) |
@@ -477,7 +468,7 @@ describe('Test live', function () { | |||
477 | liveVideoId = await createLiveWrapper(false) | 468 | liveVideoId = await createLiveWrapper(false) |
478 | 469 | ||
479 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) | 470 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId) |
480 | await waitUntilLivePublishedOnAllServers(liveVideoId) | 471 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
481 | await waitJobs(servers) | 472 | await waitJobs(servers) |
482 | 473 | ||
483 | await testVideoResolutions(liveVideoId, resolutions) | 474 | await testVideoResolutions(liveVideoId, resolutions) |
@@ -494,7 +485,7 @@ describe('Test live', function () { | |||
494 | liveVideoId = await createLiveWrapper(true) | 485 | liveVideoId = await createLiveWrapper(true) |
495 | 486 | ||
496 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId, 'video_short2.webm') | 487 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, liveVideoId, 'video_short2.webm') |
497 | await waitUntilLivePublishedOnAllServers(liveVideoId) | 488 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
498 | await waitJobs(servers) | 489 | await waitJobs(servers) |
499 | 490 | ||
500 | await testVideoResolutions(liveVideoId, resolutions) | 491 | await testVideoResolutions(liveVideoId, resolutions) |
@@ -504,7 +495,7 @@ describe('Test live', function () { | |||
504 | 495 | ||
505 | await waitJobs(servers) | 496 | await waitJobs(servers) |
506 | 497 | ||
507 | await waitUntilLivePublishedOnAllServers(liveVideoId) | 498 | await waitUntilLivePublishedOnAllServers(servers, liveVideoId) |
508 | 499 | ||
509 | const bitrateLimits = { | 500 | const bitrateLimits = { |
510 | 720: 5000 * 1000, // 60FPS | 501 | 720: 5000 * 1000, // 60FPS |
@@ -559,216 +550,6 @@ describe('Test live', function () { | |||
559 | }) | 550 | }) |
560 | }) | 551 | }) |
561 | 552 | ||
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) | ||
588 | await waitUntilLivePublishedOnAllServers(liveVideoId) | ||
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 | |||
602 | await wait(7000) | ||
603 | |||
604 | await waitJobs(servers) | ||
605 | |||
606 | await countViews(1) | ||
607 | }) | ||
608 | |||
609 | it('Should wait and display 0 views', async function () { | ||
610 | this.timeout(30000) | ||
611 | |||
612 | await wait(7000) | ||
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 | |||
625 | await wait(7000) | ||
626 | await waitJobs(servers) | ||
627 | |||
628 | await countViews(2) | ||
629 | }) | ||
630 | |||
631 | after(async function () { | ||
632 | await stopFfmpeg(command) | ||
633 | }) | ||
634 | }) | ||
635 | |||
636 | describe('Live socket messages', function () { | ||
637 | |||
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) | ||
675 | |||
676 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | ||
677 | await waitJobs(servers) | ||
678 | |||
679 | for (const stateChanges of [ localStateChanges, remoteStateChanges ]) { | ||
680 | expect(stateChanges).to.have.length.at.least(1) | ||
681 | expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.PUBLISHED) | ||
682 | } | ||
683 | |||
684 | await stopFfmpeg(command) | ||
685 | |||
686 | for (const server of servers) { | ||
687 | await waitUntilLiveEnded(server.url, server.accessToken, liveVideoUUID) | ||
688 | } | ||
689 | await waitJobs(servers) | ||
690 | |||
691 | for (const stateChanges of [ localStateChanges, remoteStateChanges ]) { | ||
692 | expect(stateChanges).to.have.length.at.least(2) | ||
693 | expect(stateChanges[stateChanges.length - 1]).to.equal(VideoState.LIVE_ENDED) | ||
694 | } | ||
695 | }) | ||
696 | |||
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 | |||
724 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | ||
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 | |||
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) | ||
758 | |||
759 | await waitUntilLivePublishedOnAllServers(liveVideoUUID) | ||
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) | ||
769 | }) | ||
770 | }) | ||
771 | |||
772 | describe('After a server restart', function () { | 553 | describe('After a server restart', function () { |
773 | let liveVideoId: string | 554 | let liveVideoId: string |
774 | let liveVideoReplayId: string | 555 | let liveVideoReplayId: string |