]>
Commit | Line | Data |
---|---|---|
bb4ba6d9 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' | |
6 | import { | |
bb4ba6d9 C |
7 | cleanupTests, |
8 | createLive, | |
9 | doubleFollow, | |
10 | flushAndRunMultipleServers, | |
a1bb73f9 | 11 | getCustomConfigResolutions, |
bb4ba6d9 C |
12 | getLive, |
13 | getPlaylistsCount, | |
14 | getVideo, | |
15 | sendRTMPStreamInVideo, | |
16 | ServerInfo, | |
17 | setAccessTokensToServers, | |
18 | setDefaultVideoChannel, | |
19 | stopFfmpeg, | |
20 | updateCustomSubConfig, | |
21 | updateLive, | |
22 | wait, | |
23 | waitJobs, | |
59fd824c C |
24 | waitUntilLivePublished, |
25 | waitUntilLiveWaiting | |
bb4ba6d9 C |
26 | } from '../../../../shared/extra-utils' |
27 | ||
28 | const expect = chai.expect | |
29 | ||
668f864f | 30 | describe('Permanent live', function () { |
bb4ba6d9 C |
31 | let servers: ServerInfo[] = [] |
32 | let videoUUID: string | |
33 | ||
34 | async function createLiveWrapper (permanentLive: boolean) { | |
35 | const attributes: LiveVideoCreate = { | |
36 | channelId: servers[0].videoChannel.id, | |
37 | privacy: VideoPrivacy.PUBLIC, | |
38 | name: 'my super live', | |
39 | saveReplay: false, | |
40 | permanentLive | |
41 | } | |
42 | ||
43 | const res = await createLive(servers[0].url, servers[0].accessToken, attributes) | |
44 | return res.body.video.uuid | |
45 | } | |
46 | ||
47 | async function checkVideoState (videoId: string, state: VideoState) { | |
48 | for (const server of servers) { | |
49 | const res = await getVideo(server.url, videoId) | |
50 | expect((res.body as VideoDetails).state.id).to.equal(state) | |
51 | } | |
52 | } | |
53 | ||
54 | before(async function () { | |
55 | this.timeout(120000) | |
56 | ||
57 | servers = await flushAndRunMultipleServers(2) | |
58 | ||
59 | // Get the access tokens | |
60 | await setAccessTokensToServers(servers) | |
61 | await setDefaultVideoChannel(servers) | |
62 | ||
63 | // Server 1 and server 2 follow each other | |
64 | await doubleFollow(servers[0], servers[1]) | |
65 | ||
66 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
67 | live: { | |
68 | enabled: true, | |
69 | allowReplay: true, | |
c9bc850e | 70 | maxDuration: -1, |
bb4ba6d9 C |
71 | transcoding: { |
72 | enabled: true, | |
a1bb73f9 | 73 | resolutions: getCustomConfigResolutions(true) |
bb4ba6d9 C |
74 | } |
75 | } | |
76 | }) | |
77 | }) | |
78 | ||
79 | it('Should create a non permanent live and update it to be a permanent live', async function () { | |
80 | this.timeout(20000) | |
81 | ||
82 | const videoUUID = await createLiveWrapper(false) | |
83 | ||
84 | { | |
85 | const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) | |
86 | expect(res.body.permanentLive).to.be.false | |
87 | } | |
88 | ||
89 | await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true }) | |
90 | ||
91 | { | |
92 | const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) | |
93 | expect(res.body.permanentLive).to.be.true | |
94 | } | |
95 | }) | |
96 | ||
97 | it('Should create a permanent live', async function () { | |
98 | this.timeout(20000) | |
99 | ||
100 | videoUUID = await createLiveWrapper(true) | |
101 | ||
102 | const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID) | |
103 | expect(res.body.permanentLive).to.be.true | |
104 | ||
105 | await waitJobs(servers) | |
106 | }) | |
107 | ||
108 | it('Should stream into this permanent live', async function () { | |
17b064e3 | 109 | this.timeout(120000) |
bb4ba6d9 C |
110 | |
111 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID) | |
112 | ||
113 | for (const server of servers) { | |
0d8de275 | 114 | await waitUntilLivePublished(server.url, server.accessToken, videoUUID) |
bb4ba6d9 C |
115 | } |
116 | ||
117 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
118 | ||
119 | await stopFfmpeg(command) | |
59fd824c | 120 | await waitUntilLiveWaiting(servers[0].url, servers[0].accessToken, videoUUID) |
bb4ba6d9 C |
121 | |
122 | await waitJobs(servers) | |
123 | }) | |
124 | ||
125 | it('Should not have cleaned up this live', async function () { | |
126 | this.timeout(40000) | |
127 | ||
128 | await wait(5000) | |
129 | await waitJobs(servers) | |
130 | ||
131 | for (const server of servers) { | |
132 | const res = await getVideo(server.url, videoUUID) | |
133 | ||
134 | const videoDetails = res.body as VideoDetails | |
135 | expect(videoDetails.streamingPlaylists).to.have.lengthOf(1) | |
136 | } | |
137 | }) | |
138 | ||
139 | it('Should have set this live to waiting for live state', async function () { | |
140 | this.timeout(20000) | |
141 | ||
142 | await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE) | |
143 | }) | |
144 | ||
145 | it('Should be able to stream again in the permanent live', async function () { | |
146 | this.timeout(20000) | |
147 | ||
148 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
149 | live: { | |
150 | enabled: true, | |
151 | allowReplay: true, | |
c9bc850e | 152 | maxDuration: -1, |
bb4ba6d9 C |
153 | transcoding: { |
154 | enabled: true, | |
a1bb73f9 | 155 | resolutions: getCustomConfigResolutions(false) |
bb4ba6d9 C |
156 | } |
157 | } | |
158 | }) | |
159 | ||
160 | const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID) | |
161 | ||
162 | for (const server of servers) { | |
0d8de275 | 163 | await waitUntilLivePublished(server.url, server.accessToken, videoUUID) |
bb4ba6d9 C |
164 | } |
165 | ||
166 | await checkVideoState(videoUUID, VideoState.PUBLISHED) | |
167 | ||
168 | const count = await getPlaylistsCount(servers[0], videoUUID) | |
169 | // master playlist and 720p playlist | |
170 | expect(count).to.equal(2) | |
171 | ||
172 | await stopFfmpeg(command) | |
173 | }) | |
174 | ||
175 | after(async function () { | |
176 | await cleanupTests(servers) | |
177 | }) | |
178 | }) |